Skip to content

Commit

Permalink
Cml profile instrumentation (#45)
Browse files Browse the repository at this point in the history
* Added cml instrumentation
  • Loading branch information
Tapas Kumar Senapati authored Sep 23, 2022
1 parent 09a6173 commit f24e104
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dbt/adapters/hive/cloudera_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import dbt.version
import json
import os
import platform
import requests
import sys
Expand Down Expand Up @@ -41,6 +42,9 @@
# Json object to store dbt profile(profile.yml) related information
profile_info = {}

# Json object to store cml environment variables
cml_info = {}


def populate_platform_info(cred: Credentials, ver):
"""
Expand All @@ -66,6 +70,22 @@ def populate_platform_info(cred: Credentials, ver):
platform_info["dbt_adapter"] = f"{cred.type}-{ver.version}"


def populate_cml_info():
"""
populate cml environment variables if available to be passed on for tracking
"""
default_value = "" # if environment variables doesn't exist add empty string as default
cml_info["ml_runtime_edition"] = os.environ.get('ML_RUNTIME_EDITION', default_value)
cml_info["ml_runtime_git_hash"] = os.environ.get('ML_RUNTIME_GIT_HASH', default_value)
cml_info["ml_runtime_kernel"] = os.environ.get('ML_RUNTIME_KERNEL', default_value)
cml_info["ml_runtime_editor"] = os.environ.get('ML_RUNTIME_EDITOR', default_value)
cml_info["ml_runtime_gbn"] = os.environ.get('ML_RUNTIME_GBN', default_value)
cml_info["ml_runtime_full_version"] = os.environ.get('ML_RUNTIME_FULL_VERSION', default_value)
cml_info["ml_runtime_description"] = os.environ.get('ML_RUNTIME_DESCRIPTION', default_value)
cml_info["ml_runtime_maintenance_version"] = os.environ.get('ML_RUNTIME_MAINTENANCE_VERSION', default_value)
cml_info["ml_runtime_metadata_version"] = os.environ.get('ML_RUNTIME_METADATA_VERSION', default_value)


def populate_unique_ids(cred: Credentials):
host = str(cred.host).encode()
user = str(cred.username).encode()
Expand Down Expand Up @@ -178,6 +198,7 @@ def track_usage(tracking_payload):
# inject other static payload to tracking_payload
tracking_payload = _merge_keys(unique_ids, tracking_payload)
tracking_payload = _merge_keys(platform_info, tracking_payload)
tracking_payload = _merge_keys(cml_info, tracking_payload)
tracking_payload = _merge_keys(profile_info, tracking_payload)

# form the tracking data
Expand Down
2 changes: 2 additions & 0 deletions dbt/adapters/hive/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def __post_init__(self):
tracker.usage_tracking = self.usage_tracking
# get platform information for tracking
tracker.populate_platform_info(self, ver)
# get cml information for tracking
tracker.populate_cml_info()
# generate unique ids for tracking
tracker.populate_unique_ids(self)

Expand Down

0 comments on commit f24e104

Please sign in to comment.