-
Notifications
You must be signed in to change notification settings - Fork 87
feat: multi-project support via selectors and flagSetId namespacing #1702
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
Changes from 11 commits
6e98bfe
fdb3fca
b9603ab
d981fb7
9dbce2c
9113339
d0a3424
e6e948e
a04799e
673e326
36fc0a5
65db740
5cbb162
9e68124
96d6f76
f4c28f3
7363dc3
d3cbd27
56b743e
c589463
0c169de
e743c56
c63391a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://flagd.dev/schema/v0/flags.json", | ||
"metadata": { | ||
"flagSetId": "other", | ||
"version": "v1" | ||
}, | ||
"flags": { | ||
"myStringFlag": { | ||
"state": "ENABLED", | ||
"variants": { | ||
"dupe1": "dupe1", | ||
"dupe2": "dupe2" | ||
}, | ||
"defaultVariant": "dupe1" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ func (je *JSON) SetState(payload sync.DataSync) (map[string]interface{}, bool, e | |
var events map[string]interface{} | ||
var reSync bool | ||
|
||
events, reSync = je.store.Update(payload.Source, payload.Selector, definition.Flags, definition.Metadata) | ||
events, reSync = je.store.Update(payload.Source, definition.Flags, definition.Metadata) | ||
|
||
// Number of events correlates to the number of flags changed through this sync, record it | ||
span.SetAttributes(attribute.Int("feature_flag.change_count", len(events))) | ||
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. unrelated to this PR, but this looks like it could also be a metric 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. Ya this is a good point. We should probably review all the metrics as part of pre-v1. |
||
|
@@ -149,8 +149,12 @@ func (je *Resolver) ResolveAllValues(ctx context.Context, reqID string, context | |
_, span := je.tracer.Start(ctx, "resolveAll") | ||
defer span.End() | ||
|
||
var err error | ||
allFlags, flagSetMetadata, err := je.store.GetAll(ctx) | ||
selector := store.NewSelector("") | ||
s := ctx.Value(store.SelectorContextKey{}) | ||
if s != nil { | ||
selector = s.(store.Selector) | ||
} | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
allFlags, flagSetMetadata, err := je.store.GetAll(ctx, selector) | ||
if err != nil { | ||
return nil, flagSetMetadata, fmt.Errorf("error retreiving flags from the store: %w", err) | ||
} | ||
|
@@ -301,19 +305,19 @@ func resolve[T constraints](ctx context.Context, reqID string, key string, conte | |
func (je *Resolver) evaluateVariant(ctx context.Context, reqID string, flagKey string, evalCtx map[string]any) ( | ||
variant string, variants map[string]interface{}, reason string, metadata map[string]interface{}, err error, | ||
) { | ||
flag, metadata, ok := je.store.Get(ctx, flagKey) | ||
|
||
selector := store.NewSelector("") | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
s := ctx.Value(store.SelectorContextKey{}) | ||
if s != nil { | ||
selector = s.(store.Selector) | ||
} | ||
flag, metadata, ok := je.store.Get(ctx, flagKey, selector) | ||
if !ok { | ||
// flag not found | ||
je.Logger.DebugWithID(reqID, fmt.Sprintf("requested flag could not be found: %s", flagKey)) | ||
return "", map[string]interface{}{}, model.ErrorReason, metadata, errors.New(model.FlagNotFoundErrorCode) | ||
} | ||
|
||
// add selector to evaluation metadata | ||
selector := je.store.SelectorForFlag(ctx, flag) | ||
if selector != "" { | ||
metadata[SelectorMetadataKey] = selector | ||
} | ||
|
||
for key, value := range flag.Metadata { | ||
// If value is not nil or empty, copy to metadata | ||
if value != nil { | ||
|
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 was a duped recipe.