Skip to content

[metrics][docs] Support Basic Auth for Prometheus PushGateway reporter#3552

Open
Guosmilesmile wants to merge 3 commits into
apache:mainfrom
Guosmilesmile:prometheus_author
Open

[metrics][docs] Support Basic Auth for Prometheus PushGateway reporter#3552
Guosmilesmile wants to merge 3 commits into
apache:mainfrom
Guosmilesmile:prometheus_author

Conversation

@Guosmilesmile

@Guosmilesmile Guosmilesmile commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #xxx

Currently PrometheusPushGatewayReporter sends metrics to the Prometheus PushGateway anonymously. In production, PushGateway is often placed behind has its own basic auth enabled, which makes the reporter unusable in secured deployments.

This PR adds first-class support for Basic Auth on the prometheus-push reporter.

Brief change log

  • Add two new config options:
    • metrics.reporter.prometheus-push.username
    • metrics.reporter.prometheus-push.password
  • PrometheusPushGatewayReporter now injects
    io.prometheus.client.exporter.BasicAuthHttpConnectionFactory into the underlying PushGateway when a username is configured; otherwise the behavior is unchanged (no Authorization header is sent).
  • PrometheusPushGatewayReporterPlugin reads the two new options and passes them to the reporter. A basicAuthEnabled flag is logged instead of the raw credentials, so passwords are never printed.

Tests

API and Format

Documentation

Add the config to the doc

this.pushInterval = pushInterval;
if (username != null && !username.isEmpty()) {
this.pushGateway.setConnectionFactory(
basicAuthConnectionFactory(username, password == null ? "" : password));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not reuse Prometheus' built-in BasicAuthHttpConnectionFactory because it relies on javax.xml.bind.DatatypeConverter for Base64 encoding, which has been removed from the JDK since Java 9 (JEP 320). Using java.util.Base64 keeps this reporter compatible with JDK 8+.

This issue has been resolved at the underlying level in higher versions of the Prometheus dependency, but the current 0.8 version does not include the fix. Upgrading the version rashly may cause problems, so we resolve it here with our own implementation.

@Guosmilesmile Guosmilesmile changed the title [metrics] Support Basic Auth for Prometheus PushGateway reporter Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant