Skip to content

Commit 035b54f

Browse files
authored
Handle specific exporter ports
1 parent faa25ff commit 035b54f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

handle_prometheus.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,24 @@ def add_exporters_to_prometheus_config(policy, template_file, config_file):
147147
exp = exporter_endpoint.split(':')
148148
if len(exp) == 1:
149149
continue
150-
static_config['targets'].append(exporter_endpoint)
150+
elif '.' not in exp[0]:
151+
kube_job = [x for x in config_content['scrape_configs'] if x.get('job_name') == 'kube-services']
152+
if not kube_job:
153+
continue
154+
relabel = kube_job[0].get('relabel_configs', [])
155+
old_label = [x for x in relabel if x.get('action') == 'keep']
156+
if old_label:
157+
old_label = old_label[0]
158+
old_regex = old_label.get('regex')
159+
new_regex = '{}|.*{}'.format(old_regex, exp[1])
160+
old_label['regex'] = new_regex
161+
else:
162+
label = {'source_labels': ['__address__'],
163+
'action': 'keep',
164+
'regex': '.*{}'.format(exp[1])}
165+
relabel.append(label)
166+
else:
167+
static_config['targets'].append(exporter_endpoint)
151168
config_changed = True
152169
log.info('(C) => exporter "{0}" added to config'.format(exporter_endpoint))
153170
else:

0 commit comments

Comments
 (0)