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: v2 evaluate boolean #1806

Merged
merged 13 commits into from
Jul 3, 2023
Merged

feat: v2 evaluate boolean #1806

merged 13 commits into from
Jul 3, 2023

Conversation

yquansah
Copy link
Contributor

@yquansah yquansah commented Jun 29, 2023

Boolean evaluation logic for the v2 evaluate endpoints. This PR also addresses some comments from the upstream branch, as far as styling and renaming.

Completes FLI-459

@yquansah yquansah requested a review from a team as a code owner June 29, 2023 17:01
@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #1806 (38604ac) into eval-v2 (5abd331) will decrease coverage by 1.03%.
The diff coverage is 78.88%.

@@             Coverage Diff             @@
##           eval-v2    #1806      +/-   ##
===========================================
- Coverage    70.32%   69.30%   -1.03%     
===========================================
  Files           58       63       +5     
  Lines         5570     5766     +196     
===========================================
+ Hits          3917     3996      +79     
- Misses        1426     1543     +117     
  Partials       227      227              
Impacted Files Coverage Δ
internal/cmd/grpc.go 0.00% <0.00%> (ø)
internal/server/rollout.go 0.00% <0.00%> (ø)
internal/storage/fs/sync.go 77.38% <0.00%> (-15.48%) ⬇️
internal/storage/sql/migrator.go 20.00% <ø> (ø)
internal/cmd/http.go 3.04% <11.11%> (-0.66%) ⬇️
internal/server/evaluator.go 45.00% <31.57%> (-49.90%) ⬇️
internal/storage/fs/snapshot.go 63.86% <42.85%> (-1.65%) ⬇️
internal/server/evaluation/server.go 75.00% <75.00%> (ø)
...nternal/server/evaluation/evaluation_store_mock.go 85.71% <85.71%> (ø)
internal/server/evaluation/evaluation.go 90.76% <90.76%> (ø)
... and 7 more

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

Copy link
Collaborator

@markphelps markphelps left a comment

Choose a reason for hiding this comment

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

do we check if the flag exists before doing either the boolean or segment evaluation?

internal/server/evaluation/evaluator.go Outdated Show resolved Hide resolved
internal/server/evaluation/evaluator.go Outdated Show resolved Hide resolved
internal/server/evaluation/evaluation.go Outdated Show resolved Hide resolved
internal/server/evaluation/evaluation.go Outdated Show resolved Hide resolved
internal/server/evaluation/evaluator.go Outdated Show resolved Hide resolved
internal/server/evaluation/evaluator.go Outdated Show resolved Hide resolved
JOIN constraints c ON (rs.segment_key = c.segment_key)
) rss ON (r.id = rss.rollout_id)
WHERE r.flag_key = $1 AND r.namespace_key = $2
ORDER BY r."rank" ASC
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 a monster query, im wondering if it would be simpler and potentially faster because all of the joins to do:

  1. get all rollouts for flag from rollouts table by flagKey, sorted by rank, this will give you a slice of []rollouts that are naturally ordered
  2. create a map[rolloutID] => rollout as an index for each type (percentage & variant)
  3. query for all percentage_rollouts by ID, using an IN() query with their IDs from step 2
  4. query for all segment_rollouts by ID, using an IN() query with their IDs from step 2
  5. now sort the final results looping through the id's in order from step 1, and built up the final result set using the actual percentage_rollout or segment_rollout.

I guess what I'm saying is I wonder which approach will be faster, implementing it all in SQL or in Go?
Perhaps we should create some benchmarks and try both approaches? We could create another issue for this to do before it goes 'live'. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@markphelps Benchmarks sound good. I meant to call this query out initially, I should have followed up with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

To further this. I think we should break this PR in two like we originally planned.
Focus on delivering the server definition first. Just leave the storage requirement as an interface with no implementation.

Then implement the storage as a follow up PR as there is a lot to digest here.
FLI-459 is the server issue
FLI-454 is the storage implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GeorgeMac Agreed. I'll move that to another PR.

internal/storage/sql/common/evaluation.go Outdated Show resolved Hide resolved
Base automatically changed from v2-evaluate-variant to eval-v2 June 30, 2023 18:02
@yquansah yquansah marked this pull request as draft June 30, 2023 18:22
@yquansah yquansah requested a review from GeorgeMac July 1, 2023 15:38
@yquansah yquansah marked this pull request as ready for review July 1, 2023 15:38
Copy link
Contributor

@GeorgeMac GeorgeMac left a comment

Choose a reason for hiding this comment

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

I think this PR looks great. Couple comments, one style, one error adjustment, but I think merge it after those 👍


for _, rollout := range rollouts {
if rollout.Rank < lastRank {
return &rpcEvaluation.BooleanEvaluationResponse{}, errs.ErrInvalidf("rollout rank: %d detected out of order", rollout.Rank)
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 should be able to start returning nil again if we stop setting reason when error is non-nil.
Also, I think this should be and internal error as we control the rank field.

Suggested change
return &rpcEvaluation.BooleanEvaluationResponse{}, errs.ErrInvalidf("rollout rank: %d detected out of order", rollout.Rank)
return nil, fmt.Errorf("rollout rank: %d detected out of order", rollout.Rank)

@@ -12,26 +12,20 @@ import (
"go.flipt.io/flipt/internal/server/metrics"
"go.flipt.io/flipt/internal/storage"
"go.flipt.io/flipt/rpc/flipt"
rpcEvaluation "go.flipt.io/flipt/rpc/flipt/evaluation"
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 tend to just lowercase package names:

Suggested change
rpcEvaluation "go.flipt.io/flipt/rpc/flipt/evaluation"
rpcevaluation "go.flipt.io/flipt/rpc/flipt/evaluation"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely. Let me get that fixed up.

@markphelps
Copy link
Collaborator

looks great! noticed a few areas of missing coverage in the evaluation server code (at least according to CodeCov 😐 ) if the report is accurate, would it be possible to get these covered?:

@yquansah yquansah merged commit ff47a99 into eval-v2 Jul 3, 2023
@yquansah yquansah deleted the v2-evaluate-boolean branch July 3, 2023 15:02
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.

3 participants