federate job configuration does not seem to work

Bug #2034526 reported by Nishant Dash
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Prometheus2 charm
Fix Released
Undecided
Unassigned

Bug Description

- When I configure this example federate job through the charm config `federate-config`,
```
- job_name: 'mesh-federate'
  scrape_interval: 2m
  scrape_timeout: 1m
  honor_labels: true
  metrics_path: '/federate'
  params:
    'match[]':
      - '{__name__=~".+"}'
  static_configs:
    - targets:
      - '<FQDN of other prometheus server>:9090'
```

- The job does not show up.
  In the Prometheus UI -> Status -> Configuration, I see
```
- job_name: mesh-federate
  honor_labels: true
  honor_timestamps: true
  params:
    match[]:
    - '{__name__=~".+"}'
  scrape_interval: 15s
  scrape_timeout: 15s
  metrics_path: /federate
  scheme: http
  follow_redirects: true
  enable_http2: true
  static_configs:
  - targets: []
    labels:
      group: promoagents-federate
```

As such, the target is missing and the scrape interval and timeout seem to be from the charm configs `scrape-timeout` and `scrape-interval` instead.

This charm is stable, 48.

Related branches

Nishant Dash (dash3)
description: updated
Revision history for this message
Nishant Dash (dash3) wrote :

The jinja template does NOT grab scrape timeout and interval in the federate config section

```
# federate jobs
{%- if federate %}
{%- for job in federate %}
  - job_name: '{{ job['job_name'] }}'
    honor_labels: true
{%- if job.get('metrics_path') %}
    metrics_path: {{ job['metrics_path'] }}
{%- else %}
    metrics_path: /federate
{%- endif %}
{%- if job.get('scheme') %}
    scheme: {{ job['scheme'] }}
{%- endif %}
    params:
{%- for param, values in job['params'].items() %}
      '{{ param }}':
{%- for value in values %}
        - '{{ value }}'
{%- endfor %}
{%- endfor %}
    static_configs:
      - targets:
{%- for target in job['targets'] %}
          - {{ target }}
{%- endfor %}
        labels:
{%- if job.get('label') %}
          group: '{{job['label']}}'
{%- else %}
          group: 'promoagents-federate'
{%- endif %}
{%- endfor %}
{%- endif %}
```

Revision history for this message
Nishant Dash (dash3) wrote :

following the code, I see it outputs the template to `/var/snap/prometheus/current/prometheus.yml`
which has
```
# federate jobs
  - job_name: 'mesh-federate'
    honor_labels: true
    metrics_path: /federate
    params:
      'match[]':
        - '{__name__=~".+"}'
    static_configs:
      - targets:
        labels:
          group: 'promoagents-federate'

```

Revision history for this message
Nishant Dash (dash3) wrote (last edit ):

I was able to see the job targets needed by changing the target snippet to
``` - targets:
{%- for item in job['static_configs'] %}
{%- for target in item['targets'] %}
          - {{ target }}
{%- endfor %}
{%- endfor %}
```

Tianqi Xiao (txiao)
Changed in charm-prometheus2:
status: New → Fix Committed
milestone: none → 23.10
Tianqi Xiao (txiao)
Changed in charm-prometheus2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.