Implement class Evaluation Context#56
Conversation
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Summary of ChangesHello @NeaguGeorgiana23, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements the EvaluationContext class and its builder, which is a great addition. The implementation is solid, but I have a few suggestions to improve performance, API safety, and design clarity. Specifically, I've recommended using heterogeneous lookup for the attributes map to avoid unnecessary string allocations. I've also suggested a change to how a missing targeting_key is represented, using std::nullopt instead of an empty string to better align with the concept of an "undefined" value. Finally, I've pointed out a potential API safety issue with storing const char* in attributes and suggested standardizing on std::string.
| } | ||
|
|
||
| EvaluationContext EvaluationContext::Builder::build() const { | ||
| return EvaluationContext(targeting_key_.value_or(""), attributes_); |
There was a problem hiding this comment.
Using an empty string to represent a missing targeting key can be ambiguous. The OpenFeature specification says the key should be "undefined" if not set. Using std::optional throughout (from builder to the context object) by passing targeting_key_ directly to the constructor would better represent this "undefined" state as std::nullopt. This makes the implementation cleaner and less ambiguous. The corresponding test DefaultBuilderCreatesEmptyContext will need to be updated to expect std::nullopt.
| return EvaluationContext(targeting_key_.value_or(""), attributes_); | |
| return EvaluationContext(targeting_key_, attributes_); |
oxddr
left a comment
There was a problem hiding this comment.
Please have a look at suggestions from Gemini and apply whenever they make sense.
Signed-off-by: NeaguGeorgiana23 <115723925+NeaguGeorgiana23@users.noreply.github.com>
…ult constructor. Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
Signed-off-by: NeaguGeorgiana23 <neagugeorgiana@google.com>
This PR
Implements the EvaluationContext class and its associated Builder. The EvaluationContext is immutable and represents a container for contextual information used during flag evaluation, such as a targeting key and custom attributes.
Includes a static merge method that combines multiple contexts. Here, the attributes are merged with higher precedence overwrites and the targeting key is resolved by selecting the first valid key found in order of precedence (highest to lowest).
Builder Pattern was used to make the EvaluationContext immutable
Related Issues
Fixes #55