Merge ~xavpaice/charm-telegraf/+git/telegraf-charm:lp1799583 into ~telegraf-charmers/charm-telegraf:master

Proposed by Xav Paice
Status: Merged
Approved by: Paul Gear
Approved revision: 591ba4414da623be9a139503c24ab644b4f31a94
Merged at revision: 90c671d417508144c6ca9235da702c5b18fd3633
Proposed branch: ~xavpaice/charm-telegraf/+git/telegraf-charm:lp1799583
Merge into: ~telegraf-charmers/charm-telegraf:master
Diff against target: 101 lines (+40/-8)
2 files modified
reactive/telegraf.py (+33/-7)
templates/base_inputs.conf (+7/-1)
Reviewer Review Type Date Requested Status
Paul Gear (community) Approve
Review via email: mp+357729@code.launchpad.net

Commit message

Remove conntrack input if not available

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
Paul Gear (paulgear) wrote :

My only concern with this is that if conntrack is enabled sometime after the telegraf charm is installed. Say, on an NGFW where we can't guarantee ordering of the charm hook runs. I think there's a reactive hook somewhere (can't lay my hands on the name of it now) which will trigger when a file's contents change - if that were included as a trigger for reconfiguring the conntrack plugin, I'd be happy with this.

Revision history for this message
Paul Gear (paulgear) wrote :

Comments inline. This should work OK as-is, but I think the suggested changes are sufficiently small and simple that they should be done before merge.

review: Approve
Revision history for this message
Paul Gear (paulgear) wrote :

LGTM

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

Change successfully merged at revision 90c671d417508144c6ca9235da702c5b18fd3633

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/reactive/telegraf.py b/reactive/telegraf.py
2index 433829c..afcf181 100644
3--- a/reactive/telegraf.py
4+++ b/reactive/telegraf.py
5@@ -39,6 +39,7 @@ from charms.reactive.bus import get_states
6 from charmhelpers import context
7 from charmhelpers.core import hookenv, host, unitdata
8 from charmhelpers.core.templating import render
9+from charmhelpers.core.host import is_container
10 from charmhelpers.fetch import apt_cache
11 import charms.promreg
12
13@@ -50,8 +51,9 @@ CONFIG_FILE = 'telegraf.conf'
14
15 CONFIG_DIR = 'telegraf.d'
16
17-
18 # Utilities #
19+
20+
21 def exec_timeout_supported():
22 cache = apt_cache()
23 pkg = cache['telegraf']
24@@ -132,15 +134,21 @@ def get_remote_unit_name():
25 return rel['__unit__']
26
27
28-def render_base_inputs():
29+def get_base_inputs():
30+ """Make a structure for rendering the base_inputs template.
31+ Returns a dict of items for the template.
32+ """
33 extra_options = get_extra_options()
34- bcache = os.path.exists("/sys/fs/bcache")
35+ conntrack = os.path.exists("/proc/sys/net/netfilter/nf_conntrack_max")
36+ return {'extra_options': extra_options['inputs'],
37+ 'bcache': is_bcache(),
38+ 'conntrack': conntrack}
39+
40+
41+def render_base_inputs():
42 # use base inputs from charm templates
43 with open(os.path.join(get_templates_dir(), 'base_inputs.conf'), 'r') as fd:
44- return render_template(
45- fd.read(),
46- {'extra_options': extra_options['inputs'],
47- 'bcache': bcache})
48+ return render_template(fd.read(), get_base_inputs())
49
50
51 def get_extra_options():
52@@ -857,3 +865,21 @@ def start_or_restart():
53 else:
54 hookenv.status_set('blocked',
55 'Telegraf failed to start. Check config.')
56+
57+
58+def is_bcache():
59+ """
60+ return true if bcache is present, and this is not a container
61+ """
62+ container = is_container()
63+ return (os.path.exists("/sys/fs/bcache") and not container)
64+
65+
66+@hook('update-status')
67+def update_status():
68+ changed = charms.reactive.helpers.is_data_changed(
69+ 'detect_changes',
70+ get_base_inputs(),
71+ hash_type='sha256')
72+ if changed:
73+ remove_state('telegraf.configured')
74diff --git a/templates/base_inputs.conf b/templates/base_inputs.conf
75index 35cf2a7..5da4fb4 100644
76--- a/templates/base_inputs.conf
77+++ b/templates/base_inputs.conf
78@@ -71,16 +71,22 @@
79 [[inputs.system]]
80 # no configuration
81
82-{%- if bcache %}
83+{% if bcache -%}
84 [[inputs.bcache]]
85+
86 {%- endif %}
87
88 [[inputs.bond]]
89+ # no configuration
90
91+{% if conntrack -%}
92 [[inputs.conntrack]]
93 files = ["ip_conntrack_count","ip_conntrack_max", "nf_conntrack_count","nf_conntrack_max"]
94
95+{%- endif %}
96+
97 [[inputs.cgroup]]
98+ # no configuration
99
100 [[inputs.exec]]
101 commands = [

Subscribers

People subscribed via source and target branches

to all changes: