Merge ~vtapia/maas:lp1927941-26 into maas:2.6

Proposed by Victor Tapia
Status: Merged
Approved by: Adam Collard
Approved revision: 7b9c60178ec7f43f0b4bf6d88022d5092c59b5b2
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~vtapia/maas:lp1927941-26
Merge into: maas:2.6
Diff against target: 35 lines (+10/-6)
1 file modified
src/maasserver/prometheus/stats.py (+10/-6)
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
MAAS Lander Approve
Review via email: mp+403773@code.launchpad.net

Commit message

Reuse metric structures for Prometheus

Backport of 2ad24e0

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1927941-26 lp:~vtapia/maas/+git/maas into -b 2.6 lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 7b9c60178ec7f43f0b4bf6d88022d5092c59b5b2

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Revision history for this message
MAAS Lander (maas-lander) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/prometheus/stats.py b/src/maasserver/prometheus/stats.py
2index 826eaa1..4ae81af 100644
3--- a/src/maasserver/prometheus/stats.py
4+++ b/src/maasserver/prometheus/stats.py
5@@ -99,6 +99,8 @@ STATS_DEFINITIONS = [
6 ['arches'])
7 ]
8
9+_METRICS = {}
10+
11
12 def prometheus_stats_handler(request):
13 configs = Config.objects.get_configs(['prometheus_enabled', 'uuid'])
14@@ -106,13 +108,15 @@ def prometheus_stats_handler(request):
15 if not have_prometheus:
16 return HttpResponseNotFound()
17
18- metrics = create_metrics(
19- STATS_DEFINITIONS,
20- extra_labels={'maas_id': configs['uuid']},
21- update_handlers=[update_prometheus_stats],
22- registry=prom_cli.CollectorRegistry())
23+ global _METRICS
24+ if not _METRICS:
25+ _METRICS = create_metrics(
26+ STATS_DEFINITIONS,
27+ extra_labels={'maas_id': configs['uuid']},
28+ update_handlers=[update_prometheus_stats],
29+ registry=prom_cli.CollectorRegistry())
30 return HttpResponse(
31- content=metrics.generate_latest(), content_type="text/plain")
32+ content=_METRICS.generate_latest(), content_type="text/plain")
33
34
35 def update_prometheus_stats(metrics: PrometheusMetrics):

Subscribers

People subscribed via source and target branches