Skip to content

refactor: telemetry request parameters#19722

Merged
parametalol merged 3 commits intomasterfrom
michael/telemetry-requestparam-refactoring
Apr 2, 2026
Merged

refactor: telemetry request parameters#19722
parametalol merged 3 commits intomasterfrom
michael/telemetry-requestparam-refactoring

Conversation

@parametalol
Copy link
Copy Markdown
Contributor

@parametalol parametalol commented Mar 31, 2026

Description

This is a prefactoring that simplifies implementation of matching requests by header name glob pattern.

In addition, gRPC metadata is now converted to http.Header type with canonicalized keys to support protocol-independent matching.

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

CI

Current dependencies on/for this PR:

@parametalol parametalol changed the title michael/telemetry-requestparam-refactoring refacotr: telemetry request parameters Mar 31, 2026
@parametalol parametalol changed the title refacotr: telemetry request parameters refactor: telemetry request parameters Mar 31, 2026
@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Mar 31, 2026

Images are ready for the commit at 117a534.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-528-g117a534f8b.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 96.77419% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.61%. Comparing base (c3cccf6) to head (117a534).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
central/telemetry/centralclient/interceptors.go 66.66% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19722      +/-   ##
==========================================
+ Coverage   49.59%   49.61%   +0.01%     
==========================================
  Files        2756     2760       +4     
  Lines      208036   208154     +118     
==========================================
+ Hits       103183   103271      +88     
- Misses      97192    97223      +31     
+ Partials     7661     7660       -1     
Flag Coverage Δ
go-unit-tests 49.61% <96.77%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@parametalol parametalol force-pushed the michael/telemetry-requestparam-refactoring branch from 2e708df to 27967f6 Compare April 1, 2026 07:58
@parametalol parametalol marked this pull request as draft April 1, 2026 12:00
@parametalol parametalol force-pushed the michael/telemetry-requestparam-refactoring branch from 2aa5f95 to 5f7202d Compare April 1, 2026 18:59
@parametalol parametalol marked this pull request as ready for review April 1, 2026 21:44
@parametalol parametalol requested review from a team and stehessel April 2, 2026 08:14
@parametalol
Copy link
Copy Markdown
Contributor Author

/test ocp-4-21-operator-e2e-tests

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Refactored telemetry campaign matching system with improved header pattern matching and request parameter handling for better internal consistency and maintainability.

Walkthrough

The pull request refactors telemetry header handling from function-based callbacks to concrete types. Changes include introducing a GlobMap type for header patterns, replacing HasHeader() with MatchHeaders() that returns matched headers instead of boolean results, updating campaign callback signatures to receive matched headers, and adding new header pattern-matching methods like GetMatching() and NewHeaders() constructor for gRPC metadata support.

Changes

Cohort / File(s) Summary
Interceptor Header Updates
central/telemetry/centralclient/interceptors.go, pkg/telemetry/phonehome/interceptor.go
Changed header handling from function-based callbacks to concrete Headers type; updated ServiceNow integration header constant casing; replaced addCustomHeaders() helper with direct header iteration using phonehome.Headers; modified getGRPCRequestDetails() and getHTTPRequestDetails() to return concrete Headers instead of per-key lookup functions.
Campaign Signature Changes
pkg/telemetry/phonehome/campaign.go
Updated APICallCampaignCriterion.Headers from map[string]glob.Pattern to GlobMap; changed MethodPattern(), PathPattern(), and HeaderPattern() parameter types from string to glob.Pattern; modified CountFulfilled() callback signature to receive matched headers in addition to criterion; updated fulfillment logic to use MatchHeaders() returning Headers instead of boolean.
Headers Multimap Methods
pkg/telemetry/phonehome/headers_multimap.go
Added NewHeaders(metadata.MD) constructor for gRPC metadata conversion; added GetMatching(key string, value glob.Pattern) method for pattern-based header retrieval with nil/absent-key semantics; removed standalone GetFirst() helper function.
Request Parameters Refactor
pkg/telemetry/phonehome/request_params.go
Changed RequestParams.Headers from func(string) []string to concrete Headers type; introduced exported GlobMap type; replaced HasHeader() method with MatchHeaders() that returns matched Headers or nil on pattern mismatches.
Interceptor Tests
central/telemetry/centralclient/interceptors_test.go, pkg/telemetry/phonehome/interceptor_test.go
Updated withUserAgent() helper to return concrete Headers instead of function; replaced test assertions using Headers(...) callable accessor with .Get(key) method calls; removed Test_addCustomHeaders() test entirely; added case-insensitive header key canonicalization assertion.
Campaign and Headers Tests
pkg/telemetry/phonehome/campaign_test.go, pkg/telemetry/phonehome/headers_multimap_test.go, pkg/telemetry/phonehome/request_params_test.go
Updated test helpers and assertions to use concrete Headers type with .Get() method; replaced TestHasHeader() with TestMatchHeaders() verifying Headers return type and pattern-matching behavior; removed TestGetFirst(); added TestGetMatching() with table-driven cases for glob pattern matching; adjusted header pattern construction from map[string]glob.Pattern to GlobMap.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 43.75% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor: telemetry request parameters' directly describes the main change - a refactoring of telemetry request parameter handling to support header-based pattern matching.
Description check ✅ Passed The PR description covers the main objectives (prefactoring for header matching, gRPC metadata conversion), indicates testing approach (CI-tested with unit tests added/modified), and completes the required checklist items comprehensively.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • ✅ Generated successfully - (🔄 Check to regenerate)
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michael/telemetry-requestparam-refactoring

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.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
central/telemetry/centralclient/interceptors.go (1)

