Skip to content

Commit 8fb2b60

Browse files
atoulmegithub-actions[bot]
authored andcommitted
[extension/headersetter] unexport Header struct (open-telemetry#40542)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 7a9b64e commit 8fb2b60

File tree

3 files changed

+60
-33
lines changed

3 files changed

+60
-33
lines changed

.chloggen/unexport_header.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: headersetterextension
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Unexport Header
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40542]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

extension/headerssetterextension/extension.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/headerssetterextension/internal/source"
2020
)
2121

22-
type Header struct {
22+
type header struct {
2323
action action.Action
2424
source source.Source
2525
}
@@ -34,7 +34,7 @@ type headerSetterExtension struct {
3434
component.StartFunc
3535
component.ShutdownFunc
3636

37-
headers []Header
37+
headers []header
3838
}
3939

4040
// PerRPCCredentials implements extensionauth.GRPCClient.
@@ -55,50 +55,50 @@ func newHeadersSetterExtension(cfg *Config, logger *zap.Logger) (*headerSetterEx
5555
return nil, errors.New("extension configuration is not provided")
5656
}
5757

58-
headers := make([]Header, 0, len(cfg.HeadersConfig))
59-
for _, header := range cfg.HeadersConfig {
58+
headers := make([]header, 0, len(cfg.HeadersConfig))
59+
for _, h := range cfg.HeadersConfig {
6060
var s source.Source
6161
switch {
62-
case header.Value != nil:
62+
case h.Value != nil:
6363
s = &source.StaticSource{
64-
Value: *header.Value,
64+
Value: *h.Value,
6565
}
66-
case header.FromAttribute != nil:
66+
case h.FromAttribute != nil:
6767
defaultValue := ""
68-
if header.DefaultValue != nil {
69-
defaultValue = string(*header.DefaultValue)
68+
if h.DefaultValue != nil {
69+
defaultValue = string(*h.DefaultValue)
7070
}
7171
s = &source.AttributeSource{
72-
Key: *header.FromAttribute,
72+
Key: *h.FromAttribute,
7373
DefaultValue: defaultValue,
7474
}
75-
case header.FromContext != nil:
75+
case h.FromContext != nil:
7676
defaultValue := ""
77-
if header.DefaultValue != nil {
78-
defaultValue = string(*header.DefaultValue)
77+
if h.DefaultValue != nil {
78+
defaultValue = string(*h.DefaultValue)
7979
}
8080
s = &source.ContextSource{
81-
Key: *header.FromContext,
81+
Key: *h.FromContext,
8282
DefaultValue: defaultValue,
8383
}
8484
}
8585

8686
var a action.Action
87-
switch header.Action {
87+
switch h.Action {
8888
case INSERT:
89-
a = action.Insert{Key: *header.Key}
89+
a = action.Insert{Key: *h.Key}
9090
case UPSERT:
91-
a = action.Upsert{Key: *header.Key}
91+
a = action.Upsert{Key: *h.Key}
9292
case UPDATE:
93-
a = action.Update{Key: *header.Key}
93+
a = action.Update{Key: *h.Key}
9494
case DELETE:
95-
a = action.Delete{Key: *header.Key}
95+
a = action.Delete{Key: *h.Key}
9696
default:
97-
a = action.Upsert{Key: *header.Key}
97+
a = action.Upsert{Key: *h.Key}
9898
logger.Warn("The action was not provided, using 'upsert'." +
9999
" In future versions, we'll require this to be explicitly set")
100100
}
101-
headers = append(headers, Header{action: a, source: s})
101+
headers = append(headers, header{action: a, source: s})
102102
}
103103

104104
return &headerSetterExtension{headers: headers}, nil
@@ -107,7 +107,7 @@ func newHeadersSetterExtension(cfg *Config, logger *zap.Logger) (*headerSetterEx
107107
// headersPerRPC is a gRPC credentials.PerRPCCredentials implementation sets
108108
// headers with values extracted from provided sources.
109109
type headersPerRPC struct {
110-
headers []Header
110+
headers []header
111111
}
112112

113113
// GetRequestMetadata returns the request metadata to be used with the RPC.
@@ -137,7 +137,7 @@ func (h *headersPerRPC) RequireTransportSecurity() bool {
137137
// values extracted from configured sources.
138138
type headersRoundTripper struct {
139139
base http.RoundTripper
140-
headers []Header
140+
headers []header
141141
}
142142

143143
// RoundTrip copies the original request and sets headers of the new requests

extension/headerssetterextension/extension_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func TestPerRPCCredentials(t *testing.T) {
9090

9191
var (
9292
mrt = &mockRoundTripper{}
93-
header = "header_name"
93+
headername = "header_name"
9494
anotherHeader = "another_header_name"
9595
tests = []struct {
9696
cfg *Config
@@ -101,7 +101,7 @@ var (
101101
cfg: &Config{
102102
HeadersConfig: []HeaderConfig{
103103
{
104-
Key: &header,
104+
Key: &headername,
105105
Action: INSERT,
106106
FromContext: stringp("tenant"),
107107
},
@@ -118,7 +118,7 @@ var (
118118
cfg: &Config{
119119
HeadersConfig: []HeaderConfig{
120120
{
121-
Key: &header,
121+
Key: &headername,
122122
Action: INSERT,
123123
Value: stringp("config value"),
124124
},
@@ -132,7 +132,7 @@ var (
132132
cfg: &Config{
133133
HeadersConfig: []HeaderConfig{
134134
{
135-
Key: &header,
135+
Key: &headername,
136136
Action: INSERT,
137137
FromContext: stringp("tenant"),
138138
},
@@ -155,7 +155,7 @@ var (
155155
cfg: &Config{
156156
HeadersConfig: []HeaderConfig{
157157
{
158-
Key: &header,
158+
Key: &headername,
159159
Action: INSERT,
160160
FromContext: stringp(""),
161161
},
@@ -169,7 +169,7 @@ var (
169169
cfg: &Config{
170170
HeadersConfig: []HeaderConfig{
171171
{
172-
Key: &header,
172+
Key: &headername,
173173
Action: INSERT,
174174
Value: stringp(""),
175175
},
@@ -183,7 +183,7 @@ var (
183183
cfg: &Config{
184184
HeadersConfig: []HeaderConfig{
185185
{
186-
Key: &header,
186+
Key: &headername,
187187
Action: INSERT,
188188
FromContext: stringp("tenant"),
189189
},
@@ -206,7 +206,7 @@ var (
206206
cfg: &Config{
207207
HeadersConfig: []HeaderConfig{
208208
{
209-
Key: &header,
209+
Key: &headername,
210210
Action: INSERT,
211211
FromContext: stringp("tenant_"),
212212
},
@@ -223,7 +223,7 @@ var (
223223
cfg: &Config{
224224
HeadersConfig: []HeaderConfig{
225225
{
226-
Key: &header,
226+
Key: &headername,
227227
Action: INSERT,
228228
FromContext: stringp("tenant"),
229229
DefaultValue: opaquep("default_tenant"),
@@ -241,7 +241,7 @@ var (
241241
cfg: &Config{
242242
HeadersConfig: []HeaderConfig{
243243
{
244-
Key: &header,
244+
Key: &headername,
245245
Action: INSERT,
246246
FromContext: stringp("tenant"),
247247
DefaultValue: opaquep("default_tenant"),

0 commit comments

Comments
 (0)