Skip to content

fix: bound evaluation HTTP metric labels - #2092

Merged
toddbaert merged 2 commits into
open-feature:mainfrom
pbacterio:fix/bound-evaluation-http-metric-labels
Oct 26, 2026
Merged

toddbaert merged 2 commits into
open-feature:mainfrom
pbacterio:fix/bound-evaluation-http-metric-labels

Conversation

@pbacterio

Copy link
Copy Markdown
Contributor

This PR

The evaluation service (default port 8013) recorded raw request paths and HTTP methods as http.server metric attributes. Requests to arbitrary paths or with custom methods could create unbounded metric series.

This PR applies the same behaviour as OFREP service:

  • Resolve http.route against the exact registered legacy, v1, and v2 RPC procedures, using / for every other path.
  • Canonicalize standard HTTP methods and record unknown methods as _OTHER, matching the bounded labels used by OFREP.

Request routing and responses are unchanged.

Add regression coverage for registered and unknown paths, custom and mixed-case methods, metric labels across the HTTP instruments, and 404 responses. The core telemetry and affected flagd package tests pass.

How to test

# Launch flagd
go run ./flagd start --uri file:./samples/example_flags.flagd.json

# Calls with random http methods and paths
curl -sS -o /dev/null http://localhost:8013/unknown/one
curl -sS -o /dev/null -X PROPFIND http://localhost:8013/unknown/two
curl -sS -o /dev/null -X MADEUP http://localhost:8013/unknown/three

# Verify correct mapping of the metrics attributes
curl -sS http://localhost:8014/metrics | grep '^http_server_request_duration'

@pbacterio
pbacterio requested review from a team as code owners October 20, 2026 07:45
@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit f84dcb0
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/6adf531fe54e00b1dc3fbb1b

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cb7ccfc9-7379-4d16-bc80-9a9374052dd6
📥 Commits

Reviewing files that changed from the base of the PR and between 1f9b7c5 and 2131661.

📒 Files selected for processing: 4
  • core/pkg/telemetry/metrics.go
  • core/pkg/telemetry/metrics_test.go
  • flagd/pkg/service/flag-evaluation/connect_service.go
  • flagd/pkg/service/flag-evaluation/connect_service_test.go
🚧 Files skipped from review as they are similar to previous changes: 4
  • core/pkg/telemetry/metrics.go
  • flagd/pkg/service/flag-evaluation/connect_service.go
  • core/pkg/telemetry/metrics_test.go
  • flagd/pkg/service/flag-evaluation/connect_service_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

HTTP metric methods are normalized, and evaluation-service metrics use request-specific route labels. Registered RPC paths retain their route; unmatched paths map to /.

Changes: HTTP metric labels

Layer / File(s) Summary
Standardize HTTP method labels
core/pkg/telemetry/metrics.go, core/pkg/telemetry/metrics_test.go
HTTPAttributes uppercases standard HTTP methods and maps other values to _OTHER. Tests cover method normalization and recorder behavior.
Derive routes from HTTP requests
flagd/pkg/service/middleware/metrics/http_metrics.go, flagd/pkg/service/flag-evaluation/connect_service.go, flagd/pkg/service/flag-evaluation/connect_service_test.go
The middleware can select a handler ID per request. The evaluation service maps registered RPC paths to routes and other paths to /. Tests inspect emitted route and method labels.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: toddbaert

Merge Risk: Minimal · up to 21316

The metric-label change appears ready to merge after normal checks.

Security architecture risk: Minimal · up to 1f9b7

The change bounds request-controlled metric labels without changing request routing or access controls. No introduced or worsened material security risk was identified in the reviewed change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed attack surface concerns telemetry resource consumption from requests reaching the evaluation service. Method normalization also applies to other consumers of the shared HTTPAttributes implementation; it does not grant additional request authority.

Security Findings and Attack Paths

  • inferred — Arbitrary paths and custom methods previously could produce distinct label values through the raw-path fallback and verbatim method recording. The new allowlists remove that unbounded label-value mechanism for evaluation HTTP metrics. This is a reduction of a pre-existing exposure, not a newly introduced concern.

Trust Boundaries and Controls

  • observed — Attacker-controlled path and method values cross into metric storage only after bounded classification on the evaluation path. Unknown paths receive a fallback metric label without being rerouted, and method normalization affects attributes rather than HTTP dispatch.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: bounding evaluation HTTP metric labels.
Description check Passed The description directly explains the unbounded metric-label issue, the route and method fixes, regression coverage, and test steps.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@pbacterio
pbacterio force-pushed the fix/bound-evaluation-http-metric-labels branch 3 times, most recently from 904e96a to 1f9b7c5 Compare October 20, 2026 08:32
@erka

erka commented Oct 20, 2026

Copy link
Copy Markdown
Member

Hey @pbacterio

Thanks for your PR. Your work is related to PR #2077. Anyway to combine this effort with that into one change?

@toddbaert toddbaert left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think I prefer this implementation over 2077. In there, if I'm reading correctly, evaluation.v1.Service/<anything> would still get recorded as is, and we have the same issue.

I don't love the maintenance associated with this hard-coded list, but in reality it's not that much.

Will merge tomorrow unless somebody objects.

Comment thread core/pkg/telemetry/metrics.go Resolved
@pbacterio

Copy link
Copy Markdown
Contributor Author

I don't love the maintenance associated with this hard-coded list, but in reality it's not that much.

