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

feat: adds evaluation context merging #56

Closed
wants to merge 1 commit into from

Conversation

mschoenlaub
Copy link
Contributor

This PR

  • Adds merging of the evaluation context

Related Issues

Fixes #55

Follow-up Tasks

More tests and better application mocking in the unit tests will be done at a later point.

Signed-off-by: Manuel Schönlaub <[email protected]>
@toddbaert
Copy link
Member

Some CI is failing, but looking at this from a spec perspective it seems correct!

@toddbaert toddbaert self-requested a review September 12, 2023 19:03
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.

Approving from a spec perspective, but it would be great to get a review from another Rubiest!

Copy link
Collaborator

@technicalpickles technicalpickles left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to work towards #55 ❤️ It looks like this needs a bit more work though to be ready to merge 😱

The tests aren't passing due to OpenFeature::SDK.context being nil, so it's hard to validate the rest of the changes.

I'm also not quite sure about using a SimpleDelegator for the Context class. I'm having a hard-time understanding what the actual class is doing.

@@ -25,7 +25,8 @@ def initialize(provider:, client_options: nil, context: nil)
# def fetch_boolean_details(flag_key:, default_value:, evaluation_context: nil)
# result = @provider.fetch_boolean_value(flag_key: flag_key, default_value: default_value, evaluation_context: evaluation_context)
# end
def fetch_#{result_type}_#{suffix}(flag_key:, default_value:, evaluation_context: nil)
def fetch_#{result_type}_#{suffix}(flag_key:, default_value:, evaluation_context: {})
evaluation_context = OpenFeature::SDK.context.merge(@context).merge(evaluation_context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are a bunch of CI failures originating back to this line, ie:

      NoMethodError:
        undefined method `merge' for nil:NilClass
      # ./lib/openfeature/sdk/client.rb:29:in `fetch_number_details'
      # ./spec/openfeature/sdk/client_spec.rb:150:in `block (6 levels) in <top (required)>'

It doesn't look like OpenFeature::SDK.context ever gets set.

hashes = values.select { |value| value.is_a?(Hash) }
while hashes.empty? == false
hash = hashes.pop
hash.freeze unless hash.frozen?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note: freeze is perfectly happy to run on a frozen object. Under the hood freeze handles that check for you.

Suggested change
hash.freeze unless hash.frozen?
hash.freeze

Copy link
Contributor Author

@mschoenlaub mschoenlaub Sep 15, 2023

Choose a reason for hiding this comment

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

Oh yeah, I think what I had in my mind was more a cheap check to avoid running in circles when one of the values contains the hash itself.
While I think there might be no obvious reason to do that, there's nothing in the spec or the language that prohibits that.
.duping stuff could avoid that... but not sure if that's not more expensive in the end.

# A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
class Context < SimpleDelegator

def initialize(context = Concurrent::Hash.new({}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is part of the concurrent-ruby and it's not a dependency. @josecolella included this dependency initially, but we ended up removing it for simplificy.

Copy link
Contributor Author

@mschoenlaub mschoenlaub Sep 15, 2023

Choose a reason for hiding this comment

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

Yeah, I realize that development has suddendly picked up a lot of pace here :D
Given that there seem to be a lot of moving parts right now in this repo, I'll probably revisit this at a later point :)

Hmm.. not sure where exactly concurrent-ruby got removed, but not in this repo. That being said, I'm not unhappy with it being removed at all.

I'm just slightly frustrated with last year's development pace vs. last weeks pace :D

module SDK
module Evaluation
# A container for arbitrary contextual data that can be used as a basis for dynamic evaluation
class Context < SimpleDelegator
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not seeing anywhere else in the PR that is using this yet 🤔

Comment on lines +21 to +29
def targeting_key
self[:targeting_key]
end

def targeting_key=(value)
raise ArgumentError, "targeting_key must be a String" unless value.is_a?(String)

self[:targeting_key] = value
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is targetting key refer to exactly?

Copy link
Member

Choose a reason for hiding this comment

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

The targeting key is basically a well-defined property in the context, which is necessary because many providers need a user-identifier or equivalent of some kind: https://openfeature.dev/specification/sections/evaluation-context#requirement-311

@mschoenlaub mschoenlaub closed this Feb 8, 2024
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.

Implement context hash
3 participants