-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[configgrpc, confighttp] Support lists of name/value pairs for headers #13996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jade-guiton-dd
wants to merge
22
commits into
open-telemetry:main
Choose a base branch
from
jade-guiton-dd:list-map-duality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2955df1
Allow list of name/value pairs for configgrpc.ClientConfig.Headers
jade-guiton-dd c933de4
Add generic internal/maplist package, and specialized configoptional.…
jade-guiton-dd 80dd3ab
Merge branch 'main' into list-map-duality
jade-guiton-dd cab6953
gotidy
jade-guiton-dd 10f7315
Fix otelcorecol
jade-guiton-dd 38ce272
Add single changelog under 'all' component
jade-guiton-dd d3c25ab
Fix ocb test
jade-guiton-dd 38b451d
Add 'maplist' to spellcheck list
jade-guiton-dd 549da85
Enforce key unicity, add `Pairs` method, and more tests
jade-guiton-dd aa534ad
Better test coverage
jade-guiton-dd 41a3893
Make API closer to native map to ease migration
jade-guiton-dd 18d6730
tidy and lint
jade-guiton-dd 5ba5118
Remove usages of MapListFromList
mx-psi 6046148
Reformat MapList literals
jade-guiton-dd 464ff75
Remove superfluous methods and specialize for configopaque.String
jade-guiton-dd fd2c22b
Merge branch 'main' into list-map-duality
jade-guiton-dd a0dd48d
tidy + checkapi
jade-guiton-dd 31225c1
Fix test and minimize diff
jade-guiton-dd 9fc0775
Use MapList without pointer
jade-guiton-dd 0c39a29
tidy + fixes
jade-guiton-dd 3ac2104
Make ResponseHeaders omitempty and fix e2e test
jade-guiton-dd 417796e
Address review feedback
jade-guiton-dd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: 'breaking' | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
| component: all | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Change type of `configgrpc.ClientConfig.Headers`, `confighttp.ClientConfig.Headers`, and `confighttp.ServerConfig.ResponseHeaders` | ||
|
|
||
| # One or more tracking issues or pull requests related to the change | ||
| issues: [13930] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | | ||
| `configopaque.MapList` is a new alternative to `map[string]configopaque.String` which can unmarshal | ||
| both maps and lists of name/value pairs. | ||
|
|
||
| For example, if `headers` is a field of type `configopaque.MapList`, | ||
| then the following YAML configs will unmarshal to the same thing: | ||
| ```yaml | ||
| headers: | ||
| "foo": "bar" | ||
|
|
||
| headers: | ||
| - name: "foo" | ||
| value: "bar" | ||
| ``` | ||
|
|
||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [api] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -288,6 +288,7 @@ | |
| "logstest", | ||
| "lycheeverse", | ||
| "mapconverter", | ||
| "maplist", | ||
| "mapstructure", | ||
| "marshalers", | ||
| "mdatagen", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,7 @@ type ClientConfig struct { | |
| // Additional headers attached to each HTTP request sent by the client. | ||
| // 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"` | ||
|
||
|
|
||
| // Auth configuration for outgoing HTTP calls. | ||
| Auth configoptional.Optional[configauth.Config] `mapstructure:"auth,omitempty"` | ||
|
|
@@ -130,7 +130,7 @@ func NewDefaultClientConfig() ClientConfig { | |
| defaultTransport := http.DefaultTransport.(*http.Transport) | ||
|
|
||
| return ClientConfig{ | ||
| Headers: map[string]configopaque.String{}, | ||
| Headers: configopaque.NewMapList(), | ||
| MaxIdleConns: defaultTransport.MaxIdleConns, | ||
| IdleConnTimeout: defaultTransport.IdleConnTimeout, | ||
| ForceAttemptHTTP2: true, | ||
|
|
@@ -235,7 +235,7 @@ func (cc *ClientConfig) ToClient(ctx context.Context, host component.Host, setti | |
| } | ||
| } | ||
|
|
||
| if len(cc.Headers) > 0 { | ||
| if cc.Headers.Len() > 0 { | ||
| clientTransport = &headerRoundTripper{ | ||
| transport: clientTransport, | ||
| headers: cc.Headers, | ||
|
|
@@ -283,18 +283,18 @@ func (cc *ClientConfig) ToClient(ctx context.Context, host component.Host, setti | |
| // Custom RoundTripper that adds headers. | ||
| type headerRoundTripper struct { | ||
| transport http.RoundTripper | ||
| headers map[string]configopaque.String | ||
| headers *configopaque.MapList | ||
| } | ||
|
|
||
| // RoundTrip is a custom RoundTripper that adds headers to the request. | ||
| func (interceptor *headerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| // Set Host header if provided | ||
| hostHeader, found := interceptor.headers["Host"] | ||
| hostHeader, found := interceptor.headers.TryGet("Host") | ||
| if found && hostHeader != "" { | ||
| // `Host` field should be set to override default `Host` header value which is Endpoint | ||
| req.Host = string(hostHeader) | ||
| } | ||
| for k, v := range interceptor.headers { | ||
| for k, v := range interceptor.headers.Iter { | ||
| req.Header.Set(k, string(v)) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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