-
Notifications
You must be signed in to change notification settings - Fork 342
feat(openfeature): emit server-side EVP flagevaluation #11639
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
27
commits into
master
Choose a base branch
from
leo.romanovsky/ffl-2446-evp-flagevaluation-java
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
571938b
refactor(evp): centralize EVP proxy routing
leoromanovsky 4949ed7
refactor(feature-flagging): share EVP publishing
leoromanovsky 4aa0647
feat(openfeature): add flagevaluation contract
leoromanovsky ac126fb
refactor(openfeature): name metrics hook explicitly
leoromanovsky 7a43658
feat(openfeature): add flagevaluation logging hook
leoromanovsky 4ec77ca
test(openfeature): cover flagevaluation logging hook
leoromanovsky 6fa7ade
fix(openfeature): snapshot flagevaluation context
leoromanovsky 986a9af
feat(openfeature): register flagevaluation hook
leoromanovsky f1c37ab
feat(feature-flagging): canonicalize flagevaluation context
leoromanovsky 115a407
feat(feature-flagging): aggregate flagevaluation rows
leoromanovsky cc3b21c
test(feature-flagging): cover flagevaluation aggregation
leoromanovsky 31d7cb5
feat(feature-flagging): encode flagevaluation payloads
leoromanovsky e43f93a
test(feature-flagging): cover flagevaluation payload encoding
leoromanovsky 17d7785
feat(telemetry): support tagged core metric counts
leoromanovsky 5f88cad
feat(feature-flagging): run flagevaluation writer lifecycle
leoromanovsky 597e97d
feat(feature-flagging): post flagevaluation payloads
leoromanovsky 58df936
test(feature-flagging): add flagevaluation test support
leoromanovsky acc6e21
test(feature-flagging): cover flagevaluation writer
leoromanovsky 96df04f
feat(feature-flagging): wire flagevaluation writer lifecycle
leoromanovsky edb264e
test(feature-flagging): cover flagevaluation writer lifecycle
leoromanovsky 90ed6cb
perf(feature-flagging): benchmark flagevaluation hot path
leoromanovsky c73cafd
chore: apply spotless formatting
leoromanovsky 5b1456b
test(feature-flagging): cover flag evaluation jacoco paths
leoromanovsky 6e1f81e
fix(feature-flagging): gate flag evaluation enqueue during shutdown
leoromanovsky 78d8297
test(feature-flagging): cover flag eval event
leoromanovsky 6acbb5e
fix(feature-flagging): make aggregator count atomic
leoromanovsky 6b7aa42
Merge branch 'master' into leo.romanovsky/ffl-2446-evp-flagevaluation…
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
15 changes: 15 additions & 0 deletions
15
communication/src/main/java/datadog/communication/EvpProxy.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,15 @@ | ||
| package datadog.communication; | ||
|
|
||
| /** Shared EVP proxy constants. */ | ||
| public final class EvpProxy { | ||
|
|
||
| public static final String SUBDOMAIN_HEADER = "X-Datadog-EVP-Subdomain"; | ||
|
|
||
| /** | ||
| * Default SDK-side target for uncompressed EVP request bodies. Writers may split batches at or | ||
| * below this size to keep Agent proxy requests comfortably bounded. | ||
| */ | ||
| public static final int PAYLOAD_SIZE_LIMIT_BYTES = 5 * 1024 * 1024; | ||
|
|
||
| private EvpProxy() {} | ||
| } | ||
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
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
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
190 changes: 190 additions & 0 deletions
190
communication/src/test/java/datadog/communication/BackendApiFactoryTest.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,190 @@ | ||
| package datadog.communication; | ||
|
|
||
| import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V2_EVP_PROXY_ENDPOINT; | ||
| import static datadog.communication.ddagent.DDAgentFeaturesDiscovery.V4_EVP_PROXY_ENDPOINT; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import datadog.communication.ddagent.DDAgentFeaturesDiscovery; | ||
| import datadog.communication.ddagent.SharedCommunicationObjects; | ||
| import datadog.metrics.api.Monitoring; | ||
| import datadog.trace.api.Config; | ||
| import datadog.trace.api.ProtocolVersion; | ||
| import datadog.trace.api.intake.Intake; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
| import okhttp3.HttpUrl; | ||
| 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.Test; | ||
|
|
||
| class BackendApiFactoryTest { | ||
|
|
||
| private static final MediaType JSON = MediaType.parse("application/json"); | ||
|
|
||
| @Test | ||
| void preferredEvpProxyEndpointMustBeAdvertisedByAgent() { | ||
| final FakeFeaturesDiscovery discovery = | ||
| new FakeFeaturesDiscovery( | ||
| V4_EVP_PROXY_ENDPOINT, Collections.singleton(V4_EVP_PROXY_ENDPOINT)); | ||
| final BackendApiFactory factory = | ||
| new BackendApiFactory(Config.get(), sharedCommunicationObjects(discovery, null)); | ||
|
|
||
| assertNull(factory.createBackendApi(Intake.EVENT_PLATFORM, V2_EVP_PROXY_ENDPOINT, false)); | ||
| } | ||
|
|
||
| @Test | ||
| void preferredEvpProxyEndpointUsesRequestedRouteWhenAdvertised() throws Exception { | ||
| final MockWebServer agent = new MockWebServer(); | ||
| agent.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); | ||
| agent.start(); | ||
| try { | ||
| final FakeFeaturesDiscovery discovery = | ||
| new FakeFeaturesDiscovery( | ||
| V4_EVP_PROXY_ENDPOINT, | ||
| new HashSet<>(Arrays.asList(V4_EVP_PROXY_ENDPOINT, V2_EVP_PROXY_ENDPOINT))); | ||
| final BackendApiFactory factory = | ||
| new BackendApiFactory( | ||
| Config.get(), sharedCommunicationObjects(discovery, agent.url("/"))); | ||
| final BackendApi api = | ||
| factory.createBackendApi(Intake.EVENT_PLATFORM, V2_EVP_PROXY_ENDPOINT, false); | ||
|
|
||
| assertNotNull(api); | ||
| api.post( | ||
| "flagevaluation", | ||
| RequestBody.create(JSON, "{}".getBytes(StandardCharsets.UTF_8)), | ||
| stream -> null, | ||
| null, | ||
| false); | ||
|
|
||
| final RecordedRequest request = agent.takeRequest(); | ||
| assertEquals("/evp_proxy/v2/api/v2/flagevaluation", request.getPath()); | ||
| } finally { | ||
| agent.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void preferredEvpProxyEndpointDoesNotRequireLegacyDefaultRoute() throws Exception { | ||
| final String futureEndpoint = "evp_proxy/v9/"; | ||
| final MockWebServer agent = new MockWebServer(); | ||
| agent.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); | ||
| agent.start(); | ||
| try { | ||
| final FakeFeaturesDiscovery discovery = | ||
| new FakeFeaturesDiscovery(null, Collections.singleton(futureEndpoint)); | ||
| final BackendApiFactory factory = | ||
| new BackendApiFactory( | ||
| Config.get(), sharedCommunicationObjects(discovery, agent.url("/"))); | ||
| final BackendApi api = factory.createBackendApi(Intake.EVENT_PLATFORM, futureEndpoint, false); | ||
|
|
||
| assertNotNull(api); | ||
| api.post( | ||
| "flagevaluation", | ||
| RequestBody.create(JSON, "{}".getBytes(StandardCharsets.UTF_8)), | ||
| stream -> null, | ||
| null, | ||
| false); | ||
|
|
||
| final RecordedRequest request = agent.takeRequest(); | ||
| assertEquals("/evp_proxy/v9/api/v2/flagevaluation", request.getPath()); | ||
| } finally { | ||
| agent.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void defaultEvpProxyEndpointSupportsDisabledResponseCompression() throws Exception { | ||
| final MockWebServer agent = new MockWebServer(); | ||
| agent.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); | ||
| agent.start(); | ||
| try { | ||
| final FakeFeaturesDiscovery discovery = | ||
| new FakeFeaturesDiscovery( | ||
| V4_EVP_PROXY_ENDPOINT, | ||
| new HashSet<>(Arrays.asList(V4_EVP_PROXY_ENDPOINT, V2_EVP_PROXY_ENDPOINT))); | ||
| final BackendApiFactory factory = | ||
| new BackendApiFactory( | ||
| Config.get(), sharedCommunicationObjects(discovery, agent.url("/"))); | ||
| final BackendApi api = factory.createBackendApi(Intake.EVENT_PLATFORM, null, false); | ||
|
|
||
| assertNotNull(api); | ||
| api.post( | ||
| "flagevaluation", | ||
| RequestBody.create(JSON, "{}".getBytes(StandardCharsets.UTF_8)), | ||
| stream -> null, | ||
| null, | ||
| false); | ||
|
|
||
| final RecordedRequest request = agent.takeRequest(); | ||
| assertEquals("/evp_proxy/v4/api/v2/flagevaluation", request.getPath()); | ||
| } finally { | ||
| agent.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| private static SharedCommunicationObjects sharedCommunicationObjects( | ||
| final DDAgentFeaturesDiscovery discovery, final HttpUrl agentUrl) { | ||
| final TestSharedCommunicationObjects sco = new TestSharedCommunicationObjects(discovery); | ||
| sco.agentUrl = agentUrl != null ? agentUrl : HttpUrl.get("http://localhost:8126/"); | ||
| sco.agentHttpClient = new OkHttpClient(); | ||
| return sco; | ||
| } | ||
|
|
||
| private static final class TestSharedCommunicationObjects extends SharedCommunicationObjects { | ||
| private final DDAgentFeaturesDiscovery discovery; | ||
|
|
||
| private TestSharedCommunicationObjects(final DDAgentFeaturesDiscovery discovery) { | ||
| this.discovery = discovery; | ||
| } | ||
|
|
||
| @Override | ||
| public DDAgentFeaturesDiscovery featuresDiscovery(final Config config) { | ||
| return discovery; | ||
| } | ||
| } | ||
|
|
||
| private static final class FakeFeaturesDiscovery extends DDAgentFeaturesDiscovery { | ||
| private final String evpProxyEndpoint; | ||
| private final Set<String> evpProxyEndpoints; | ||
|
|
||
| private FakeFeaturesDiscovery( | ||
| final String evpProxyEndpoint, final Set<String> evpProxyEndpoints) { | ||
| super( | ||
| new OkHttpClient(), | ||
| Monitoring.DISABLED, | ||
| HttpUrl.get("http://localhost:8126/"), | ||
| ProtocolVersion.V0_5, | ||
| true, | ||
| false); | ||
| this.evpProxyEndpoint = evpProxyEndpoint; | ||
| this.evpProxyEndpoints = evpProxyEndpoints; | ||
| } | ||
|
|
||
| @Override | ||
| public void discoverIfOutdated() {} | ||
|
|
||
| @Override | ||
| public String getEvpProxyEndpoint() { | ||
| return evpProxyEndpoint; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsEvpProxyEndpoint(final String endpoint) { | ||
| return evpProxyEndpoints.contains(endpoint) || evpProxyEndpoints.contains("/" + endpoint); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsEvpProxy() { | ||
| return evpProxyEndpoint != null; | ||
| } | ||
| } | ||
| } |
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.
The declared limit in the agent is 10MB, but I'm leaving it at 5 here to not change tracer behavior too much.