@toddbaert what about to use protobuf reflections to simplify it?

func buildEvaluationMetricRoutes() map[string]struct{} {
	routes := make(map[string]struct{})
	for _, fd := range []protoreflect.FileDescriptor{
		schemaV1pb.File_schema_v1_schema_proto,
		evalV1pb.File_flagd_evaluation_v1_evaluation_proto,
		evalV2pb.File_flagd_evaluation_v2_evaluation_proto,
	} {
		svcs := fd.Services()
		for i := 0; i < svcs.Len(); i++ {
			svc := svcs.Get(i)
			methods := svc.Methods()
			for j := 0; j < methods.Len(); j++ {
				routes["/"+string(svc.FullName())+"/"+string(methods.Get(j).Name())] = struct{}{}
			}
		}
	}
	return routes
}

@toddbaert

toddbaert commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

I don't love the maintenance associated with this hard-coded list, but in reality it's not that much.

@toddbaert what about to use protobuf reflections to simplify it?

func buildEvaluationMetricRoutes() map[string]struct{} {
	routes := make(map[string]struct{})
	for _, fd := range []protoreflect.FileDescriptor{
		schemaV1pb.File_schema_v1_schema_proto,
		evalV1pb.File_flagd_evaluation_v1_evaluation_proto,
		evalV2pb.File_flagd_evaluation_v2_evaluation_proto,
	} {
		svcs := fd.Services()
		for i := 0; i < svcs.Len(); i++ {
			svc := svcs.Get(i)
			methods := svc.Methods()
			for j := 0; j < methods.Len(); j++ {
				routes["/"+string(svc.FullName())+"/"+string(methods.Get(j).Name())] = struct{}{}
			}
		}
	}
	return routes
}

I've added something like this here.

@toddbaert
toddbaert force-pushed the fix/bound-evaluation-http-metric-labels branch from e4388f3 to 073045c Compare October 23, 2026 21:01
@toddbaert
toddbaert requested a review from erka October 23, 2026 21:18
@pbacterio
pbacterio force-pushed the fix/bound-evaluation-http-metric-labels branch from 073045c to 37a0811 Compare October 26, 2026 08:16
pbacterio and others added 2 commits October 26, 2026 09:18
The evaluation service (default port 8013) recorded raw request paths and HTTP methods as http.server metric attributes. Requests to arbitrary paths or with custom methods could create unbounded metric series.

Resolve http.route against the exact registered legacy, v1, and v2 RPC procedures, using / for every other path. Canonicalize standard HTTP methods and record unknown methods as _OTHER, matching the bounded labels used by OFREP. Request routing and responses are unchanged.

Add regression coverage for registered and unknown paths, custom and mixed-case methods, metric labels across the HTTP instruments, and 404 responses. The core telemetry and affected flagd package tests pass.

Signed-off-by: Germán Moya <[email protected]>
@toddbaert
toddbaert force-pushed the fix/bound-evaluation-http-metric-labels branch from 872ae33 to f84dcb0 Compare October 26, 2026 13:18
@sonarqubecloud

Copy link
Copy Markdown

@toddbaert
toddbaert merged commit f2e7713 into open-feature:main Oct 26, 2026
22 of 24 checks passed
toddbaert added a commit that referenced this pull request Oct 26, 2026
Stacked on #2092.

Disables otelhttp metrics on the OFREP/sync handlers (tracing is kept),
so OFREP requests are recorded once by the flagd metrics middleware.
Together with the status-code fix in #2092, this fixes #2102.

---------

Signed-off-by: Todd Baert <[email protected]>
toddbaert pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


<details><summary>flagd: 0.18.1</summary>

##
[0.18.1](flagd/v0.18.0...flagd/v0.18.1)
(2026-10-26)


### 🐛 Bug Fixes

* bound evaluation HTTP metric labels
([#2092](#2092))
([f2e7713](f2e7713))
* record OFREP and sync HTTP metrics once
([#2103](#2103))
([0a39a29](0a39a29))


### ✨ New Features

* add flag set ID to evaluation metrics
([#2078](#2078))
([10f2ca0](10f2ca0))
* strict numeric range opt, TYPE_MISMATCH on precision loss
([#2100](#2100))
([5cf6fff](5cf6fff))


### 🧹 Chore

* **deps:** update module golang.org/x/net to v0.61.0
([#2097](#2097))
([21db5c3](21db5c3))
* Update CHANGELOG with more details
([3f01794](3f01794))
</details>

<details><summary>flagd-proxy: 0.9.13</summary>

##
[0.9.13](flagd-proxy/v0.9.12...flagd-proxy/v0.9.13)
(2026-10-26)


### 🧹 Chore

* **deps:** update module golang.org/x/net to v0.61.0
([#2097](#2097))
([21db5c3](21db5c3))
</details>

<details><summary>core: 0.19.1</summary>

##
[0.19.1](core/v0.19.0...core/v0.19.1)
(2026-10-26)


### 🐛 Bug Fixes

* bound evaluation HTTP metric labels
([#2092](#2092))
([f2e7713](f2e7713))
* record OFREP and sync HTTP metrics once
([#2103](#2103))
([0a39a29](0a39a29))


### ✨ New Features

* add flag set ID to evaluation metrics
([#2078](#2078))
([10f2ca0](10f2ca0))
* strict numeric range opt, TYPE_MISMATCH on precision loss
([#2100](#2100))
([5cf6fff](5cf6fff))
</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]>
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