# (C) Copyright 2017 Hewlett Packard Enterprise Development LP

init_config:
  timeout: {{ PROMETHEUS_TIMEOUT | default(3) }}
{% if not PROMETHEUS_ENDPOINTS %}
  auto_detect_endpoints: true
  detect_method: {{ PROMETHEUS_DETECT_METHOD | default('pod') }}
{% endif %}

instances:
{% if PROMETHEUS_ENDPOINTS %}
  {% for endpoint in PROMETHEUS_ENDPOINTS.split(',') %}
    {% if '|' in endpoint %}
      {% set endpoint, dimensions = endpoint.split('|', 2) %}
      {% set dimensions = dimensions.split('&') %}
    {% else %}
      {% set dimensions = [] %}
    {% endif %}
  - metric_endpoint: "{{ endpoint }}"
    {% if dimensions %}
    default_dimensions:
      {% for dimension in dimensions %}
        {% set k, v = dimension.split('=', 1) %}
      {{k}}: {{v}}
      {% endfor %}
    {% endif %}
  {% endfor %}
{% else %}
  {% if PROMETHEUS_KUBERNETES_LABELS %}
  - kubernetes_labels:
    {% for label in PROMETHEUS_KUBERNETES_LABELS.split(',') %}
    - {{ label }}
    {% endfor %}
  {% else %}
  - kubernetes_labels: ['app']
  {% endif %}
{% endif %}
