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
diff --git a/src/maasserver/prometheus/stats.py b/src/maasserver/prometheus/stats.py
index ff47b15..862ddb9 100644
--- a/src/maasserver/prometheus/stats.py
+++ b/src/maasserver/prometheus/stats.py
@@ -113,6 +113,8 @@ STATS_DEFINITIONS = [
113 ),113 ),
114]114]
115115
116_METRICS = {}
117
116118
117def prometheus_stats_handler(request):119def prometheus_stats_handler(request):
118 configs = Config.objects.get_configs(["prometheus_enabled", "uuid"])120 configs = Config.objects.get_configs(["prometheus_enabled", "uuid"])
@@ -120,14 +122,17 @@ def prometheus_stats_handler(request):
120 if not have_prometheus:122 if not have_prometheus:
121 return HttpResponseNotFound()123 return HttpResponseNotFound()
122124
123 metrics = create_metrics(125 global _METRICS
124 STATS_DEFINITIONS,126 if not _METRICS:
125 extra_labels={"maas_id": configs["uuid"]},127 _METRICS = create_metrics(
126 update_handlers=[update_prometheus_stats],128 STATS_DEFINITIONS,
127 registry=prom_cli.CollectorRegistry(),129 extra_labels={"maas_id": configs["uuid"]},
128 )130 update_handlers=[update_prometheus_stats],
131 registry=prom_cli.CollectorRegistry(),
132 )
133
129 return HttpResponse(134 return HttpResponse(
130 content=metrics.generate_latest(), content_type="text/plain"135 content=_METRICS.generate_latest(), content_type="text/plain"
131 )136 )
132137
133138

Subscribers

People subscribed via source and target branches