Merge ~vtapia/maas:lp1927941 into maas:master

Proposed by Victor Tapia
Status: Merged
Approved by: Alberto Donato
Approved revision: 14b3bd07af70f85328fdf587d14dea640a49a64f
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~vtapia/maas:lp1927941
Merge into: maas:master
Diff against target: 36 lines (+12/-7)
1 file modified
src/maasserver/prometheus/stats.py (+12/-7)
Reviewer Review Type Date Requested Status
MAAS Lander Needs Fixing
Alberto Donato (community) Approve
Review via email: mp+403523@code.launchpad.net

Commit message

Reuse metric structures for Prometheus

Description of the change

After enabling Prometheus metrics, regiond was creating a new set of metrics + CollectorRegistry with every query. Those structures were never released, turning into a memory leak. This patch reuses the same metric structures which keep updating with every query.

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

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

STATUS: SUCCESS
COMMIT: 0036ade433495530beebebe2d0245f85c0987dd9

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Thanks for the change, +1

One small nit inline

review: Approve
~vtapia/maas:lp1927941 updated
14b3bd0... by Victor Tapia

Apply naming convention on _METRICS

Revision history for this message
MAAS Lander (maas-lander) wrote :

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

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10186/console
COMMIT: 14b3bd07af70f85328fdf587d14dea640a49a64f

review: Needs Fixing
Revision history for this message
Victor Tapia (vtapia) wrote :

Done, thanks for the review!

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 ff47b15..862ddb9 100644
3--- a/src/maasserver/prometheus/stats.py
4+++ b/src/maasserver/prometheus/stats.py
5@@ -113,6 +113,8 @@ STATS_DEFINITIONS = [
6 ),
7 ]
8
9+_METRICS = {}
10+
11
12 def prometheus_stats_handler(request):
13 configs = Config.objects.get_configs(["prometheus_enabled", "uuid"])
14@@ -120,14 +122,17 @@ 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- )
24+ global _METRICS
25+ if not _METRICS:
26+ _METRICS = create_metrics(
27+ STATS_DEFINITIONS,
28+ extra_labels={"maas_id": configs["uuid"]},
29+ update_handlers=[update_prometheus_stats],
30+ registry=prom_cli.CollectorRegistry(),
31+ )
32+
33 return HttpResponse(
34- content=metrics.generate_latest(), content_type="text/plain"
35+ content=_METRICS.generate_latest(), content_type="text/plain"
36 )
37
38

Subscribers

People subscribed via source and target branches