From 50a0f239b5c9cf0fdf15a058343fd61512bb1462 Mon Sep 17 00:00:00 2001 From: Tapas Kumar Senapati Date: Mon, 26 Sep 2022 11:36:48 +0530 Subject: [PATCH] Added code to fetch cml platform data (#91) --- dbt/adapters/impala/cloudera_tracking.py | 19 +++++++++++++++++++ dbt/adapters/impala/connections.py | 2 ++ 2 files changed, 21 insertions(+) diff --git a/dbt/adapters/impala/cloudera_tracking.py b/dbt/adapters/impala/cloudera_tracking.py index 4565f95..531c0bb 100644 --- a/dbt/adapters/impala/cloudera_tracking.py +++ b/dbt/adapters/impala/cloudera_tracking.py @@ -14,6 +14,7 @@ import dbt.version import json +import os import platform import requests import sys @@ -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): """ @@ -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() @@ -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 diff --git a/dbt/adapters/impala/connections.py b/dbt/adapters/impala/connections.py index 866aea5..7ed6fdc 100644 --- a/dbt/adapters/impala/connections.py +++ b/dbt/adapters/impala/connections.py @@ -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)