Merge ~barryprice/charm-telegraf:master into charm-telegraf:master

Proposed by Barry Price
Status: Merged
Approved by: Barry Price
Approved revision: b5d62012ca9743939efd436484217c4c5cdf19fd
Merged at revision: ac37632f6f4719ba3e58712ec0ec6989665faa55
Proposed branch: ~barryprice/charm-telegraf:master
Merge into: charm-telegraf:master
Diff against target: 53 lines (+24/-2)
2 files modified
src/reactive/telegraf.py (+4/-1)
src/tests/unit/test_telegraf.py (+20/-1)
Reviewer Review Type Date Requested Status
Benjamin Allot Approve
BootStack Reviewers Pending
Review via email: mp+398950@code.launchpad.net

Commit message

Support older Juju 1.x deploys where hookenv.model_name() is undefined

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
Benjamin Allot (ballot) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision ac37632f6f4719ba3e58712ec0ec6989665faa55

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
2index e3fcad3..1fbe002 100644
3--- a/src/reactive/telegraf.py
4+++ b/src/reactive/telegraf.py
5@@ -546,7 +546,10 @@ def configure_telegraf(): # noqa: C901
6 # add extra juju-related tags to be exposed as labels
7 tags.append('juju_application = "{}"'.format(get_remote_unit_name().split("/")[0]))
8 tags.append('juju_unit = "{}"'.format(get_remote_unit_name().replace("/", "-")))
9- tags.append('juju_model = "{}"'.format(hookenv.model_name()))
10+ try:
11+ tags.append('juju_model = "{}"'.format(hookenv.model_name()))
12+ except KeyError:
13+ pass # support older Juju 1.x deploys
14 context["tags"] = tags
15
16 if inputs:
17diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
18index 56da00f..1b97b91 100644
19--- a/src/tests/unit/test_telegraf.py
20+++ b/src/tests/unit/test_telegraf.py
21@@ -843,7 +843,7 @@ outputs:
22 assert expected in config_file.read()
23
24
25-def test_default_tags(monkeypatch, config):
26+def test_default_tags_juju2(monkeypatch, config):
27 monkeypatch.setattr(telegraf.hookenv, "principal_unit", lambda: "principal-unit")
28 monkeypatch.setattr(telegraf.hookenv, "open_port", lambda p: None)
29 telegraf.configure_telegraf()
30@@ -863,6 +863,25 @@ def test_default_tags(monkeypatch, config):
31 assert expected in config_file.read()
32
33
34+def test_default_tags_juju1(monkeypatch, config):
35+ monkeypatch.setattr(telegraf.hookenv, "principal_unit", lambda: "principal-unit")
36+ monkeypatch.setattr(telegraf.hookenv, "open_port", lambda p: None)
37+ monkeypatch.delitem(os.environ, "JUJU_MODEL_NAME") # no models in Juju 1.x
38+ telegraf.configure_telegraf()
39+ expected = """
40+[tags]
41+ # dc = "us-east-1" # will tag all metrics with dc=us-east-1
42+ # rack = "1a"
43+
44+ juju_application = "remote-unit"
45+
46+ juju_unit = "remote-unit-0"
47+
48+"""
49+ config_file = base_dir().join("telegraf.conf")
50+ assert expected in config_file.read()
51+
52+
53 # Plugin tests
54
55

Subscribers

People subscribed via source and target branches

to all changes: