Skip to content
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

fix: prefix telemetry endpoint with 'management.' #119

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/deadline/client/api/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class TelemetryClient:
MAX_BACKOFF_SECONDS = 10 # The maximum amount of time to wait between retries
MAX_RETRY_ATTEMPTS = 4

ENDPOINT_PREFIX = "management."

def __init__(
self,
package_name: str,
Expand All @@ -76,7 +78,10 @@ def __init__(
return
self.package_name = package_name
self.package_ver = ".".join(package_ver.split(".")[:3])
self.endpoint: str = f"{get_deadline_endpoint_url(config=config)}/2023-10-12/telemetry"
self.endpoint: str = self._get_prefixed_endpoint(
f"{get_deadline_endpoint_url(config=config)}/2023-10-12/telemetry",
TelemetryClient.ENDPOINT_PREFIX,
)

# IDs for this session
self.session_id: str = str(uuid.uuid4())
Expand All @@ -86,6 +91,13 @@ def __init__(

self._start_threads()

def _get_prefixed_endpoint(self, endpoint: str, prefix: str) -> str:
"""Insert the prefix right after 'https://'"""
if endpoint.startswith("https://"):
prefixed_endpoint = endpoint[:8] + prefix + endpoint[8:]
return prefixed_endpoint
return endpoint

def _get_telemetry_identifier(self, config: Optional[ConfigParser] = None):
identifier = config_file.get_setting("telemetry.identifier", config=config)
try:
Expand Down Expand Up @@ -222,7 +234,7 @@ def record_upload_summary(self, summary: SummaryStatistics, *, from_gui: bool =

def record_error(self, event_details: Dict[str, Any], exception_type: str):
event_details["exception_type"] = exception_type
# Possiblity to add stack trace here
# Possibility to add stack trace here
self.record_event("com.amazon.rum.deadline.error", event_details)

def record_event(self, event_type: str, event_details: Dict[str, Any]):
Expand Down
30 changes: 30 additions & 0 deletions test/unit/deadline_client/api/test_api_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,33 @@ def test_record_error(telemetry_client):

# THEN
queue_mock.put_nowait.assert_called_once_with(expected_event)


@pytest.mark.parametrize(
"endpoint,prefix,expected_result",
[
pytest.param(
"test.endpoint.url",
"",
"test.endpoint.url",
id="The endpoint is not prefixed if the prefix is empty.",
),
pytest.param(
"test.endpoint.url",
"management.",
"test.endpoint.url",
id="The endpoint is not prefixed if the endpoint does not start with 'https://'.",
),
pytest.param(
"https://test.endpoint.url",
"management.",
"https://management.test.endpoint.url",
id="The prefix is inserted right after 'https://'.",
),
],
)
def test_get_prefixed_endpoint(
telemetry_client: TelemetryClient, endpoint: str, prefix: str, expected_result: str
):
"""Test that the _get_prefixed_endpoint function returns the expected prefixed endpoint"""
assert telemetry_client._get_prefixed_endpoint(endpoint, prefix) == expected_result