Merge ~dparv/charm-telegraf:fix_1891943 into charm-telegraf:master

Proposed by Diko Parvanov
Status: Superseded
Proposed branch: ~dparv/charm-telegraf:fix_1891943
Merge into: charm-telegraf:master
Diff against target: 81 lines (+21/-10)
3 files modified
src/config.yaml (+4/-2)
src/reactive/telegraf.py (+15/-6)
src/tests/unit/test_telegraf.py (+2/-2)
Reviewer Review Type Date Requested Status
🤖 prod-jenkaas-bootstack (community) continuous-integration Needs Fixing
Canonical IS Reviewers Pending
BootStack Reviewers Pending
BootStack Reviewers Pending
Review via email: mp+412628@code.launchpad.net

This proposal has been superseded by a proposal from 2022-01-24.

Commit message

Fixes for bug 1891943

Description of the change

- prometheus_datasource now defaults to ""
- relation prometheus-client is used to parse the related application
name for prometheus from the related unit name
- prometheus_datasource will override this setting
- fixed lint/black

To post a comment you must log in.
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

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
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Xav Paice (xavpaice) wrote :

CI failed on charm build due to the move of the nrpe-external-master interface. I've retriggered the CI run.

Other than CI, change LGTM.

Unmerged commits

295b888... by Diko Parvanov

Fixes for bug 1891943

- prometheus_datasource now defaults to ""
- relation prometheus-client is used to parse the related application
name for prometheus from the related unit name
- prometheus_datasource will override this setting
- fixed lint/black

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/config.yaml b/src/config.yaml
2index 6bc4da8..591d434 100644
3--- a/src/config.yaml
4+++ b/src/config.yaml
5@@ -197,11 +197,13 @@ options:
6 description: >
7 Comma separated list of nagios servicegroups for the telegraf check
8 prometheus_datasource:
9- default: "prometheus"
10+ default: ""
11 type: string
12 description: >
13 Specifies the datasource for Grafana dashboards. This usually corresponds
14- to the application name of the related Prometheus. Defaults to "prometheus".
15+ to the application name of the related Prometheus. Defaults to "" to
16+ use the prometheus-client relation to parse the application name. If set
17+ it will override the relation data.
18
19 Note: The complete datasource inserted into dashboard will be
20 "$prometheus_datasource - Juju generated source"
21diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
22index ba2e170..2cf3a47 100644
23--- a/src/reactive/telegraf.py
24+++ b/src/reactive/telegraf.py
25@@ -1362,7 +1362,7 @@ def redis_input(redis):
26 @when("endpoint.postfix.joined")
27 @when_not("apt.installed.acl")
28 def install_acl_package():
29- apt.queue_install(['acl'])
30+ apt.queue_install(["acl"])
31
32
33 @when("endpoint.postfix.joined")
34@@ -1390,9 +1390,9 @@ def postfix_input(postfix, spool="/var/spool/postfix"):
35 host.write_file(config_path, input_config.encode("utf-8"))
36
37 # https://github.com/influxdata/telegraf/blob/master/plugins/inputs/postfix/README.md#permissions
38- cmd = ['setfacl', '-Rm', 'g:{}:rX'.format(get_telegraf_group()), spool]
39+ cmd = ["setfacl", "-Rm", "g:{}:rX".format(get_telegraf_group()), spool]
40 subprocess.call(cmd)
41- cmd = ['setfacl', '-dm', 'g:{}:rX'.format(get_telegraf_group()), spool]
42+ cmd = ["setfacl", "-dm", "g:{}:rX".format(get_telegraf_group()), spool]
43 subprocess.call(cmd)
44
45 set_flag("plugins.postfix.configured")
46@@ -1794,9 +1794,18 @@ def register_grafana_dashboard():
47
48
49 def _load_grafana_dashboard(dashboard_data):
50- prometheus_datasource = "{} - Juju generated source".format(
51- hookenv.config().get("prometheus_datasource", "prometheus")
52- )
53+
54+ related_prometheus_app = None
55+ for relation_id in hookenv.relation_ids("prometheus-client"):
56+ for unit in hookenv.related_units(relation_id):
57+ related_prometheus_app = unit[0 : unit.find("/")] # noqa W203
58+
59+ if related_prometheus_app:
60+ prometheus_app = related_prometheus_app
61+ else:
62+ prometheus_app = hookenv.config().get("prometheus_datasource", "prometheus")
63+
64+ prometheus_datasource = "{} - Juju generated source".format(prometheus_app)
65 dashboard_context = dict(datasource=prometheus_datasource)
66 dashboard_context.update(dashboard_data.get("context_vars", {}))
67 return render_custom(
68diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
69index e9dc1f1..e4d3b54 100644
70--- a/src/tests/unit/test_telegraf.py
71+++ b/src/tests/unit/test_telegraf.py
72@@ -957,8 +957,8 @@ def test_postfix_input_no_relations(monkeypatch):
73 monkeypatch.setattr(telegraf.hookenv, "relations_of_type", lambda n: [])
74 telegraf.postfix_input("test")
75 assert not configs_dir().join("postfix.conf").exists()
76- with open(configs_dir().join("postfix.conf"), 'w') as f:
77- f.write('blah blah')
78+ with open(configs_dir().join("postfix.conf"), "w") as f:
79+ f.write("blah blah")
80 telegraf.postfix_input("test", spool="/tmp")
81 assert not configs_dir().join("postfix.conf").exists()
82

Subscribers

People subscribed via source and target branches

to all changes: