Skip to content

Commit

Permalink
update prometheus_url get logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubangizi committed May 20, 2024
1 parent 6174313 commit 6482a8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
4 changes: 4 additions & 0 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ paths:
format: float
step:
type: string
prometheus_url:
type: string
project_id:
type: string
project_name:
Expand Down Expand Up @@ -79,6 +81,8 @@ paths:
type: string
project_id:
type: string
prometheus_url:
type: string
project_name:
type: string
app_id:
Expand Down
21 changes: 7 additions & 14 deletions app/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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={
Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions app/schemas/monitoring_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6482a8c

Please sign in to comment.