Add relabel_configs section to targets config
Add host label to exporters grain generator
Change-Id: I0a8cbf27ebcf724fe2bf7f547a30080d94198592
PROD-related: PROD-18671
diff --git a/prometheus/_exporters_config.sls b/prometheus/_exporters_config.sls
index 2974b46..49fa91e 100644
--- a/prometheus/_exporters_config.sls
+++ b/prometheus/_exporters_config.sls
@@ -34,6 +34,11 @@
replacement: {{ host }}
source_labels: "instance"
target_label: "host"
+ relabel_configs:
+ - regex: {{ address }}:{{ svc_parameters.bind.port }}
+ replacement: {{ host }}
+ source_labels: "__address__"
+ target_label: "host"
{%- endif %}
{%- endif %}
{%- endfor %}
diff --git a/prometheus/files/server/prometheus.yml b/prometheus/files/server/prometheus.yml
index 250235e..3bb85f7 100644
--- a/prometheus/files/server/prometheus.yml
+++ b/prometheus/files/server/prometheus.yml
@@ -65,12 +65,18 @@
{%- if static_target[job_name]['metric_relabel'] is not defined %}
{%- do static_target[job_name].update({'metric_relabel': []}) %}
{%- endif %}
+ {%- if static_target[job_name]['relabel_configs'] is not defined %}
+ {%- do static_target[job_name].update({'relabel_configs': []}) %}
+ {%- endif %}
{%- for target in job.get('endpoint', []) %}
{%- do static_target[job_name]['endpoint'].append(target) %}
{%- endfor %}
{%- for label in job.get('metric_relabel', []) %}
{%- do static_target[job_name]['metric_relabel'].append(label) %}
{%- endfor %}
+ {%- for label in job.get('relabel_configs', []) %}
+ {%- do static_target[job_name]['relabel_configs'].append(label) %}
+ {%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endif %}
@@ -128,6 +134,26 @@
{%- endif %}
{%- endfor %}
{%- endif %}
+ {%- if job.get('relabel_configs') %}
+ relabel_configs:
+ {%- for label in job.get('relabel_configs', []) %}
+ {%- if label.source_labels is string %}
+ {%- set label_list = label.source_labels.split(',') %}
+ {%- elif label.source_labels is list %}
+ {%- set label_list = label.source_labels %}
+ {%- endif %}
+ {%- if label_list is defined %}
+ - source_labels: {{ label_list }}
+ regex: "{{ label.regex }}"
+ {%- if label.get('target_label') %}
+ target_label: "{{ label.target_label }}"
+ {%- endif %}
+ {%- if label.get('replacement') %}
+ replacement: "{{ label.replacement }}"
+ {%- endif %}
+ {%- endif %}
+ {%- endfor %}
+ {%- endif %}
{%- endif %}
{%- endfor %}