Merge ~afreiberger/charm-grafana/+git/grafana-charm:anymetricdashboards into ~prometheus-charmers/charm-grafana:master

Proposed by Drew Freiberger
Status: Rejected
Rejected by: Chris Sanders
Proposed branch: ~afreiberger/charm-grafana/+git/grafana-charm:anymetricdashboards
Merge into: ~prometheus-charmers/charm-grafana:master
Diff against target: 33 lines (+8/-5)
1 file modified
reactive/grafana.py (+8/-5)
Reviewer Review Type Date Requested Status
Chris Sanders (community) Disapprove
Review via email: mp+353664@code.launchpad.net

Commit message

Update dashboard generation to allow for 50% or more matching metrics to enable dashboard

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Chris Sanders (chris.sanders) wrote :

I like the list comprehension it's a lot easier to understand than the break/else. We should rework that without the % comparison and instead fix the dashboards to not have missing metrics.

review: Disapprove

Unmerged commits

e42cf7b... by Drew Freiberger

Update dashboard generation to allow for 50% or more matching metrics to enable dashboard

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/grafana.py b/reactive/grafana.py
2index add41be..370686d 100644
3--- a/reactive/grafana.py
4+++ b/reactive/grafana.py
5@@ -44,6 +44,7 @@ GRAFANA_INI_TMPL = 'grafana.ini.j2'
6 GRAFANA_DEPS = ['libfontconfig1']
7 DASHBOARDS_BACKUP_CRON = '/etc/cron.d/juju-dashboards-backup'
8 DASHBOARDS_BACKUP_CRON_TMPL = 'juju-dashboards-backup.j2'
9+MIN_MATCHING_METRICS_FOR_DASH_PCT = 50
10
11
12 try:
13@@ -518,13 +519,15 @@ def generate_prometheus_dashboards(gf_adminpasswd, ds):
14 expr = str(re.findall('"expr":(.*),', template.read()))
15 metrics = re.findall('[a-zA-Z0-9]*_[a-zA-Z0-9_]*', expr)
16 if not metrics:
17- hookenv.log("Skipping Dashboard Template: {} no metrics"
18+ hookenv.log("Skipping Dashboard Template: {} no metrics in template"
19 " {}".format(filename, metrics))
20 continue
21- for metric in metrics:
22- if metric not in prom_metrics:
23- hookenv.log("Skipping Dashboard Template: {} no metric"
24- " {}".format(filename, metric))
25+ matching_metrics = [x for x in metrics if x in prom_metrics]
26+ missing_metrics = [x for x in metrics if x not in prom_metrics]
27+ matching_pct = (len(matching_metrics) / len(metrics)) * 100
28+ if matching_pct < MIN_MATCHING_METRICS_FOR_DASH_PCT:
29+ hookenv.log("Skipping Dashboard Template: {} missing metrics for"
30+ " {}".format(filename, missing_metrics))
31 break
32 else:
33 hookenv.log("Using Dashboard Template: {}".format(filename))

Subscribers

People subscribed via source and target branches