From a5155fd1ddaab9e821e39295fc88032c0729419a 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 --- assets/kube-burner-report-ocp-wrapper/queries.libsonnet | 5 ----- dittybopper/syncer/entrypoint.py | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/kube-burner-report-ocp-wrapper/queries.libsonnet b/assets/kube-burner-report-ocp-wrapper/queries.libsonnet index 1a4e13e..0d5e0aa 100644 --- a/assets/kube-burner-report-ocp-wrapper/queries.libsonnet +++ b/assets/kube-burner-report-ocp-wrapper/queries.libsonnet @@ -1276,8 +1276,6 @@ local elasticsearch = g.query.elasticsearch; + elasticsearch.withQuery(query) + elasticsearch.withTimeField('timestamp'), queries(): [ - self.base("Available", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryAvailable-Masters\" AND labels.instance.keyword: $master"), - self.base("Total", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryTotal-Masters\" AND labels.instance.keyword: $master"), self.base("Utilization", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryUtilization-Masters\" AND labels.instance.keyword: $master"), ], }, @@ -1362,8 +1360,6 @@ local elasticsearch = g.query.elasticsearch; + elasticsearch.withQuery(query) + elasticsearch.withTimeField('timestamp'), queries(): [ - self.base("available", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryAvailable-Workers\" AND labels.instance.keyword: \"$worker\""), - self.base("Total", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryTotal-Workers\" AND labels.instance.keyword: $worker"), self.base("Utilization", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryUtilization-Workers\" AND labels.instance.keyword: $worker"), ], }, @@ -1534,7 +1530,6 @@ local elasticsearch = g.query.elasticsearch; + elasticsearch.withTimeField('timestamp'), queries(): [ self.base("Available", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryAvailable-AggregatedWorkers\""), - self.base("Total", "uuid.keyword: $uuid AND metricName.keyword: \"nodeMemoryTotal-AggregatedWorkers\""), ], }, aggWorkerNodeContainerCpuUsage: { 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: