Skip to content

Commit 0135479

Browse files
authored
Merge pull request openlabs#12 from Traum-Ferienwohnungen/limit_possible_metric_labels
Create metrics only for specific endpoints to not flood prometheus
2 parents 2b90c18 + 2bdc720 commit 0135479

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from prometheus import prometheus_metrics
1818

1919
@Request.application
20-
@prometheus_metrics('/metrics')
20+
@prometheus_metrics('/metrics', ('/', '/healthz'))
2121
def application(request):
2222

2323
if request.method == 'GET':

src/prometheus.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
['method', 'endpoint', 'code']
1515
)
1616

17-
def prometheus_metrics(metrics_path):
17+
def prometheus_metrics(metrics_path, monitor_endpoints):
18+
monitor_endpoints = set([metrics_path] + list(monitor_endpoints))
1819
def prometheus_metrics_decorator(f):
1920
@wraps(f)
2021
def f_wrapper(request):
21-
start_time = time()
22+
# Create metrics only for specific endpoints to not flood
23+
# prometheus with dynamically created labels.
24+
if request.path not in monitor_endpoints:
25+
return f(request)
2226

27+
start_time = time()
2328
if request.method == 'GET' and request.path == metrics_path:
2429
status = 200
2530
REQUEST_LATENCIES.labels(

0 commit comments

Comments
 (0)