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

Proposed by Benjamin Allot
Status: Rejected
Rejected by: Haw Loeung
Proposed branch: ~ballot/charm-telegraf/+git/telegraf-charm:add_relations
Merge into: ~telegraf-charmers/charm-telegraf:master
Diff against target: 75 lines (+45/-0)
3 files modified
layer.yaml (+1/-0)
metadata.yaml (+3/-0)
reactive/telegraf.py (+41/-0)
Reviewer Review Type Date Requested Status
BootStack Reviewers mr tracking; do not claim Pending
BootStack Reviewers Pending
BootStack Reviewers Pending
Telegraf Charmers Pending
Review via email: mp+373538@code.launchpad.net
To post a comment you must log in.

Unmerged commits

5788930... by Benjamin Allot

Add input-prometheus interface

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/layer.yaml b/layer.yaml
2index 7c1b2bd..15fe2fc 100644
3--- a/layer.yaml
4+++ b/layer.yaml
5@@ -30,6 +30,7 @@ includes:
6 - interface:prometheus-rules
7 - interface:rabbitmq
8 - interface:redis
9+ - interface:input-prometheus
10 options:
11 basic:
12 use_venv: true
13diff --git a/metadata.yaml b/metadata.yaml
14index bf43b34..900f0f5 100644
15--- a/metadata.yaml
16+++ b/metadata.yaml
17@@ -72,6 +72,9 @@ requires:
18 sentry:
19 interface: sentry-metrics
20 scope: container
21+ input-prometheus:
22+ interface: input-prometheus
23+ scope: container
24 provides:
25 prometheus-client:
26 interface: http
27diff --git a/reactive/telegraf.py b/reactive/telegraf.py
28index 4ad854c..1ef46f2 100644
29--- a/reactive/telegraf.py
30+++ b/reactive/telegraf.py
31@@ -969,3 +969,44 @@ def update_status():
32 hash_type='sha256')
33 if changed:
34 clear_flag('telegraf.configured')
35+
36+
37+@when('input-prometheus.available')
38+def input_prometheus(urls):
39+ """Add a relation for prometheus input.
40+
41+ Allow telefraf to scrape a list of urls in prometheus format.
42+ """
43+ template = """
44+[[inputs.internal]]
45+
46+[[inputs.prometheus]]
47+ urls = {{ urls }}
48+"""
49+ config_path = '{0}/{1}.conf'.format(get_configs_dir(), 'input-prometheus')
50+ rels = hookenv.relations_of_type('input-prometheus')
51+ prom_urls = []
52+ for rel in rels:
53+ enabled = rel.get('enabled', False)
54+ # Juju gives us a string instead of a boolean, fix it
55+ if isinstance(enabled, str):
56+ if enabled in ['y', 'yes', 'true', 't', 'on', 'True']:
57+ enabled = True
58+ else:
59+ enabled = False
60+ if not enabled:
61+ continue
62+ addr = rel['private-address']
63+ if addr == hookenv.unit_private_ip():
64+ addr = "localhost"
65+ port = rel['port']
66+ prom_url = 'http://{0}:{1}/metrics'.format(addr, port)
67+ prom_urls.append(prom_url)
68+ if prom_urls:
69+ input_config = render_template(template, {"urls": json.dumps(prom_urls)})
70+ hookenv.log("Updating {0} plugin config file".format('input-prometheus'))
71+ host.write_file(config_path, input_config.encode('utf-8'))
72+ set_flag('plugins.input-prometheus.configured')
73+ elif os.path.exists(config_path):
74+ os.unlink(config_path)
75+ set_flag('telegraf.needs_reload')

Subscribers

People subscribed via source and target branches

to all changes: