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
diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
index e3fcad3..1fbe002 100644
--- a/src/reactive/telegraf.py
+++ b/src/reactive/telegraf.py
@@ -546,7 +546,10 @@ def configure_telegraf(): # noqa: C901
546 # add extra juju-related tags to be exposed as labels546 # add extra juju-related tags to be exposed as labels
547 tags.append('juju_application = "{}"'.format(get_remote_unit_name().split("/")[0]))547 tags.append('juju_application = "{}"'.format(get_remote_unit_name().split("/")[0]))
548 tags.append('juju_unit = "{}"'.format(get_remote_unit_name().replace("/", "-")))548 tags.append('juju_unit = "{}"'.format(get_remote_unit_name().replace("/", "-")))
549 tags.append('juju_model = "{}"'.format(hookenv.model_name()))549 try:
550 tags.append('juju_model = "{}"'.format(hookenv.model_name()))
551 except KeyError:
552 pass # support older Juju 1.x deploys
550 context["tags"] = tags553 context["tags"] = tags
551554
552 if inputs:555 if inputs:
diff --git a/src/tests/unit/test_telegraf.py b/src/tests/unit/test_telegraf.py
index 56da00f..1b97b91 100644
--- a/src/tests/unit/test_telegraf.py
+++ b/src/tests/unit/test_telegraf.py
@@ -843,7 +843,7 @@ outputs:
843 assert expected in config_file.read()843 assert expected in config_file.read()
844844
845845
846def test_default_tags(monkeypatch, config):846def test_default_tags_juju2(monkeypatch, config):
847 monkeypatch.setattr(telegraf.hookenv, "principal_unit", lambda: "principal-unit")847 monkeypatch.setattr(telegraf.hookenv, "principal_unit", lambda: "principal-unit")
848 monkeypatch.setattr(telegraf.hookenv, "open_port", lambda p: None)848 monkeypatch.setattr(telegraf.hookenv, "open_port", lambda p: None)
849 telegraf.configure_telegraf()849 telegraf.configure_telegraf()
@@ -863,6 +863,25 @@ def test_default_tags(monkeypatch, config):
863 assert expected in config_file.read()863 assert expected in config_file.read()
864864
865865
866def test_default_tags_juju1(monkeypatch, config):
867 monkeypatch.setattr(telegraf.hookenv, "principal_unit", lambda: "principal-unit")
868 monkeypatch.setattr(telegraf.hookenv, "open_port", lambda p: None)
869 monkeypatch.delitem(os.environ, "JUJU_MODEL_NAME") # no models in Juju 1.x
870 telegraf.configure_telegraf()
871 expected = """
872[tags]
873 # dc = "us-east-1" # will tag all metrics with dc=us-east-1
874 # rack = "1a"
875
876 juju_application = "remote-unit"
877
878 juju_unit = "remote-unit-0"
879
880"""
881 config_file = base_dir().join("telegraf.conf")
882 assert expected in config_file.read()
883
884
866# Plugin tests885# Plugin tests
867886
868887

Subscribers

People subscribed via source and target branches

to all changes: