Skip to content

Commit

Permalink
Added code to fetch cml platform data (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapas Kumar Senapati authored Sep 26, 2022
1 parent a0b9cf7 commit 50a0f23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dbt/adapters/impala/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 @@ -42,6 +43,8 @@
# 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 @@ -64,6 +67,21 @@ def populate_platform_info(cred: Credentials, ver):
# dbt adapter info e.g. impala-1.2.0
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()
Expand Down Expand Up @@ -172,6 +190,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/impala/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 50a0f23

Please sign in to comment.