Skip to content

Commit

Permalink
adding commit hash as a tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishnu Challa committed Oct 19, 2023
1 parent 79ec362 commit 4dd2ae4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dittybopper/syncer/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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",
Expand All @@ -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:
Expand Down

0 comments on commit 4dd2ae4

Please sign in to comment.