Repository navigation
Send the split serial id on feature flag exposure events #12432
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e5420bf
Send the split serial id on feature flag exposure events
danyal002 561b32b
Build the serial id config fixtures from a shared flag helper
danyal002 ca3df22
Keep the exposure event constructor compatible across versions
danyal002 330b50d
Remove the comments from the exposure serial id sources
danyal002 89e298c
Fall back to legacy exposures with older agents
leoromanovsky e0a25dc
Probe the agent bootstrap once instead of guarding one read
danyal002 732b8d5
Track split and exposure serial id support separately
danyal002 2922666
Cover the span enrichment serial id gate in a forked test
danyal002 fa28262
Merge latest master into danyal.khan/EX-3415
leoromanovsky 14424cf
Keep serial ID compatibility stack traces at debug level
leoromanovsky 8353325
Explain exposure type qualification in the evaluator
leoromanovsky 568fab4
Import the unambiguous exposure subject in evaluator tests
leoromanovsky a7de07d
Describe legacy bootstrap behavior in compatibility tests
leoromanovsky 99858c3
Move remote configuration test JSON into readable resources
leoromanovsky 7b3f74b
Merge branch 'master' into danyal.khan/EX-3415
leoromanovsky a0c0bbd
Merge remote-tracking branch 'origin/master' into danyal.khan/EX-3415
danyal002 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
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
98 changes: 98 additions & 0 deletions
98
...-api/src/test/java/datadog/trace/api/openfeature/DDEvaluatorSpanEnrichmentForkedTest.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,98 @@ | ||
| package datadog.trace.api.openfeature; | ||
|
|
||
| import static java.util.Collections.emptyList; | ||
| import static java.util.Collections.emptyMap; | ||
| import static java.util.Collections.singletonList; | ||
| 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 static org.mockito.Mockito.mock; | ||
|
|
||
| import datadog.trace.api.featureflag.ufc.v1.Allocation; | ||
| import datadog.trace.api.featureflag.ufc.v1.Flag; | ||
| import datadog.trace.api.featureflag.ufc.v1.ServerConfiguration; | ||
| import datadog.trace.api.featureflag.ufc.v1.Split; | ||
| import datadog.trace.api.featureflag.ufc.v1.ValueType; | ||
| import datadog.trace.api.featureflag.ufc.v1.Variant; | ||
| import dev.openfeature.sdk.EvaluationContext; | ||
| import dev.openfeature.sdk.MutableContext; | ||
| import dev.openfeature.sdk.ProviderEvaluation; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Drives the span-enrichment branch of {@link DDEvaluator}, which the ordinary test task cannot | ||
| * reach: the gate is read once into a static final field at class load. The property is set here | ||
| * rather than through {@code @WithConfig} because that extension rewrites {@code Config.INSTANCE}, | ||
| * which this module does not use, and the forked task gives this class its own JVM where nothing | ||
| * has loaded the evaluator yet. | ||
| */ | ||
| class DDEvaluatorSpanEnrichmentForkedTest { | ||
|
|
||
| static { | ||
| System.setProperty("dd.experimental.flagging.provider.span.enrichment.enabled", "true"); | ||
| } | ||
|
|
||
| @Test | ||
| void enrichmentMetadataCarriesTheSplitSerialId() { | ||
| final ProviderEvaluation<?> result = evaluate(340132); | ||
|
|
||
| assertNotNull( | ||
| result.getFlagMetadata().getBoolean(DDEvaluator.METADATA_DO_LOG), | ||
| "span enrichment must be on, or the assertions below pass vacuously"); | ||
| assertEquals( | ||
| Integer.valueOf(340132), | ||
| result.getFlagMetadata().getInteger(DDEvaluator.METADATA_SPLIT_SERIAL_ID)); | ||
| } | ||
|
|
||
| /** | ||
| * Simulates legacy exposure support while Split.serialId remains available. Falling back to the | ||
| * five-argument exposure constructor must not suppress the serial id in enrichment metadata. | ||
| */ | ||
| @Test | ||
| void enrichmentMetadataSurvivesAnAgentWithoutTheExposureConstructor() { | ||
| final boolean previous = DDEvaluator.USE_LEGACY_EXPOSURE_API.getAndSet(true); | ||
| try { | ||
| assertEquals( | ||
| Integer.valueOf(340132), | ||
| evaluate(340132).getFlagMetadata().getInteger(DDEvaluator.METADATA_SPLIT_SERIAL_ID)); | ||
| } finally { | ||
| DDEvaluator.USE_LEGACY_EXPOSURE_API.set(previous); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void enrichmentMetadataOmitsTheSerialIdWhenTheAgentSplitHasNoField() { | ||
| final boolean previous = DDEvaluator.SPLIT_SERIAL_ID_SUPPORTED.getAndSet(false); | ||
| try { | ||
| assertNull( | ||
| evaluate(340132).getFlagMetadata().getInteger(DDEvaluator.METADATA_SPLIT_SERIAL_ID)); | ||
| } finally { | ||
| DDEvaluator.SPLIT_SERIAL_ID_SUPPORTED.set(previous); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void enrichmentMetadataOmitsTheSerialIdWhenTheSplitHasNone() { | ||
| assertNull(evaluate(null).getFlagMetadata().getInteger(DDEvaluator.METADATA_SPLIT_SERIAL_ID)); | ||
| } | ||
|
|
||
| private static ProviderEvaluation<?> evaluate(final Integer serialId) { | ||
| final Map<String, Variant> variations = new HashMap<>(); | ||
| variations.put("on", new Variant("on", 1)); | ||
| final Split split = new Split(emptyList(), "on", emptyMap(), serialId); | ||
| final Allocation allocation = | ||
| new Allocation("alloc-1", null, null, null, singletonList(split), Boolean.FALSE); | ||
| final Map<String, Flag> flags = new HashMap<>(); | ||
| flags.put( | ||
| "target", | ||
| new Flag("target", true, ValueType.INTEGER, variations, singletonList(allocation))); | ||
|
|
||
| final DDEvaluator evaluator = new DDEvaluator(mock(Runnable.class)); | ||
| evaluator.accept(new ServerConfiguration("", "", true, null, flags)); | ||
|
|
||
| final EvaluationContext ctx = new MutableContext("target").setTargetingKey("user-1"); | ||
| return evaluator.evaluate(Integer.class, "target", 23, ctx); | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.