Skip to content

Conversation

@barryib
Copy link

@barryib barryib commented Jan 16, 2026

What is the purpose of the change

This pull request adds support for passing the Datadog API Key via an environment variable (DATADOG_API_KEY) instead of only through configuration properties. This enables secure credential management in containerized and cloud-native deployments where environment variables are commonly used.

Why: We utilize a GitOps workflow with ArgoCD to deploy the Flink operator and applications. Since we cannot commit sensitive data like the Datadog API key to our repository, injecting it during deployment has proven difficult.

This simplifies our secret management by allowing us to use the External Secrets Operator. We can now sync the API key to a Kubernetes Secret and inject it securely into the application using envFrom.

Brief change log

  • Add DD_API_KEY environment variable support in DatadogHttpReporterFactory
  • Configuration property apikey takes precedence over environment variable for backward compatibility
  • Environment variable provides fallback when no configuration property is provided
  • Add comprehensive test suite with 9 test cases covering environment variable support and various configuration scenarios

Resolves FLINK-36456 FLINK-33994

Related to:

API Key Resolution Order

The API key is resolved in the following priority order:

  1. Configuration property apikey (if provided and non-empty)
  2. Environment variable DD_API_KEY (fallback)
  3. null (if neither is provided)

Verifying this change

This change added tests and can be verified as follows:

  • Added 5 test cases validating environment variable support:
    • testMetricReporterSetupViaSPI - Verifies metric reporter can be created via SPI
    • testApiKeyFromConfigurationProperty - Verifies API key from config property works
    • testApiKeyFromEnvironmentVariable - Tests environment variable fallback using Mockito
    • testConfigurationPropertyTakesPrecedenceOverEnvironmentVariable - Ensures config takes priority over env var
    • testEmptyConfigurationPropertyFallsBackToEnvironmentVariable - Tests fallback when config is empty
  • All tests use Mockito's mockStatic() instead of reflection-based environment manipulation to avoid Java module issues
  • All existing tests remain unchanged and pass
  • The change is backward compatible with existing configurations

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

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): no
  • 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? JavaDocs - The getApiKey() method includes comprehensive JavaDoc explaining the resolution order and behavior

@barryib barryib changed the title feat: Add support to pass Datadog API Key as environment variable [FLINK-36456] feat: Add support to pass Datadog API Key as environment variable Jan 16, 2026
@flinkbot
Copy link
Collaborator

flinkbot commented Jan 16, 2026

CI report:

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

@barryib barryib force-pushed the feature/datadog-api-key-env-var branch from 2659790 to 00bac62 Compare January 16, 2026 16:11
@barryib
Copy link
Author

barryib commented Jan 18, 2026

@flinkbot run azure

@barryib barryib force-pushed the feature/datadog-api-key-env-var branch 2 times, most recently from c0a2c09 to f2c8ba0 Compare January 19, 2026 09:46
@barryib
Copy link
Author

barryib commented Jan 19, 2026

@flinkbot run azure

@barryib
Copy link
Author

barryib commented Jan 19, 2026

@zentol @molsionmo can I get your attention on this PR please. It has been closed for few times. I tried to add tests

@barryib
Copy link
Author

barryib commented Jan 19, 2026

cc @pinxiu for info

@barryib
Copy link
Author

barryib commented Jan 19, 2026

@Sxnan is it possible to review this PR please 🙏🏽

@davidradl
Copy link
Contributor

I cant find the Jira - do you mean FLINK-33994

* @param config the configuration properties
* @return the Datadog API key, or null if not found in either location
*/
private String getApiKey(Properties config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

On the whole this change seems reasonable. Some points to raise:

  • would it not make sense for the environment variable to be honoured, so you can override the configuration at a more granular level?
  • Could you add this environment variable name and usage to the English and Chinese docs.
  • I notice the docs say
    "On Docker-based deployments, you can use the FLINK_PROPERTIES environment variable for passing configuration values." Does this help you resolve this issue without this fix?

Copy link
Author

@barryib barryib Jan 22, 2026

Choose a reason for hiding this comment

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

@davidradl Make sense, I'll change the order to prioritize the environment variable if it is present.

Regarding the FLINK_PROPERTIES suggestion: that mechanism works well in standard Docker environments, but it fails in Kubernetes when using the Flink Operator. The Operator mounts the configuration as a ConfigMap, which is read-only (can't be something else). Since the standard Docker entrypoint attempts to append FLINK_PROPERTIES to flink-conf.yaml, it causes the pod to crash with a "Read-only file system" error. This PR solves that by allowing the API key to be read directly from the environment without needing to modify the config file at runtime.

Copy link
Author

Choose a reason for hiding this comment

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

I did apply you reco.

@github-actions github-actions bot added the community-reviewed PR has been reviewed by the community. label Jan 20, 2026
- Add DATADOG_API_KEY environment variable support in DatadogHttpReporterFactory
- Configuration property 'apikey' takes precedence over environment variable
- Environment variable provides fallback when no configuration is provided
- Add comprehensive test suite covering environment variable support and configuration scenarios

The API key resolution follows this order:
1. Configuration property 'apikey' (if provided and non-empty)
2. Environment variable 'DATADOG_API_KEY' (fallback)

This enhancement allows secure credential management using environment variables,
which is particularly useful in containerized and cloud deployments.

Signed-off-by: Thierno IB. BARRY <ibrahima.br@gmail.com>
…e support

- Add testApiKeyFromConfigurationProperty: Verify API key resolution from config
- Add testApiKeyFromEnvironmentVariable: Test environment variable fallback
- Add testConfigurationPropertyTakesPrecedenceOverEnvironmentVariable: Ensure config takes priority
- Add testEmptyConfigurationPropertyFallsBackToEnvironmentVariable: Test empty config fallback
- Use reflection to test private getApiKey() method directly
- Avoid API validation issues in tests using environment variable manipulation
…eflection issues

- Remove unnecessary Field lookup for getApiKey method
- Replace CommonTestUtils.setEnv() with Mockito mockStatic() to mock System.getenv()
- This resolves InaccessibleObjectException when running on Java 16+
- Fixes failing tests: testApiKeyFromEnvironmentVariable, testConfigurationPropertyTakesPrecedenceOverEnvironmentVariable, testEmptyConfigurationPropertyFallsBackToEnvironmentVariable
- Remove Mockito mock implementation that violates Flink coding guidelines
- Keep testable scenarios: configuration property tests
- Environment variable testing relies on System.getenv() behavior in production
- Simplify test suite to 3 core tests that can run without mocking
@barryib barryib force-pushed the feature/datadog-api-key-env-var branch from 817d76f to ca20a57 Compare January 22, 2026 10:24
@barryib barryib requested a review from davidradl January 22, 2026 10:25
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