Repository navigation
fix: handle invalid selector errors - #1976
Conversation
✅ Deploy Preview for polite-licorice-3db33c canceled.
|
8e8b5fd to
d79d9be
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors the Selector creation and manipulation. NewSelector now validates selector keys and returns an error for invalid keys, with corresponding error handling added across evaluation and sync services. Additionally, generic WithIndex calls are replaced with type-safe methods like WithSource and WithFlagSetId. The review feedback recommends two improvements: recording the error on the tracing span when startResolveV2 fails in flag_evaluator_v2.go, and setting exitReason = "error" when returning an invalid selector error in flag-sync/handler.go to ensure accurate metrics.
75e6aff to
9a39218
Compare
|
@alxckn unit test for
Otherwise this can regress silently. WDYT? Also FYI, some of the sonar issues should be fixed on |
9a39218 to
b353b2e
Compare
|
|
@toddbaert thanks for the review. I took care of comments, added integration tests to prevent regressions, and the sonar warnings seem resolved 👍 |
|
@toddbaert ping :) do you think this could get merged? This would be helpful to us to remove the risk of false positive alarms |
Signed-off-by: Alexandre Chakroun <[email protected]>
Signed-off-by: Alexandre Chakroun <[email protected]>
Signed-off-by: Alexandre Chakroun <[email protected]>
Signed-off-by: Alexandre Chakroun <[email protected]>
Signed-off-by: Alexandre Chakroun <[email protected]>
Signed-off-by: Alexandre Chakroun <[email protected]>
9dac26e to
a5d8ddf
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughChangesSelectors now validate only Selector validation and propagation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant EvaluationService
participant selectorFromHeader
participant store.NewSelector
participant Evaluator
Client->>EvaluationService: Send request with Flagd-Selector
EvaluationService->>selectorFromHeader: Extract selector header
selectorFromHeader->>store.NewSelector: Validate expression
store.NewSelector-->>selectorFromHeader: Selector or error
selectorFromHeader-->>EvaluationService: Valid selector or InvalidArgument
EvaluationService->>Evaluator: Continue evaluation with selector
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@flagd/pkg/service/flag-evaluation/flag_evaluator.go`:
- Around line 77-80: Selector parsing failures return without updating the
active OpenTelemetry span. In
flagd/pkg/service/flag-evaluation/flag_evaluator.go at lines 77-80, 191-194,
225-228, 260-263, 295-298, and 330-333, and flag_evaluation_v1.go at lines
77-80, 217-220, 252-255, 287-290, 322-325, and 357-360, update each Resolve*
selectorFromHeader error path to record the error and set the span status to
codes.Error with the error message before returning.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 595d404c-3b47-4981-8a2d-6a5422940b3b
📒 Files selected for processing (15)
core/pkg/store/query.gocore/pkg/store/query_test.gocore/pkg/store/store.gocore/pkg/store/store_test.goflagd/pkg/service/flag-evaluation/context_utils.goflagd/pkg/service/flag-evaluation/flag_evaluator.goflagd/pkg/service/flag-evaluation/flag_evaluator_test.goflagd/pkg/service/flag-evaluation/flag_evaluator_v1.goflagd/pkg/service/flag-evaluation/flag_evaluator_v1_test.goflagd/pkg/service/flag-evaluation/flag_evaluator_v2.goflagd/pkg/service/flag-evaluation/flag_evaluator_v2_test.goflagd/pkg/service/flag-evaluation/ofrep/handler.goflagd/pkg/service/flag-evaluation/ofrep/handler_test.goflagd/pkg/service/flag-sync/handler.goflagd/pkg/service/flag-sync/handler_test.go
Signed-off-by: Todd Baert <[email protected]>
|
🤖 I have created a release *beep* *boop* --- <details><summary>flagd: 0.16.1</summary> ## [0.16.1](flagd/v0.16.0...flagd/v0.16.1) (2026-07-27) ### 🐛 Bug Fixes * add server ReadTimeouts, update security deps ([#1980](#1980)) ([0e1e8b3](0e1e8b3)) * handle invalid selector errors ([#1976](#1976)) ([409a62e](409a62e)) * **security:** update module google.golang.org/grpc to v1.82.1 [security] ([#2005](#2005)) ([4281adf](4281adf)) * **security:** update vulnerability-updates [security] ([#1984](#1984)) ([2a5a6b6](2a5a6b6)) ### ✨ New Features * **sync:** configurable gRPC keepalive enforcement on sync server ([#1999](#1999)) ([19e57b9](19e57b9)) </details> <details><summary>flagd-proxy: 0.9.7</summary> ## [0.9.7](flagd-proxy/v0.9.6...flagd-proxy/v0.9.7) (2026-07-27) ### 🐛 Bug Fixes * add server ReadTimeouts, update security deps ([#1980](#1980)) ([0e1e8b3](0e1e8b3)) * **security:** update module google.golang.org/grpc to v1.82.1 [security] ([#2005](#2005)) ([4281adf](4281adf)) * **security:** update vulnerability-updates [security] ([#1984](#1984)) ([2a5a6b6](2a5a6b6)) </details> <details><summary>core: 0.16.1</summary> ## [0.16.1](core/v0.16.0...core/v0.16.1) (2026-07-27) ### 🐛 Bug Fixes * **certreloader:** re-check reload condition under write lock ([#1994](#1994)) ([86489da](86489da)) * handle invalid selector errors ([#1976](#1976)) ([409a62e](409a62e)) * readyz never true of multiple gRPC syncs are used ([#1985](#1985)) ([29833e8](29833e8)) * **security:** update module google.golang.org/grpc to v1.82.1 [security] ([#2005](#2005)) ([4281adf](4281adf)) * **security:** update vulnerability-updates [security] ([#1984](#1984)) ([2a5a6b6](2a5a6b6)) * **sync:** avoid send on closed channel in fileinfo watcher Close ([#1992](#1992)) ([a7339ea](a7339ea)) * **sync:** handle non-string YAML map keys in config parsing ([#1990](#1990)) ([3c72e6f](3c72e6f)) * **sync:** re-establish file watch after delete and restore ([#2001](#2001)) ([d434adf](d434adf)) * **sync:** synchronize readiness state ([#2006](#2006)) ([317a7e0](317a7e0)) ### ✨ New Features * improve ETag and body hash support to blob/http sync ([#1991](#1991)) ([1e210d4](1e210d4)) ### 🧹 Chore * fix flaky test ([7ff137d](7ff137d)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Signed-off-by: OpenFeature Bot <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>



This PR
Invalid selector expressions in the
flagd-selectorheader were causing unhandled errors that surfaced as 500 responses. This PR validates the selector at parse time and maps invalid input to the appropriate error code(
InvalidArgument/ HTTP 400) across all service layers (flag evaluation, flag sync, OFRep).As part of this fix, the
Selectorconstruction API has been redesigned to eliminate unchecked string-based construction entirely:NewSelector(expr string)now returns an error for unknown keysWithIndexis removed (breaking change) — replaced by typed methodsWithSourceandWithFlagSetIdwhich cannot produce an invalid selectorRelated Issues
Notes
Breaking change:
(Selector).WithIndex(key, value string)has been removed from the public API. Callers should migrate toSelector{}.WithSource(source)orSelector{}.WithFlagSetId(id).(with AI help)