Merge ~ballot/charm-telegraf/+git/telegraf-charm:cRT135443 into charm-telegraf:master

Proposed by Benjamin Allot
Status: Work in progress
Proposed branch: ~ballot/charm-telegraf/+git/telegraf-charm:cRT135443
Merge into: charm-telegraf:master
Diff against target: 100 lines (+65/-0)
3 files modified
src/charmcraft.yaml (+18/-0)
src/metadata.yaml (+3/-0)
src/reactive/telegraf.py (+44/-0)
Reviewer Review Type Date Requested Status
Robert Gildein Needs Fixing
Tianqi Xiao (community) Needs Fixing
BootStack Reviewers Pending
BootStack Reviewers Pending
BootStack Reviewers mr tracking; do not claim Pending
Review via email: mp+425417@code.launchpad.net
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
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Unable to determine commit message from repository - please click "Set commit message" and enter the commit message manually.

Revision history for this message
Tianqi Xiao (txiao) wrote :

Thanks for the contribution. This proposed branch broke off from master at commit dec0633e (2021-04-09), which is pretty outdated. Could you please rebase it to the latest master and run tests again?

Please also see my inline comment.

Revision history for this message
Tianqi Xiao (txiao) :
review: Needs Fixing
Revision history for this message
Robert Gildein (rgildein) wrote :

I don't think we should add new features without unittests and functional tests. Unittests are definitely essential.

Revision history for this message
Robert Gildein (rgildein) :
review: Needs Fixing
Revision history for this message
Eric Chen (eric-chen) wrote :

Mark this review as WIP until the unit test available.

Unmerged commits

c9af14d... by Benjamin Allot

Add charmcraft support

ff1683c... by Benjamin Allot

Add cassandra relation

Relation with cassandra will configure a basic tcp check on the
listening address and the native_transport_port of cassandra to check
its readiness.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/charmcraft.yaml b/src/charmcraft.yaml
2new file mode 100644
3index 0000000..40922e4
4--- /dev/null
5+++ b/src/charmcraft.yaml
6@@ -0,0 +1,18 @@
7+type: "charm"
8+bases:
9+ - build-on:
10+ - name: "ubuntu"
11+ channel: "20.04"
12+ run-on:
13+ - name: "ubuntu"
14+ channel: "20.04"
15+ - name: "ubuntu"
16+ channel: "18.04"
17+ - name: "ubuntu"
18+ channel: "16.04"
19+
20+parts:
21+ charm:
22+ source: .
23+ plugin: reactive
24+ build-snaps: [charm]
25diff --git a/src/metadata.yaml b/src/metadata.yaml
26index bb9361d..1844733 100644
27--- a/src/metadata.yaml
28+++ b/src/metadata.yaml
29@@ -77,6 +77,9 @@ requires:
30 sentry:
31 interface: sentry-metrics
32 scope: container
33+ cassandra:
34+ interface: cassandra-metrics
35+ scope: container
36 provides:
37 dashboards:
38 interface: grafana-dashboard
39diff --git a/src/reactive/telegraf.py b/src/reactive/telegraf.py
40index 00051ca..5f19f26 100644
41--- a/src/reactive/telegraf.py
42+++ b/src/reactive/telegraf.py
43@@ -47,6 +47,7 @@ from charms.reactive import (
44 set_flag,
45 toggle_flag,
46 when,
47+ when_any,
48 when_not,
49 )
50 from charms.reactive.bus import get_states
51@@ -1913,6 +1914,49 @@ def grafana_dashboard_import_failed():
52 clear_flag("grafana.configured")
53
54
55+@when_any(
56+ "endpoint.cassandra.changed",
57+ "endpoint.cassandra.joined")
58+@when("telegraf.installed")
59+def cassandra_input():
60+ template = """
61+[[inputs.net_response]]
62+ protocol = "tcp"
63+ address = "{{ listen_address }}:{{ port }}"
64+"""
65+ config_path = "{}/{}.conf".format(get_configs_dir(), "cassandra")
66+
67+ rels = hookenv.relations_of_type("cassandra")
68+ if rels:
69+ for rel in rels:
70+ addr = rel["listen_address"]
71+ port = rel["native_transport_port"]
72+ input_config = render_template(template, {
73+ "listen_address": addr,
74+ "port": port,
75+ })
76+ hookenv.log("Updating {} plugin config file".format("cassandra"))
77+ host.write_file(config_path, input_config.encode("utf-8"))
78+ set_flag("plugins.cassandra.configured")
79+ elif os.path.exists(config_path):
80+ os.unlink(config_path)
81+ clear_flag("plugins.cassandra.configured")
82+
83+ set_flag("telegraf.needs_reload")
84+
85+
86+@when_not("cassandra.available")
87+@when("plugins.exec.configured")
88+def cassandra_input_departed():
89+ config_path = "{}/{}.conf".format(get_configs_dir(), "cassandra")
90+ rels = hookenv.relations_of_type("cassandra")
91+ if not rels:
92+ clear_flag("plugins.cassandra.configured")
93+ if os.path.exists(config_path):
94+ os.unlink(config_path)
95+ set_flag("telegraf.needs_reload")
96+
97+
98 @when("telegraf.needs_reload")
99 @when("telegraf.installed")
100 @when("telegraf.configured")

Subscribers

People subscribed via source and target branches

to all changes: