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: add flag key to hash in fractional evaluation #847

Merged
merged 8 commits into from
Aug 23, 2023
Merged

feat: add flag key to hash in fractional evaluation #847

merged 8 commits into from
Aug 23, 2023

Conversation

craigpastro
Copy link
Member

@craigpastro craigpastro commented Aug 17, 2023

This PR

This PR adds the flag key as input to the hash in fractional evaluation. Since the evaluation function only has access to user-supplied logic and context, which almost certainly will not contain the flag key, in order to get this data to the evaluation function I add a flagdProperties struct to the context via a namespaced key $flagd. The flagdProperties struct contains the flag key, which is then used as input to the hash.

Related Issues

Part 2 of #843.

Notes

Follow-up Tasks

How to test

Signed-off-by: Craig Pastro <pastro.craig@gmail.com>
@netlify
Copy link

netlify bot commented Aug 17, 2023

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 8c59388
🔍 Latest deploy log https://app.netlify.com/sites/polite-licorice-3db33c/deploys/64e601bcf53da90008d653b2

@toddbaert
Copy link
Member

toddbaert commented Aug 21, 2023

@craigpastro

Could we add another test that just directly references $flagd.flag_key in a rule? Something that returns a value if flagd.flag_key === {some-known-value}. I know nobody would often write a rule like this in real life, but it will assure that we are actually populating the value as expected. See json logic do here.

@toddbaert
Copy link
Member

Related: #851

Craig Pastro added 2 commits August 21, 2023 12:55
Signed-off-by: Craig Pastro <pastro.craig@gmail.com>
@craigpastro
Copy link
Member Author

Could we add another test that just directly references $flagd.flag_key in a rule? Something that returns a value if flagd.flag_key === {some-known-value}. I know nobody would often write a rule like this in real life, but it will assure that we are actually populating the value as expected. See json logic do here.

I've added a test. Is it what you had in mind?

@craigpastro craigpastro marked this pull request as ready for review August 21, 2023 21:56
@craigpastro craigpastro requested a review from a team as a code owner August 21, 2023 21:56
Signed-off-by: Craig Pastro <pastro.craig@gmail.com>
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.

Once this and this are resolved, I think I can approve.

@toddbaert
Copy link
Member

Could we add another test that just directly references $flagd.flag_key in a rule? Something that returns a value if flagd.flag_key === {some-known-value}. I know nobody would often write a rule like this in real life, but it will assure that we are actually populating the value as expected. See json logic do here.

I've added a test. Is it what you had in mind?

yes!

Signed-off-by: Craig Pastro <pastro.craig@gmail.com>
@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #847 (8c59388) into main (88d832a) will decrease coverage by 0.14%.
The diff coverage is 71.87%.

@@            Coverage Diff             @@
##             main     #847      +/-   ##
==========================================
- Coverage   72.70%   72.56%   -0.14%     
==========================================
  Files          27       27              
  Lines        2729     2759      +30     
==========================================
+ Hits         1984     2002      +18     
- Misses        661      669       +8     
- Partials       84       88       +4     
Files Changed Coverage Δ
core/pkg/eval/json_evaluator.go 84.58% <67.85%> (-2.92%) ⬇️
core/pkg/eval/fractional_evaluation.go 67.46% <100.00%> (+0.80%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
@craigpastro
Copy link
Member Author

The length of evaluateVariant is failing the linter. I don't see any nice way to restructure the function. I can make it pass by removing whitespace but that doesn't seem like a good idea, and if more properties are added to flagdProperties it will just fail again in the future. Added a // nolint:funlen is an option.

@toddbaert toddbaert self-requested a review August 22, 2023 17:55
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.

LGTM. I think we can differ documenting this feature until we decide to add other properties (such as current_timestamp).

We can tackle the changes described here in a separate PR.

@toddbaert
Copy link
Member

toddbaert commented Aug 22, 2023

The length of evaluateVariant is failing the linter. I don't see any nice way to restructure the function. I can make it pass by removing whitespace but that doesn't seem like a good idea, and if more properties are added to flagdProperties it will just fail again in the future. Added a // nolint:funlen is an option.

I've added the nolint. A lot of length in this func is coming from debug messages and helpful comments. It doesn't read as overly complex to me.

There's also a very small negative delta in codecov, but I'm fine with merging as is.

@toddbaert toddbaert merged commit ca6a35f into open-feature:main Aug 23, 2023
12 of 14 checks passed
@github-actions github-actions bot mentioned this pull request Aug 22, 2023
@craigpastro craigpastro deleted the fractional-eval-improv-ii branch August 23, 2023 15:36
beeme1mr pushed a commit that referenced this pull request Aug 31, 2023
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.6.4</summary>

##
[0.6.4](flagd/v0.6.3...flagd/v0.6.4)
(2023-08-30)


### 🐛 Bug Fixes

* **deps:** update module github.com/cucumber/godog to v0.13.0
([#855](#855))
([5b42486](5b42486))
* **deps:** update module github.com/open-feature/flagd/core to v0.6.3
([#794](#794))
([9671964](9671964))


### 🧹 Chore

* **deps:** update golang docker tag to v1.21
([#822](#822))
([effe29d](effe29d))
</details>

<details><summary>flagd-proxy: 0.2.9</summary>

##
[0.2.9](flagd-proxy/v0.2.8...flagd-proxy/v0.2.9)
(2023-08-30)


### 🐛 Bug Fixes

* **deps:** update module github.com/open-feature/flagd/core to v0.6.3
([#794](#794))
([9671964](9671964))


### 🧹 Chore

* **deps:** update golang docker tag to v1.21
([#822](#822))
([effe29d](effe29d))
</details>

<details><summary>core: 0.6.4</summary>

##
[0.6.4](core/v0.6.3...core/v0.6.4)
(2023-08-30)


### 🐛 Bug Fixes

* **deps:** update kubernetes packages to v0.28.0
([#841](#841))
([cc195e1](cc195e1))
* **deps:** update kubernetes packages to v0.28.1
([#860](#860))
([f3237c2](f3237c2))
* **deps:** update module github.com/open-feature/open-feature-operator
to v0.2.36 ([#799](#799))
([fa4da4b](fa4da4b))
* **deps:** update module golang.org/x/crypto to v0.12.0
([#797](#797))
([edae3fd](edae3fd))
* **deps:** update module golang.org/x/net to v0.14.0
([#798](#798))
([92c2f26](92c2f26))
* **deps:** update module sigs.k8s.io/controller-runtime to v0.15.1
([#795](#795))
([13d62fd](13d62fd))
* **deps:** update module sigs.k8s.io/controller-runtime to v0.16.0
([#856](#856))
([88d832a](88d832a))


### ✨ New Features

* add flag key to hash in fractional evaluation
([#847](#847))
([ca6a35f](ca6a35f))
* add gRPC healthchecks
([#863](#863))
([da30b7b](da30b7b))
* support nested props in fractional evaluator
([#869](#869))
([50ff739](50ff739))


### 🧹 Chore

* deprecate fractionalEvaluation for fractional
([#873](#873))
([243fef9](243fef9))
* replace xxh3 with murmur3 in bucket algorithm
([#846](#846))
([c3c9e4e](c3c9e4e))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@github-actions github-actions bot mentioned this pull request Dec 2, 2023
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.

4 participants