Skip to content

Commit

Permalink
Fix metrics, output in ms
Browse files Browse the repository at this point in the history
  • Loading branch information
dominickp committed Feb 14, 2024
1 parent ac7ed90 commit e7126e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions python/src/chan_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def handle_request(self, method, url, headers={}):
"""
start = time()
chan_r = requests.request(method, url, timeout=REQUEST_TIMEOUT, headers=headers)
total_time = time() - start
METRIC_FANOUT_REQUEST_TIME.labels(method, url, chan_r.status_code).observe(total_time)
total_time_ms = (time() - start) * 1000
METRIC_FANOUT_REQUEST_TIME.labels(method, url, chan_r.status_code).observe(total_time_ms)
return chan_r

def get_catalog(self, board, headers={}):
Expand Down
4 changes: 2 additions & 2 deletions python/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def after_request(response):
Capture the time spent on the request and record it as a metric.
"""
# Calculate the total time spent on the request
total_time = time() - g.start
total_time_ms = (time() - g.start) * 1000
# Get the normalized route like "/<string:name>/<int:page>" if url_rule is present
normalized_path = request.url_rule.rule if request.url_rule else "unmatched-route"
# Ensure unmatched routes are recorded as "not_found"
METRIC_TOTAL_REQUEST_TIME.labels(request.method, normalized_path, response.status_code).observe(total_time)
METRIC_TOTAL_REQUEST_TIME.labels(request.method, normalized_path, response.status_code).observe(total_time_ms)
return response

@app.route("/")
Expand Down

0 comments on commit e7126e2

Please sign in to comment.