-
Notifications
You must be signed in to change notification settings - Fork 352
feat(openfeature): add direct flagevaluation fallback #12204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leoromanovsky
wants to merge
8
commits into
agent/java-direct-exposure-egress
from
agent/java-direct-flagevaluation-egress
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44c4896
feat(openfeature): add direct flagevaluation fallback
leoromanovsky 5916539
test(openfeature): cover both direct EVP signals
leoromanovsky 792a754
Merge branch 'agent/java-direct-exposure-egress' into agent/java-dire…
leoromanovsky 2624739
Merge branch 'agent/java-direct-exposure-egress' into agent/java-dire…
leoromanovsky 855b295
fix(openfeature): clarify feature flag transport policy
leoromanovsky 06d4ee2
Merge branch 'agent/java-direct-exposure-egress' into agent/java-dire…
leoromanovsky 7ec5079
Merge branch 'agent/java-direct-exposure-egress' into agent/java-dire…
leoromanovsky 6616b0c
Merge branch 'agent/java-direct-exposure-egress' into agent/java-dire…
leoromanovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
communication/src/test/java/datadog/communication/IntakeApiTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package datadog.communication; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import datadog.communication.http.HttpRetryPolicy; | ||
| import java.io.IOException; | ||
| import okhttp3.MediaType; | ||
| import okhttp3.OkHttpClient; | ||
| import okhttp3.RequestBody; | ||
| import okhttp3.mockwebserver.MockResponse; | ||
| import okhttp3.mockwebserver.MockWebServer; | ||
| import okhttp3.mockwebserver.RecordedRequest; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class IntakeApiTest { | ||
|
|
||
| private static final MediaType JSON = MediaType.parse("application/json"); | ||
|
|
||
| private MockWebServer server; | ||
| private OkHttpClient client; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws IOException { | ||
| server = new MockWebServer(); | ||
| server.start(); | ||
| client = new OkHttpClient.Builder().build(); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() throws IOException { | ||
| client.dispatcher().executorService().shutdownNow(); | ||
| client.connectionPool().evictAll(); | ||
| server.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
| void requestsGzipResponseCompressionWhenEnabled() throws Exception { | ||
| assertEquals("gzip", postAndReadAcceptEncoding(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void requestsIdentityResponseEncodingWhenCompressionIsDisabled() throws Exception { | ||
| assertEquals("identity", postAndReadAcceptEncoding(false)); | ||
| } | ||
|
|
||
| private String postAndReadAcceptEncoding(final boolean responseCompression) throws Exception { | ||
| server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); | ||
| final IntakeApi api = | ||
| new IntakeApi( | ||
| server.url("/api/v2/"), | ||
| "api-key", | ||
| "123", | ||
| HttpRetryPolicy.Factory.NEVER_RETRY, | ||
| client, | ||
| responseCompression); | ||
|
|
||
| api.post("flagevaluation", RequestBody.create(JSON, "{}"), responseBody -> null, null, false); | ||
|
|
||
| final RecordedRequest request = server.takeRequest(); | ||
| assertEquals("/api/v2/flagevaluation", request.getPath()); | ||
| return request.getHeader("Accept-Encoding"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
...feature-flagging-lib/src/main/java/com/datadog/featureflag/ExposureBackendApiFactory.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...ture-flagging-lib/src/main/java/com/datadog/featureflag/FeatureFlagBackendApiFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| package com.datadog.featureflag; | ||
|
|
||
| import static datadog.trace.api.featureflag.config.FeatureFlaggingConfig.CONFIGURATION_SOURCE_AGENTLESS; | ||
|
|
||
| import datadog.communication.BackendApi; | ||
| import datadog.communication.BackendApiFactory; | ||
| import datadog.communication.ddagent.SharedCommunicationObjects; | ||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.intake.Intake; | ||
| import javax.annotation.Nullable; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** Selects the transport for Feature Flagging events. */ | ||
| final class FeatureFlagBackendApiFactory { | ||
|
|
||
| private static final Logger LOGGER = LoggerFactory.getLogger(FeatureFlagBackendApiFactory.class); | ||
|
|
||
| private final Config config; | ||
| private final BackendApiFactory backendApiFactory; | ||
| private final FeatureFlagEventType eventType; | ||
|
|
||
| FeatureFlagBackendApiFactory( | ||
| final Config config, | ||
| final SharedCommunicationObjects sharedCommunicationObjects, | ||
| final FeatureFlagEventType eventType) { | ||
| this(config, new BackendApiFactory(config, sharedCommunicationObjects), eventType); | ||
| } | ||
|
|
||
| FeatureFlagBackendApiFactory( | ||
| final Config config, | ||
| final BackendApiFactory backendApiFactory, | ||
| final FeatureFlagEventType eventType) { | ||
| this.config = config; | ||
| this.backendApiFactory = backendApiFactory; | ||
| this.eventType = eventType; | ||
| } | ||
|
|
||
| @Nullable | ||
| BackendApi create() { | ||
| final BackendApi proxyApi = | ||
| backendApiFactory.createEvpProxyApi( | ||
| Intake.EVENT_PLATFORM, eventType.responseCompressionEnabled()); | ||
| if (!CONFIGURATION_SOURCE_AGENTLESS.equals(config.getFeatureFlaggingConfigurationSource())) { | ||
| if (proxyApi == null) { | ||
| LOGGER.warn( | ||
| "Feature Flagging {} delivery is disabled because the local Agent does not support the EVP proxy", | ||
| eventType.logName()); | ||
| } | ||
| return proxyApi; | ||
| } | ||
|
|
||
| if (proxyApi != null) { | ||
| if (hasDirectCredentials()) { | ||
| return new AgentlessFeatureFlagBackendApi( | ||
| proxyApi, this::createDirectApi, eventType.logName()); | ||
| } | ||
| return proxyApi; | ||
| } | ||
|
|
||
| final BackendApi directApi = createDirectApi(); | ||
| if (directApi != null) { | ||
| return directApi; | ||
| } | ||
|
|
||
| LOGGER.warn( | ||
| "Feature Flagging {} delivery is disabled because no compatible local EVP proxy or direct intake credentials are available", | ||
| eventType.logName()); | ||
| return null; | ||
| } | ||
|
|
||
| private boolean hasDirectCredentials() { | ||
| final String apiKey = config.getApiKey(); | ||
| return apiKey != null && !apiKey.isEmpty(); | ||
| } | ||
|
|
||
| @Nullable | ||
| private BackendApi createDirectApi() { | ||
| if (!hasDirectCredentials()) { | ||
| return null; | ||
| } | ||
| try { | ||
| return backendApiFactory.createDirectIntakeApi( | ||
| Intake.EVENT_PLATFORM, eventType.responseCompressionEnabled()); | ||
| } catch (final IllegalArgumentException exception) { | ||
| LOGGER.debug( | ||
| "Cannot configure direct Feature Flagging {} delivery", eventType.logName(), exception); | ||
| return null; | ||
| } | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ging/feature-flagging-lib/src/main/java/com/datadog/featureflag/FeatureFlagEventType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.datadog.featureflag; | ||
|
|
||
| /** Defines event-specific transport behavior for Feature Flag delivery. */ | ||
| enum FeatureFlagEventType { | ||
| // Keep the established exposure transport behavior for compatibility. | ||
| EXPOSURE("exposure", true), | ||
|
|
||
| // Flag evaluation writers ignore successful response bodies, so gzip negotiation adds no value. | ||
| FLAG_EVALUATION("flag evaluation", false); | ||
|
|
||
| private final String logName; | ||
| private final boolean responseCompressionEnabled; | ||
|
|
||
| FeatureFlagEventType(final String logName, final boolean responseCompressionEnabled) { | ||
| this.logName = logName; | ||
| this.responseCompressionEnabled = responseCompressionEnabled; | ||
| } | ||
|
|
||
| String logName() { | ||
| return logName; | ||
| } | ||
|
|
||
| boolean responseCompressionEnabled() { | ||
| return responseCompressionEnabled; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side comment: Github UI didn't recognize ExposureBackendApiFactory->FeatureFlagBackendApiFactory as a ~rename, but did for AgentlessExposureBackendApi->AgentlessFeatureFlagBackendApi......booo