Merge ~vtapia/maas:lp1927941-27 into maas:2.7

Proposed by Victor Tapia
Status: Merged
Approved by: Adam Collard
Approved revision: 138ffb82ee7e14dd1bb21b9d10206024b435bcf2
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~vtapia/maas:lp1927941-27
Merge into: maas:2.7
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 Approve
Adam Collard (community) Approve
Review via email: mp+403724@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-27 lp:~vtapia/maas/+git/maas into -b 2.7 lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10204/console
COMMIT: c6fdbd45daa4a020dc4041ce7ea312a562b89c5b

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

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

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10239/console
COMMIT: 138ffb82ee7e14dd1bb21b9d10206024b435bcf2

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

I haven't been able to reproduce the locale issue ("RuntimeError: Click will abort further execution because Python was configured to use ASCII as encoding for the environment") using my local bionic builder, even after setting the default locale to C:

$ env | egrep 'LANG|LC_'
LANG=C

$ sudo -E -H -u ubuntu -- python -c 'import locale; import codecs; print(codecs.lookup(locale.getpreferredencoding()).name)'
ascii

This same issue happens for both bionic releases (2.7 and 2.8) and according to https://click.palletsprojects.com/en/7.x/python3/:

"In Python 3.7 and later you will no longer get a RuntimeError in many cases thanks to PEP 538 and PEP 540, which changed the default assumption in unconfigured environments."

Bionic ships 3.6, which might explain why this happens only on its releases and not on Focal's (Python 3.8).

Could this be a builder issue?

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

jenkins: !test

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

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

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/10271/console
COMMIT: 138ffb82ee7e14dd1bb21b9d10206024b435bcf2

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

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

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

STATUS: SUCCESS
COMMIT: 138ffb82ee7e14dd1bb21b9d10206024b435bcf2

review: Approve

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 3d5a5ea..fd4fadf 100644
3--- a/src/maasserver/prometheus/stats.py
4+++ b/src/maasserver/prometheus/stats.py
5@@ -115,6 +115,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@@ -122,14 +124,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