From 4dd2ae454cc87a1aa70b1d7a331b16d694100296 Mon Sep 17 00:00:00 2001 From: Vishnu Challa Date: Thu, 19 Oct 2023 19:28:25 -0400 Subject: [PATCH] adding commit hash as a tag --- dittybopper/syncer/entrypoint.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dittybopper/syncer/entrypoint.py b/dittybopper/syncer/entrypoint.py index e9d607a..8142ed3 100644 --- a/dittybopper/syncer/entrypoint.py +++ b/dittybopper/syncer/entrypoint.py @@ -13,9 +13,10 @@ class GrafanaOperations: """ This class is responsible for Grafana operations """ - def __init__(self, grafana_url: str, input_directory: str): + def __init__(self, grafana_url: str, input_directory: str, git_commit_hash: str): self.grafana_url = grafana_url self.input_directory = input_directory + self.git_commit_hash = git_commit_hash self.dashboards = defaultdict(list) self.folder_map = dict() self.logger = logging.getLogger(__name__) @@ -102,6 +103,10 @@ def create_dashboards(self): for folder_id, files in self.dashboards.items(): for json_file in set(files): dashboard_json = self.read_dashboard_json(json_file) + if "tags" in dashboard_json.keys(): + dashboard_json["tags"].append(self.git_commit_hash) + else: + dashboard_json["tags"] = self.git_commit_hash try: response = requests.post( f"{self.grafana_url}/api/dashboards/db", @@ -122,7 +127,7 @@ def create_dashboards(self): raise Exception(f"Error creating dashboard '{dashboard_json['title']}' in folder '{folder_id}'. Message: {e}") if __name__ == '__main__': - grafana_operations = GrafanaOperations(os.environ.get("GRAFANA_URL"), os.environ.get("INPUT_DIR")) + grafana_operations = GrafanaOperations(os.environ.get("GRAFANA_URL"), os.environ.get("INPUT_DIR"), os.environ.get("GIT_COMMIT_HASH")) grafana_operations.fetch_all_dashboards() grafana_operations.create_dashboards() while True: