-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add caching to GoFeatureFlag provider #386
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
base: main
Are you sure you want to change the base?
Conversation
c352d05
to
e82db60
Compare
Signed-off-by: Torben Hørup <torben@t-hoerup.dk>
e82db60
to
d1ca06b
Compare
@thomaspoignant could you take a look ? |
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.
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.
I don't see any major issues from this PR.
For consistency I would apply the suggestions in the Options
file.
Finally, the build is failing due to formatting issues. I would run dotnet format
at the root of this repository in your local branch!
src/OpenFeature.Contrib.Providers.GOFeatureFlag/GoFeatureFlagProvider.cs
Outdated
Show resolved
Hide resolved
src/OpenFeature.Contrib.Providers.GOFeatureFlag/GoFeatureFlagProviderOptions.cs
Show resolved
Hide resolved
src/OpenFeature.Contrib.Providers.GOFeatureFlag/GoFeatureFlagProviderOptions.cs
Outdated
Show resolved
Hide resolved
src/OpenFeature.Contrib.Providers.GOFeatureFlag/GoFeatureFlagProvider.cs
Outdated
Show resolved
Hide resolved
Ill look at your suggestions in the weekend. In the meantime, do you think the default values are reasonable/ too low / too high?? |
@@ -15,8 +15,12 @@ | |||
<PackageReference Include="System.Net.Http" Version="4.3.4" /> | |||
</ItemGroup> | |||
|
|||
<ItemGroup> | |||
<PackageReference Include="ZiggyCreatures.FusionCache" Version="2.2.0" /> |
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.
Another suggestion, please lower the required version of this dependency. The reason is, if a consumer is using 2.1, if they want to upgrade GoFF, they would need to upgrade to 2.2. My advise is to keep as lower as possible so no consumer is forced to upgrade. Other possible solution is to use PrivateAssets
but I'm not that familiar with the full consequences.
@hoerup they seem like reasonable values. Also, they are default so the consumer can tune the way they prefer. |
another thing: Currently I use the entire EvaluationContext as part of the cache key - is that how you'd expect it or should I only use the targetingKey bit ? |
@askpt could you take another look ? |
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.
Looks good to me, I am just concerned about the key size. Waiting on opinions from others.
@@ -311,6 +357,11 @@ private async Task<OfrepResponse> CallApi<T>(string flagKey, T defaultValue, | |||
return ofrepResp; | |||
} | |||
|
|||
private string GenerateCacheKey(string flagKey, EvaluationContext ctx) | |||
{ | |||
return ctx != null ? flagKey + ":" + new OfrepRequest(ctx).AsJsonString() : flagKey; |
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.
Bringing the cache key discussion here. I am concerned about the key size (character number) and it's impacts on performance. Do you think you can use some sort of hash that represents the object instead of the json
string itself? @thomaspoignant @kylejuliandev @toddbaert Any suggestions?
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.
That is exactly why i asked
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.
Maybe @thomaspoignant could help us with this decision ?
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.
I agree with @askpt, a Hash (like SHA or MD5) would produce a sufficiently unique key for this use case. A base64 encoded sting might be fine too. You may need to order the EvaluationContext so the encoded string is the same every time.
The problem I see with the JSON string, aside from performance, is whether it is actually deterministic. If the EvaluationContext is created slightly differently then a new key is produced. If we cannot reliably reproduce the same key each time then it kind of defeats the point of using a cache.
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.
I just checked the java provider for openfeature/goFF, and it looks like they use key + hash(evaluationContextAsJson), so I think i will do the same
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.
Done
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.
I cannot see any hashing in this method. You're just returning the string JSON.
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.
Weird - im certain that I pushed a change last night - ill look into it
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.
Finally got around to look at it - I don't know why it wasn't commited, but it is now
Signed-off-by: Torben Hørup <torben@t-hoerup.dk>
@askpt I think I have addressed all comments now |
@thomaspoignant just saw that you are working on a in-process evaluation thing - should we abort this cache PR in favor of the new feature ? |
Signed-off-by: Torben Hørup <torben@t-hoerup.dk>
@thomaspoignant when ever you got the time, i'd really appreciate your input on this |
This PR
Add caching to GoFeatureFlag provider
Related Issues
Fixes thomaspoignant/go-feature-flag#657
Notes
Follow-up Tasks
How to test