Skip to content
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

fix: improve targetingKey handling in the context #805

Merged

Conversation

Kavindu-Dodan
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan commented Feb 14, 2024

This PR

Fixes #801.

What's changed?

I have changed how we store the targetingKey internally (in both mutable and immutable contexts). Instead of storing in a field, we now store targetingKey as a property of the delegated Structure implemementation.

Why

Both mutable and immutable contexts use a Structure implementation instance and delegate operations onto this instance. For example, asObjectMap and asMap() are exposed through this delegation. With this change, we keep the same delegation and expose targetingKey from the above-mentioned attribute exporters.

Impact

There are no behaviour change other than for avoiding storing of empty string ("") for targetingKey.

@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner February 14, 2024 18:27
@@ -184,7 +183,7 @@ public class EvalContextTest {

ctx2.setTargetingKey(" ");
ctxMerged = ctx1.merge(ctx2);
assertEquals(key1, ctxMerged.getTargetingKey());
Copy link
Contributor Author

@Kavindu-Dodan Kavindu-Dodan Feb 14, 2024

Choose a reason for hiding this comment

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

This is the only major change - we do not accept empty value or spaces for targeting key. Eaerlier this was handled in the merge stage where we filtered for null or empty values.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (ef56006) 94.89% compared to head (b9f4469) 95.39%.

❗ Current head b9f4469 differs from pull request most recent head 1c18a9e. Consider uploading reports for the commit 1c18a9e to get more accurate results

Files Patch % Lines
.../main/java/dev/openfeature/sdk/MutableContext.java 85.71% 0 Missing and 2 partials ⚠️
...ain/java/dev/openfeature/sdk/ImmutableContext.java 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #805      +/-   ##
============================================
+ Coverage     94.89%   95.39%   +0.49%     
- Complexity      365      368       +3     
============================================
  Files            34       34              
  Lines           862      847      -15     
  Branches         53       50       -3     
============================================
- Hits            818      808      -10     
+ Misses           23       21       -2     
+ Partials         21       18       -3     
Flag Coverage Δ
unittests 95.39% <86.95%> (+0.49%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@toddbaert
Copy link
Member

toddbaert commented Feb 14, 2024

@Kavindu-Dodan This seems like a good idea to me. We recently had a bug in flagd-java due to this. I think the risk is low but I'm interested in what others think.

Do you think we should do the same thing in dotnet? cc @kinyoklion @austindrenski

@kinyoklion
Copy link
Member

@Kavindu-Dodan This seems like a good idea to me. We recently had a bug in flagd-java due to this. I think the risk is low but I'm interested in what others think.

Do you think we should do the same thing in dotnet? cc @kinyoklion @austindrenski

I like this idea. Prior to it being formalized into the API of the context itself I had been targeting the "targetingKey" based on a string constant.

A snippet from the documentation for the LaunchDarkly dotnet provider.

var evaluationContext = EvaluationContext.Builder()
  .Set("kind", "organization")
  .Set("targetingKey", "my-org-key") // Could also use "key" instead of "targetingKey".
  .Build();

By storing it in an attribute it would theoretically maintain compatibility with those assumptions.

Copy link
Member

@lukas-reining lukas-reining left a comment

Choose a reason for hiding this comment

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

Makes sense and the change looks good to me!

Copy link
Member

@toddbaert toddbaert left a comment

Choose a reason for hiding this comment

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

@Kavindu-Dodan would you mind creating a similar .NET issue if you agree?

@Kavindu-Dodan
Copy link
Contributor Author

@Kavindu-Dodan would you mind creating a similar .NET issue if you agree?

Created a .Net issue - open-feature/dotnet-sdk#235

I will merge this as we have an agreement on the change :)

Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com>
Copy link

sonarcloud bot commented Feb 14, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@Kavindu-Dodan Kavindu-Dodan merged commit f7a9d57 into open-feature:main Feb 14, 2024
6 checks passed
@Kavindu-Dodan Kavindu-Dodan deleted the fix/export-targeting-key branch February 14, 2024 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Consider exposing TargetingKey with all value exporters
4 participants