Skip to content

fix(observability): instrument broker and jobsink requests once - #9606

Open
RajPrakash681 wants to merge 1 commit into
knative:mainfrom
RajPrakash681:fix/broker-double-count
Open

RajPrakash681 wants to merge 1 commit into
knative:mainfrom
RajPrakash681:fix/broker-double-count

Conversation

@RajPrakash681

@RajPrakash681 RajPrakash681 commented Nov 21, 2026 •

Copy link
Copy Markdown

Fixes #9605

Proposed Changes

  • 🐛 The MT Broker ingress, the MT Broker filter and the job-sink record each request once in http.server.request.duration and the HTTP body-size histograms, with one server span. Before, their handler was wrapped with otelhttp twice, so the requests it handled were counted twice.
  • otel.NewHandler becomes otel.HandlerOptions: the meter and tracer providers and the span name formatter now go through eventingtls.NewServerManager to the otelhttp handler that the receiver already creates.
  • Tested with unit tests and on Eventing 1.24.0: 50 events sent to a Broker counted 100 at the ingress and at the filter before this change, and 50 after.

Pre-review Checklist

  • At least 80% unit test coverage
  • E2E tests for any new behavior
  • Docs PR for any user-facing impact
  • Spec PR for any new API feature
  • Conformance test for any change to the spec

Release Note

The MT Broker ingress, the MT Broker filter and the job-sink no longer count requests twice in `http.server.request.duration` and the HTTP body-size metrics, and create one server span per request instead of two.

Docs

None needed.

@knative-prow

knative-prow Bot commented Nov 21, 2026

Copy link
Copy Markdown

Welcome @RajPrakash681! It looks like this is your first PR to knative/eventing 🎉

@knative-prow knative-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 21, 2026
@knative-prow

knative-prow Bot commented Nov 21, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: RajPrakash681
Once this PR has been reviewed and has the lgtm label, please assign dsimansk for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow

knative-prow Bot commented Nov 21, 2026

Copy link
Copy Markdown

Hi @RajPrakash681. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@knative-prow
knative-prow Bot requested review from creydr and matzew November 21, 2026 19:27
@RajPrakash681
RajPrakash681 force-pushed the fix/broker-double-count branch 2 times, most recently from e4b6d82 to 6ef4596 Compare November 22, 2026 12:14
@kahirokunn

Copy link
Copy Markdown
Member

/ok-to-test

@knative-prow knative-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 22, 2026
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.46%. Comparing base (f819a05) to head (6ef4596).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/observability/otel/handler.go 0.00% 8 Missing ⚠️
cmd/jobsink/main.go 0.00% 2 Missing ⚠️
pkg/eventingtls/servermanager.go 50.00% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9606      +/-   ##
==========================================
+ Coverage   51.33%   51.46%   +0.12%     
==========================================
  Files         412      412              
  Lines       22189    22178      -11     
==========================================
+ Hits        11391    11414      +23     
+ Misses       9917     9880      -37     
- Partials      881      884       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kahirokunn

Copy link
Copy Markdown
Member

/retest

t.Fatal("Unable to create handler:", err)
}

httpPort := freeport.GetPort()

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.

freeport.GetPort() releases the port before the receiver binds it, so another process can take it and waitForListener can mistake that listener for the receiver. Could the test bind to port 0, wait for Ready, and use GetPort() to get the assigned port?

tp := sdktrace.NewTracerProvider(sdktrace.WithSyncer(exporter))

prevMP, prevTP := otel.GetMeterProvider(), otel.GetTracerProvider()
otel.SetMeterProvider(mp)

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.

The first calls to otel.SetMeterProvider and otel.SetTracerProvider make the original default providers forward to these test providers. Restoring the saved providers in t.Cleanup leaves that forwarding in place, so later tests can still send telemetry to this test’s reader and exporter. Could we isolate the global provider setup in a subprocess?

Signed-off-by: RajPrakash681 <rjnt452@gmail.com>
@RajPrakash681
RajPrakash681 force-pushed the fix/broker-double-count branch from 6ef4596 to 183f26c Compare November 27, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MT Broker ingress and filter count requests twice in http.server.request.duration

2 participants