14-14: Header constant casing changed.

The constant changed from Rh-ServiceNow-Integration to Rh-Servicenow-Integration. Since HTTP header lookup is case-insensitive and http.Header canonicalizes keys, this should work correctly for matching. However, if external systems expect the exact original casing in responses or logs, verify this change aligns with their expectations.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@central/telemetry/centralclient/interceptors.go` at line 14, The header
constant snowIntegrationHeader in interceptors.go was altered from
"Rh-ServiceNow-Integration" to "Rh-Servicenow-Integration"; revert the constant
value back to "Rh-ServiceNow-Integration" (or confirm with integrators that the
new casing is acceptable) so external systems expecting the original exact
header casing in responses/logs are not broken; update the snowIntegrationHeader
definition accordingly and run tests to ensure no callers or logs rely on the
changed string.
pkg/telemetry/phonehome/campaign_test.go (1)

140-140: Typo in variable name.

expecedHeaders should be expectedHeaders.

Proposed fix
-		expecedHeaders := Headers{
+		expectedHeaders := Headers{

Also update the reference on line 155.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/telemetry/phonehome/campaign_test.go` at line 140, Rename the misspelled
test variable `expecedHeaders` to `expectedHeaders` (the variable is of type
`Headers`) and update any references to it in the same test (e.g., the assertion
or comparison that currently uses `expecedHeaders`) to use `expectedHeaders`
instead so the identifier matches the correct spelling.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@central/telemetry/centralclient/interceptors.go`:
- Line 14: The header constant snowIntegrationHeader in interceptors.go was
altered from "Rh-ServiceNow-Integration" to "Rh-Servicenow-Integration"; revert
the constant value back to "Rh-ServiceNow-Integration" (or confirm with
integrators that the new casing is acceptable) so external systems expecting the
original exact header casing in responses/logs are not broken; update the
snowIntegrationHeader definition accordingly and run tests to ensure no callers
or logs rely on the changed string.

In `@pkg/telemetry/phonehome/campaign_test.go`:
- Line 140: Rename the misspelled test variable `expecedHeaders` to
`expectedHeaders` (the variable is of type `Headers`) and update any references
to it in the same test (e.g., the assertion or comparison that currently uses
`expecedHeaders`) to use `expectedHeaders` instead so the identifier matches the
correct spelling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: b73b4739-be94-4858-b7b8-7ca6e167f4ac

📥 Commits

Reviewing files that changed from the base of the PR and between c3cccf6 and 117a534.

📒 Files selected for processing (10)
  • central/telemetry/centralclient/interceptors.go
  • central/telemetry/centralclient/interceptors_test.go
  • pkg/telemetry/phonehome/campaign.go
  • pkg/telemetry/phonehome/campaign_test.go
  • pkg/telemetry/phonehome/headers_multimap.go
  • pkg/telemetry/phonehome/headers_multimap_test.go
  • pkg/telemetry/phonehome/interceptor.go
  • pkg/telemetry/phonehome/interceptor_test.go
  • pkg/telemetry/phonehome/request_params.go
  • pkg/telemetry/phonehome/request_params_test.go

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #19777

coderabbitai bot added a commit that referenced this pull request Apr 2, 2026
Docstrings generation was requested by @parametalol.

* #19722 (comment)

The following files were modified:

* `central/telemetry/centralclient/interceptors.go`
* `pkg/telemetry/phonehome/campaign.go`
* `pkg/telemetry/phonehome/headers_multimap.go`
* `pkg/telemetry/phonehome/interceptor.go`
@parametalol parametalol merged commit 994dff5 into master Apr 2, 2026
117 checks passed
@parametalol parametalol deleted the michael/telemetry-requestparam-refactoring branch April 2, 2026 12:31
c-du pushed a commit that referenced this pull request Apr 2, 2026
parametalol pushed a commit that referenced this pull request Apr 3, 2026
Docstrings generation was requested by @parametalol.

* #19722 (comment)

The following files were modified:

* `central/telemetry/centralclient/interceptors.go`
* `pkg/telemetry/phonehome/campaign.go`
* `pkg/telemetry/phonehome/headers_multimap.go`
* `pkg/telemetry/phonehome/interceptor.go`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants