From 6482a8c2d99eb9f5c95be9933980de37ac5ac318 Mon Sep 17 00:00:00 2001 From: Mubangizi Date: Mon, 20 May 2024 11:38:27 +0300 Subject: [PATCH] update prometheus_url get logic --- api_docs.yml | 4 ++++ app/helpers/utils.py | 21 +++++++-------------- app/schemas/monitoring_metrics.py | 1 + 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/api_docs.yml b/api_docs.yml index f7199de..3970b31 100644 --- a/api_docs.yml +++ b/api_docs.yml @@ -32,6 +32,8 @@ paths: format: float step: type: string + prometheus_url: + type: string project_id: type: string project_name: @@ -79,6 +81,8 @@ paths: type: string project_id: type: string + prometheus_url: + type: string project_name: type: string app_id: diff --git a/app/helpers/utils.py b/app/helpers/utils.py index 31388d1..0ab3cb0 100644 --- a/app/helpers/utils.py +++ b/app/helpers/utils.py @@ -27,10 +27,14 @@ def get_project_data(request): step = validated_query_data.get('step', '1h') project_id = validated_query_data.get('project_id', '') project_name = validated_query_data.get('project_name', '') + prometheus_url = validated_query_data.get('prometheus_url', '') if not project_id and not project_name: return SimpleNamespace(status='failed', message="project_id or project_name is required", status_code=400) + if project_name and not prometheus_url: + return SimpleNamespace(status='fail', message='Please add a prometheus_url', status_code=404) + if not project_name: project_response = requests.get( f"{PROJECT_ENDPOINT}/{project_id}", headers={ @@ -42,22 +46,11 @@ def get_project_data(request): project_response = project_response.json() project_data = project_response['data']['project'] - project_name = project_data['alias'] - - # cluster_response = requests.get( - # f"{PRODUCT_BASE_URL}/clusters/{project_data['cluster_id']}", headers={ - # "accept": "application/json", - # "Authorization": request.headers.get('Authorization') - # }) - - # print(cluster_response.json()) - - # if not cluster_response.ok: - # return SimpleNamespace(status='failed', message="Failed to fetch cluster info for the project", status_code=400) + project_name = project_data.get('alias', '') + prometheus_url = project_data.get('prometheus_url', '') - prometheus_url = ' https://prom.renu-01.cranecloud.io' if not prometheus_url: - return SimpleNamespace(status='fail', message='No prometheus url provided', status_code=404) + return SimpleNamespace(status='fail', message='No prometheus url available on the project', status_code=404) os.environ["PROMETHEUS_URL"] = prometheus_url return SimpleNamespace( diff --git a/app/schemas/monitoring_metrics.py b/app/schemas/monitoring_metrics.py index ab11ac2..b14dee7 100644 --- a/app/schemas/monitoring_metrics.py +++ b/app/schemas/monitoring_metrics.py @@ -13,6 +13,7 @@ class MetricsSchema(Schema): project_name = fields.String() app_name = fields.String() app_id = fields.String() + prometheus_url = fields.String() class UserGraphSchema(Schema):