Skip to content

Commit

Permalink
feat: Adds common data to telemetry events
Browse files Browse the repository at this point in the history
Signed-off-by: Caden Marofke <marofke@amazon.com>
  • Loading branch information
marofke committed Mar 13, 2024
1 parent 5cda9e6 commit cfcdca7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 14 deletions.
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
4 changes: 3 additions & 1 deletion src/deadline/client/ui/dialogs/submit_job_progress_dialog.py
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

0 comments on commit cfcdca7

Please sign in to comment.