Skip to content

/metrics endpoint should set Content-Type: text/plain; version=0.0.4 (Prometheus exposition format) #26

Description

@jantman

Background

The metrics endpoint (metrics.py) currently returns the Prometheus exposition body with:

Response(output, mimetype="text/plain; charset=utf-8")

That Content-Type has no version=0.0.4. Prometheus v2 tolerated this (it silently fell back to the 0.0.4 text format), but Prometheus v3 fails the scrape on a missing/unknown format version.

This surfaced during the DecaturMakers monitoring stack's Prometheus v2 → v3 upgrade. As a stopgap, the kiosk scrape job in dm-puppet now sets fallback_scrape_protocol: PrometheusText0.0.4, but the proper fix is to emit a correct Content-Type here so that shim can be removed.

The fix

Use prometheus_client's canonical content type instead of a hand-written one:

from prometheus_client import CONTENT_TYPE_LATEST, generate_latest
# ...
return Response(generate_latest(registry), mimetype=CONTENT_TYPE_LATEST)

CONTENT_TYPE_LATEST is text/plain; version=0.0.4; charset=utf-8.

Done when

  • /metrics responds with Content-Type: text/plain; version=0.0.4; charset=utf-8
  • New image released and the dmpuppet::internals::kiosk_show tag bumped in dm-puppet
  • The fallback_scrape_protocol line is removed from the kiosk job in dm-puppet's prometheus.yml, and the kiosk target still scrapes on Prometheus v3

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions