Skip to content

Conversation

jade-guiton-dd
Copy link
Contributor

@jade-guiton-dd jade-guiton-dd commented Oct 10, 2025

Description

This PR introduces:

  • A generic MapList[T] type, which is equivalent to []{ Name string, Value T }, but can be unmarshalled from a map[string]T as well. This type is defined in a new internal/maplist package.
  • A specialized version exported as configopaque.MapList

configgrpc and confighttp are changed to use this type instead of map[string]configopaque.String for storing header configuration, so as to be consistent with the SDK declarative config (see tracking issue).

Note that while this is relatively elegant, it causes a number of breaking changes. An alternative would be to keep the current map[string]configopaque.String types, and add an Unmarshal method on the surrounding struct: see this PoC.

Link to tracking issue

Fixes #13930

Testing

I added a basic unit test in internal/maplist.

@codecov
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.65%. Comparing base (71418b6) to head (417796e).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13996      +/-   ##
==========================================
+ Coverage   91.61%   91.65%   +0.03%     
==========================================
  Files         655      657       +2     
  Lines       42793    42864      +71     
==========================================
+ Hits        39205    39287      +82     
+ Misses       2765     2758       -7     
+ Partials      823      819       -4     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

i think this is the right approach 👍🏻

songy23 pushed a commit to open-telemetry/opentelemetry-collector-contrib that referenced this pull request Oct 15, 2025
#### Description

#43509 changed the `make for-all` Makefile target to access the
`ALL_MODS` variable through environment variables instead of expanding
it into the shell command, in order to bypass Windows' 8192 byte command
line length limit.

However, the environment variable was not defined, which led to `make
for-all` becoming a no-op. This can be confirmed by running `make
for-all CMD='echo test'`.

(I discovered this issue because [this
PR](open-telemetry/opentelemetry-collector#13996)
in core repository, which should be failing `contrib-tests`, suddenly
started passing them. This was because the job inserts `replace`
statements in a copy of contrib using `for-all`; failing to do that
caused the contrib tests to run against whatever version of core is
imported here rather than against the PR's code.)

This PR fixes that oversight, by adding the `export` keyword to the
`ALL_MODS` variable.
@jade-guiton-dd
Copy link
Contributor Author

jade-guiton-dd commented Oct 16, 2025

Next steps:

  • File a draft PR in contrib with the corresponding changes, so the breakage can be fixed quickly
  • Mark this as ready for review
  • File a follow-up issue about deprecating and eventually removing the "map" behavior

ChrsMark pushed a commit to ChrsMark/opentelemetry-collector-contrib that referenced this pull request Oct 20, 2025
#### Description

open-telemetry#43509 changed the `make for-all` Makefile target to access the
`ALL_MODS` variable through environment variables instead of expanding
it into the shell command, in order to bypass Windows' 8192 byte command
line length limit.

However, the environment variable was not defined, which led to `make
for-all` becoming a no-op. This can be confirmed by running `make
for-all CMD='echo test'`.

(I discovered this issue because [this
PR](open-telemetry/opentelemetry-collector#13996)
in core repository, which should be failing `contrib-tests`, suddenly
started passing them. This was because the job inserts `replace`
statements in a copy of contrib using `for-all`; failing to do that
caused the contrib tests to run against whatever version of core is
imported here rather than against the PR's code.)

This PR fixes that oversight, by adding the `export` keyword to the
`ALL_MODS` variable.
@jade-guiton-dd
Copy link
Contributor Author

jade-guiton-dd commented Oct 20, 2025

I pushed the corresponding changes in contrib on my fork here; all in all, about 150 small changes, mostly in tests.

Along the way, I ended up modifying this PR's core API to make it match the native map API better and make the migration easier. These changes have some notable implications:

  • MapList[T] is now meant to be used through a pointer, and has the same distinction between "nil" and "empty but not nil" as map
  • MapList[T] now has a few additional methods, all of which will be part of configopaque's exported API. Since the module is stable, this API will immediately be set in stone (at least until v2), so I'd like additional scrutiny on it.
  • The Get, TryGet, and Set methods have a linear time complexity, vs. the constant time complexity of using map. I doubt there is a significant risk of users adding so many headers that this becomes a problem, but I'm interested in feedback.

I will mark this PR as ready for review, but as a reminder, we can still change course and go for the "backwards-compatible" approach if the benefits of this PR are not deemed to be worth the additional complexity.


// The headers associated with gRPC requests.
Headers map[string]configopaque.String `mapstructure:"headers,omitempty"`
Headers *configopaque.MapList `mapstructure:"headers,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

If we can do without the * that would be better

// Existing header values are overwritten if collision happens.
// Header values are opaque since they may be sensitive.
Headers map[string]configopaque.String `mapstructure:"headers,omitempty"`
Headers *configopaque.MapList `mapstructure:"headers,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

ditto

@mx-psi mx-psi marked this pull request as draft October 22, 2025 14:33
@mx-psi
Copy link
Member

mx-psi commented Oct 22, 2025

I am going to mark this as draft until it is ready for another review, feel free to mark as ready whenever that happens!

@jade-guiton-dd
Copy link
Contributor Author

I think I've addressed all the previous comments, and I've filed a corresponding draft PR in contrib (open-telemetry/opentelemetry-collector-contrib#43701) which is almost passing tests, so I'll mark this as ready for another round of review.

@jade-guiton-dd jade-guiton-dd marked this pull request as ready for review October 23, 2025 12:07
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

This looks good to me. Since this introduces a new type on a 1.x module, I want to get at least one more approval before moving forward with this.

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.

[configgrpc, confighttp] update headers to array of name/value pairs to match configuration schema

3 participants