-
Notifications
You must be signed in to change notification settings - Fork 27
[FSSDK-8971] feat: add FetchQualifiedSegments to Decide #364
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
Merged
andrewleap-optimizely
merged 11 commits into
master
from
aleap/add_fetch_qualified_segments
Mar 3, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b9244c0
fix tests for odp
andrewleap-optimizely 42fd8c5
add FetchQualifiedSegments to decide
andrewleap-optimizely 25c7f72
modify TestClient and TestConfig for odp
andrewleap-optimizely 73ffb29
add unit tests for FetchQualifiedSegments
andrewleap-optimizely 2aa013e
extend tests for fetch options
andrewleap-optimizely 6276446
fix typo
andrewleap-optimizely efaebda
lint fixes
andrewleap-optimizely 91f87d2
test invalid fetch segment options
andrewleap-optimizely 621402f
go mod tidy
andrewleap-optimizely 64e6f3b
add fetch segments to openapi spec
andrewleap-optimizely 6575fcf
cleanup
andrewleap-optimizely File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/**************************************************************************** | ||
* Copyright 2021, Optimizely, Inc. and contributors * | ||
* Copyright 2021,2023, Optimizely, Inc. and contributors * | ||
* * | ||
* Licensed under the Apache License, Version 2.0 (the "License"); * | ||
* you may not use this file except in compliance with the License. * | ||
|
@@ -18,23 +18,27 @@ | |
package handlers | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/optimizely/agent/pkg/middleware" | ||
|
||
"github.com/optimizely/go-sdk/pkg/client" | ||
"github.com/optimizely/go-sdk/pkg/decide" | ||
"github.com/optimizely/go-sdk/pkg/decision" | ||
"github.com/optimizely/go-sdk/pkg/odp/segment" | ||
|
||
"github.com/go-chi/render" | ||
) | ||
|
||
// DecideBody defines the request body for decide API | ||
type DecideBody struct { | ||
UserID string `json:"userId"` | ||
UserAttributes map[string]interface{} `json:"userAttributes"` | ||
DecideOptions []string `json:"decideOptions"` | ||
ForcedDecisions []ForcedDecision `json:"forcedDecisions,omitempty"` | ||
UserID string `json:"userId"` | ||
UserAttributes map[string]interface{} `json:"userAttributes"` | ||
DecideOptions []string `json:"decideOptions"` | ||
ForcedDecisions []ForcedDecision `json:"forcedDecisions,omitempty"` | ||
FetchSegments bool `json:"fetchSegments"` | ||
FetchSegmentsOptions []segment.OptimizelySegmentOption `json:"fetchSegmentsOptions,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we confirm that if user sends a wrong value here then this will not break? maybe have 3 unit tests:
|
||
} | ||
|
||
// ForcedDecision defines Forced Decision | ||
|
@@ -73,6 +77,15 @@ func Decide(w http.ResponseWriter, r *http.Request) { | |
|
||
optimizelyUserContext := optlyClient.CreateUserContext(db.UserID, db.UserAttributes) | ||
|
||
if db.FetchSegments { | ||
success := optimizelyUserContext.FetchQualifiedSegments(db.FetchSegmentsOptions) | ||
if !success { | ||
err := errors.New("failed to fetch qualified segments") | ||
RenderError(err, http.StatusInternalServerError, w, r) | ||
return | ||
} | ||
} | ||
|
||
// Setting up forced decisions | ||
for _, fd := range db.ForcedDecisions { | ||
context := decision.OptimizelyDecisionContext{FlagKey: fd.FlagKey, RuleKey: fd.RuleKey} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be done using
go mod tidy
andgo mod clean
to automatically updatego.sum
and remove irrelevant indirect dependencies which were needed by go-sdk1.8.3
.