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

feat: Adds common data to telemetry events #205

Merged
merged 1 commit into from
Mar 13, 2024
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
9 changes: 9 additions & 0 deletions src/deadline/client/api/_submit_job_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def create_job_from_job_bundle(
if logging.DEBUG >= logger.getEffectiveLevel():
logger.debug(json.dumps(create_job_args, indent=1))

api.get_deadline_cloud_library_telemetry_client().record_event(
event_type="com.amazon.rum.deadline.submission",
event_details={},
)

create_job_response = deadline.create_job(**create_job_args)
logger.debug(f"CreateJob Response {create_job_response}")

Expand All @@ -302,6 +307,10 @@ def _default_create_job_result_callback() -> bool:
create_job_result_callback,
)

api.get_deadline_cloud_library_telemetry_client().record_event(
event_type="com.amazon.rum.deadline.create_job", event_details={"is_success": success}
)

if not success:
raise DeadlineOperationError(status_message)

Expand Down
34 changes: 24 additions & 10 deletions src/deadline/client/api/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class TelemetryClient:

ENDPOINT_PREFIX = "management."

_common_details: Dict[str, Any] = {}
_system_metadata: Dict[str, Any] = {}

def __init__(
self,
package_name: str,
Expand All @@ -91,8 +94,10 @@ def __init__(
# IDs for this session
self.session_id: str = str(uuid.uuid4())
self.telemetry_id: str = self._get_telemetry_identifier(config=config)
# Get common data we'll include in each request
self.system_metadata = self._get_system_metadata(config=config)
# If a different base package is provided, include info from this library as supplementary info
if package_name != "deadline-cloud-library":
self._common_details["deadline-cloud-version"] = version
self._system_metadata = self._get_system_metadata(config=config)

self._start_threads()

Expand Down Expand Up @@ -198,7 +203,7 @@ def _process_event_queue_thread(self):
{
"details": str(json.dumps(event_data.event_details)),
"id": str(uuid.uuid4()),
"metadata": str(json.dumps(self.system_metadata)),
"metadata": str(json.dumps(self._system_metadata)),
"timestamp": int(datetime.now().timestamp()),
"type": event_data.event_type,
},
Expand Down Expand Up @@ -228,8 +233,7 @@ def _record_summary_statistics(
self, event_type: str, summary: SummaryStatistics, from_gui: bool
):
details: Dict[str, Any] = asdict(summary)
details["usage_mode"] = "GUI" if from_gui else "CLI"
self._put_telemetry_record(TelemetryEvent(event_type=event_type, event_details=details))
self.record_event(event_type=event_type, event_details=details, from_gui=from_gui)

def record_hashing_summary(self, summary: SummaryStatistics, *, from_gui: bool = False):
self._record_summary_statistics(
Expand All @@ -241,28 +245,38 @@ def record_upload_summary(self, summary: SummaryStatistics, *, from_gui: bool =
"com.amazon.rum.deadline.job_attachments.upload_summary", summary, from_gui
)

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

def record_event(self, event_type: str, event_details: Dict[str, Any]):
def record_event(
self, event_type: str, event_details: Dict[str, Any], *, from_gui: bool = False
):
event_details.update(self._common_details)
event_details["usage_mode"] = "GUI" if from_gui else "CLI"
self._put_telemetry_record(
TelemetryEvent(
event_type=event_type,
event_details=event_details,
)
)

def update_common_details(self, details: Dict[str, Any]):
"""Updates the dict of common data that is included in every telemetry request."""
self._common_details.update(details)


def get_telemetry_client(
package_name: str, package_ver: str, config: Optional[ConfigParser] = None
) -> TelemetryClient:
"""
Retrieves the cached telemetry client, lazy-loading the first time this is called.
:param package_name: Base package name to associate data by.
:param package_ver: Base package version to associate data by.
:param config: Optional configuration to use for the client. Loads defaults if not given.
:param package_name: Optional override package name to include in requests. Defaults to the 'deadline-cloud' package.
:param package_ver: Optional override package version to include in requests. Defaults to the 'deadline-cloud' version.
:return: Telemetry client to make requests with.
"""
global __cached_telemetry_client
Expand Down
6 changes: 6 additions & 0 deletions src/deadline/client/cli/_groups/bundle_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def _decide_cancel_submission(
raise DeadlineOperationError(
f"Failed to submit the job bundle to Amazon Deadline Cloud:\n{exc}"
) from exc
except Exception as exc:
api.get_deadline_cloud_library_telemetry_client().record_error(
event_details={"exception_scope": "on_submit"},
exception_type=str(type(exc)),
)
raise


@cli_bundle.command(name="gui-submit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ def handle_create_job_thread_succeeded(self, success: bool, status_message: str)
job creation has finished.
"""
api.get_deadline_cloud_library_telemetry_client().record_event(
event_type="com.amazon.rum.deadline.create_job", event_details={"is_success": success}
event_type="com.amazon.rum.deadline.create_job",
event_details={"is_success": success},
from_gui=True,
)

if success:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ def on_submit(self):
event_details={
"submitter_name": settings.submitter_name,
},
from_gui=True,
)

self.create_job_response = job_progress_dialog.start_submission(
Expand All @@ -476,8 +477,9 @@ def on_submit(self):
except Exception as exc:
logger.exception("error submitting job")
api.get_deadline_cloud_library_telemetry_client().record_error(
event_details={"submitter_name": settings.submitter_name},
event_details={"exception_scope": "on_submit"},
exception_type=str(type(exc)),
from_gui=True,
)
QMessageBox.warning(self, f"{settings.submitter_name} Job Submission", str(exc))
job_progress_dialog.close()
Expand Down
8 changes: 6 additions & 2 deletions test/unit/deadline_client/api/test_api_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def fixture_telemetry_client(fresh_deadline_config):
side_effect=[("user-id", "identity-store-id")],
):
return TelemetryClient(
"test-library", "0.1.2.1234", config=config.config_file.read_config()
"deadline-cloud-library", "0.1.2.1234", config=config.config_file.read_config()
)


Expand Down Expand Up @@ -170,7 +170,11 @@ def test_record_error(telemetry_client):
queue_mock = MagicMock()
test_error_details = {"some_field": "some_value"}
test_exc = Exception("some exception")
expected_event_details = {"some_field": "some_value", "exception_type": str(type(test_exc))}
expected_event_details = {
"some_field": "some_value",
"exception_type": str(type(test_exc)),
"usage_mode": "CLI",
}
expected_event = TelemetryEvent(
event_type="com.amazon.rum.deadline.error", event_details=expected_event_details
)
Expand Down