-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] argilla server
: add user and server id on telemetry metrics
#5445
Merged
frascuchon
merged 11 commits into
feat/5204-feature-add-huggingface_hubutilssend_telemetry-to-the-argilla-server
from
feat/argilla-server/add-user-and-server-id-on-telemetry-metrics
Sep 2, 2024
+202
−25
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22c088d
chore: Remove unused methods
frascuchon c8ac5a9
chore: Remove specific user me telemetry tracking
frascuchon 66db650
refactor: Add authenticated user to the request
frascuchon 857916f
feat: Track request with user id and role and add server id to the sy…
frascuchon 5ae2069
chore: Add missing test
frascuchon 39c1c43
Merge branch 'feat/5204-feature-add-huggingface_hubutilssend_telemetr…
frascuchon 56ebfbc
refactor: using server-id int value
frascuchon 8b936e5
tests: Add more tests
frascuchon 692d244
refactor: Store server id in file
frascuchon bc43b43
chore: Move telemetry python module
frascuchon e047a04
tests: add more tests
frascuchon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,26 +16,31 @@ | |
import json | ||
import logging | ||
import platform | ||
import uuid | ||
from typing import Union | ||
|
||
from fastapi import Request, Response | ||
from huggingface_hub.utils import send_telemetry | ||
|
||
from argilla_server._version import __version__ | ||
from argilla_server.api.errors.v1.exception_handlers import get_request_error | ||
from argilla_server.settings import settings | ||
from argilla_server.utils._fastapi import resolve_endpoint_path_for_request | ||
from argilla_server.utils._telemetry import ( | ||
is_running_on_docker_container, | ||
server_deployment_type, | ||
) | ||
from argilla_server.security.authentication.provider import get_request_user | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@dataclasses.dataclass | ||
class TelemetryClient: | ||
_server_id: int = uuid.getnode() | ||
|
||
def __post_init__(self): | ||
self._system_info = { | ||
"server_id": self._server_id, | ||
"system": platform.system(), | ||
"machine": platform.machine(), | ||
"platform": platform.platform(), | ||
|
@@ -47,16 +52,11 @@ def __post_init__(self): | |
_LOGGER.info("System Info:") | ||
_LOGGER.info(f"Context: {json.dumps(self._system_info, indent=2)}") | ||
|
||
async def track_data(self, topic: str, data: dict, include_system_info: bool = True, count: int = 1): | ||
library_name = "argilla/server" | ||
topic = f"{library_name}/{topic}" | ||
|
||
user_agent = {**data} | ||
if include_system_info: | ||
user_agent.update(self._system_info) | ||
if count is not None: | ||
user_agent["count"] = count | ||
async def track_data(self, topic: str, data: dict): | ||
library_name = "argilla-server" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This aligns the library name (argilla-server) to the package published in pypi.org |
||
topic = f"argilla/server/{topic}" | ||
|
||
user_agent = {**data, **self._system_info} | ||
send_telemetry(topic=topic, library_name=library_name, library_version=__version__, user_agent=user_agent) | ||
|
||
async def track_api_request(self, request: Request, response: Response) -> None: | ||
|
@@ -85,15 +85,16 @@ async def track_api_request(self, request: Request, response: Response) -> None: | |
"response.status": str(response.status_code), | ||
} | ||
|
||
if "Server-Timing" in response.headers: | ||
duration_in_ms = response.headers["Server-Timing"] | ||
duration_in_ms = duration_in_ms.removeprefix("total;dur=") | ||
|
||
if server_timing := response.headers.get("Server-Timing"): | ||
duration_in_ms = server_timing.removeprefix("total;dur=") | ||
data["duration_in_milliseconds"] = duration_in_ms | ||
|
||
if user := get_request_user(request=request): | ||
data["user.id"] = str(user.id) | ||
data["user.role"] = user.role | ||
|
||
if response.status_code >= 400: | ||
argilla_error: Exception = get_request_error(request=request) | ||
if argilla_error: | ||
if argilla_error := get_request_error(request=request): | ||
data["response.error_code"] = argilla_error.code # noqa | ||
|
||
await self.track_data(topic=topic, data=data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
uuid.getnode
returns an integer value. We can use it "as is".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check that
uuid.getnode()
is returning the same value on HF Spaces even after a factory rebuild.