Add relabel_configs section to targets config

Add host label to exporters grain generator

Change-Id: I0a8cbf27ebcf724fe2bf7f547a30080d94198592
PROD-related: PROD-18671
This commit is contained in:
Dmitry Kalashnik 2018-03-27 13:45:06 +04:00
parent 846332b40d
commit 93992a0742
2 changed files with 31 additions and 0 deletions

View file

@ -33,6 +33,11 @@
- regex: {{ address }}:{{ svc_parameters.bind.port }}
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 %}

View file

@ -65,12 +65,18 @@ rule_files:
{%- 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 @@ scrape_configs:
{%- 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 %}