Skip to content

Conversation

@Myracle
Copy link
Contributor

@Myracle Myracle commented Feb 11, 2026

What is the purpose of the change

This pull request adds HTTP Basic Authentication support for the PrometheusPushGatewayReporter. This enables users to connect Flink metrics reporting to secured PushGateway instances that require authentication.

Many production deployments secure their PushGateway endpoints with authentication to prevent unauthorized metrics submission. Without this feature, users would need to configure network-level security (firewalls, VPNs) to protect the PushGateway, which is often more complex and less flexible than application-level authentication.

Brief change log

  • Added username and password configuration options to PrometheusPushGatewayReporterOptions for specifying HTTP Basic Auth credentials
  • Updated PrometheusPushGatewayReporter to configure BasicAuthHttpConnectionFactory when both credentials are provided
  • Updated PrometheusPushGatewayReporterFactory to read credentials from configuration and emit a warning log when only one of username/password is configured (incomplete configuration)
  • Added unit tests to cover all authentication scenarios (no auth, partial auth with warning, complete auth)
  • Updated documentation (both English and Chinese) with configuration examples and security recommendations

Verifying this change

This change added tests and can be verified as follows:

  • Added PrometheusPushGatewayReporterTest#testBasicAuthNotEnabledWithoutCredentials - verifies reporter creation without credentials
  • Added PrometheusPushGatewayReporterTest#testBasicAuthNotEnabledWithOnlyUsername - verifies warning log when only username is configured
  • Added PrometheusPushGatewayReporterTest#testBasicAuthNotEnabledWithOnlyPassword - verifies warning log when only password is configured
  • Added PrometheusPushGatewayReporterTest#testBasicAuthEnabledWithBothCredentials - verifies reporter creation with complete credentials

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no (uses existing simpleclient_pushgateway dependency which already includes BasicAuthHttpConnectionFactory)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): yes (added new configuration options username and password to PrometheusPushGatewayReporterOptions which is annotated with @PublicEvolving)
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? docs (updated docs/content/docs/deployment/metric_reporters.md and docs/content.zh/docs/deployment/metric_reporters.md)

@flinkbot
Copy link
Collaborator

flinkbot commented Feb 11, 2026

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@@ -70,17 +72,28 @@ public PrometheusPushGatewayReporter createMetricReporter(Properties properties)
jobName = configuredJobName + new AbstractID();
}

String username = metricConfig.getString(USERNAME.key(), null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor consistency nit: for consistency, we may want to use defaultValue() instead of null here as those would both functionally identical (null) but would follow the same pattern as the other available configuration options.

For example, HOST_URL:

String hostUrl = metricConfig.getString(HOST_URL.key(), HOST_URL.defaultValue());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! You're absolutely right - I've updated the code to use USERNAME.defaultValue() and PASSWORD.defaultValue() instead of hardcoded null to maintain consistency with other configuration options like HOST_URL.

metricConfig.setProperty(USERNAME.key(), "flink-user");
metricConfig.setProperty(PASSWORD.key(), "flink-password");
// Both username and password configured - Basic Auth should be enabled
PrometheusPushGatewayReporter reporter = factory.createMetricReporter(metricConfig);
Copy link
Contributor

@rionmonster rionmonster Feb 11, 2026

Choose a reason for hiding this comment

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

I think we need to add another assertion to this test to verify that authentication was actually enabled. We may want to consider following a pattern similar to hostUrl to expose it for testing (e.g. @VisibleForTesting package-private boolean field), something like basicAuthEnabled and then we could simply check that property here:

assertThat(reporter.basicAuthEnabled).isTrue();

Either that or rely on a reflection based approach to inspect the underlying connection factory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I've added a @VisibleForTesting boolean basicAuthEnabled field following the same pattern as hostUrl. Now all four basic auth test cases verify this property:
testBasicAuthNotEnabledWithoutCredentials - asserts basicAuthEnabled is false
testBasicAuthNotEnabledWithOnlyUsername - asserts basicAuthEnabled is false
testBasicAuthNotEnabledWithOnlyPassword - asserts basicAuthEnabled is false
testBasicAuthEnabledWithBothCredentials - asserts basicAuthEnabled is true

@github-actions github-actions bot added the community-reviewed PR has been reviewed by the community. label Feb 11, 2026
hostUrl,
jobName,
randomSuffix,
deleteOnShutdown,
groupingKey);
groupingKey,
username != null && password != null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit: this can probably align with the recently added basicAuthEnabled flag to avoid the redundant logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants