minder
minder copied to clipboard
Feature flags not working when evaluated outside the context of a request
Describe the issue
Feature flags evaluated outside the context of a request don't populate EvaluationContext correctly.
An example of where this bug happens is here, which is the code path executed during the evaluation of a profile rule. That code path goes on running this line which eventually runs jwt.GetUserSubjectFromContext(ctx) which leads to empty string being returned as targetingKey (here).
This is an example stack trace that leads to error openfeature: TARGETING_KEY_MISSING: no targetingKey provided in the evaluation context
0 0x0000000105e54b80 in github.com/stacklok/minder/internal/auth.GetUserSubjectFromContext
at ./internal/auth/jwtauth.go:119
1 0x000000010602c098 in github.com/stacklok/minder/internal/flags.fromContext
at ./internal/flags/flags.go:42
2 0x000000010602c2c4 in github.com/stacklok/minder/internal/flags.Bool
at ./internal/flags/flags.go:52
3 0x00000001065fb414 in github.com/stacklok/minder/internal/engine.(*Executor).createOrUpdateEvalStatus
at ./internal/engine/eval_status.go:204
4 0x00000001065fd8d0 in github.com/stacklok/minder/internal/engine.(*Executor).evalEntityEvent.func1.1
at ./internal/engine/executor.go:226
5 0x000000010608ddc4 in github.com/stacklok/minder/internal/profiles.TraverseRules
at ./internal/profiles/util.go:165
6 0x00000001065fd32c in github.com/stacklok/minder/internal/engine.(*Executor).evalEntityEvent.func1
at ./internal/engine/executor.go:203
7 0x00000001065fdeec in github.com/stacklok/minder/internal/engine.(*Executor).forProjectsInHierarchy
at ./internal/engine/executor.go:266
8 0x00000001065fce24 in github.com/stacklok/minder/internal/engine.(*Executor).evalEntityEvent
at ./internal/engine/executor.go:194
9 0x00000001065fc670 in github.com/stacklok/minder/internal/engine.(*Executor).HandleEntityEvent.func1
at ./internal/engine/executor.go:142
To Reproduce
- add this to
flags-config.yaml
eval_history:
variations:
enabled: true
disabled: false
defaultRule:
variation: enabled
- trigger some rule evaluation
- connect to postgresql (e.g.
psql minder) - run
select * from evaluation_statuses
What version are you using?
minder-0.20240703.2465_ref.924bd1a