Skip to content

Commit 9f862de

Browse files
authored
NH-76572 Applied community feedback back to our current code (#42)
- Applied configgrpc for better configuration support - Applied ToClientConn for better gRPC client creation - Removed the usage of depreciated type & layer from apm-proto decoding - Removed the usage of depreciated function call Subjects in SystemCertPool - Sync-ed with the current upstream PR (More mock unit tests for gRPC responses)
1 parent a45d5e7 commit 9f862de

File tree

16 files changed

+755
-440
lines changed

16 files changed

+755
-440
lines changed

collector/extension/solarwindsapmsettingsextension/config.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import (
77
"time"
88

99
"go.opentelemetry.io/collector/component"
10+
"go.opentelemetry.io/collector/config/configgrpc"
1011
)
1112

1213
type Config struct {
13-
Endpoint string `mapstructure:"endpoint"`
14-
Key string `mapstructure:"key"`
15-
Interval time.Duration `mapstructure:"interval"`
14+
ClientConfig configgrpc.ClientConfig `mapstructure:",squash"`
15+
Key string `mapstructure:"key"`
16+
Interval time.Duration `mapstructure:"interval"`
1617
}
1718

1819
const (
@@ -24,17 +25,19 @@ const (
2425

2526
func createDefaultConfig() component.Config {
2627
return &Config{
27-
Endpoint: DefaultEndpoint,
28+
ClientConfig: configgrpc.ClientConfig{
29+
Endpoint: DefaultEndpoint,
30+
},
2831
Interval: DefaultInterval,
2932
}
3033
}
3134

3235
func (cfg *Config) Validate() error {
3336
// Endpoint
34-
matched, _ := regexp.MatchString(`apm.collector.[a-z]{2,3}-[0-9]{2}.[a-z\-]*.solarwinds.com:443`, cfg.Endpoint)
37+
matched, _ := regexp.MatchString(`apm.collector.[a-z]{2,3}-[0-9]{2}.[a-z\-]*.solarwinds.com:443`, cfg.ClientConfig.Endpoint)
3538
if !matched {
3639
// Replaced by the default
37-
cfg.Endpoint = DefaultEndpoint
40+
cfg.ClientConfig.Endpoint = DefaultEndpoint
3841
}
3942
// Key
4043
keyArr := strings.Split(cfg.Key, ":")
@@ -58,10 +61,10 @@ func (cfg *Config) Validate() error {
5861
}
5962

6063
func resolveServiceNameBestEffort() string {
61-
if name, ok := os.LookupEnv("OTEL_SERVICE_NAME"); ok && len(name) > 0 {
62-
return name
63-
} else if name, ok := os.LookupEnv("AWS_LAMBDA_FUNCTION_NAME"); ok && len(name) > 0 {
64-
return name
64+
if otelServiceName, otelServiceNameDefined := os.LookupEnv("OTEL_SERVICE_NAME"); otelServiceNameDefined && len(otelServiceName) > 0 {
65+
return otelServiceName
66+
} else if awsLambdaFunctionName, awsLambdaFunctionNameDefined := os.LookupEnv("AWS_LAMBDA_FUNCTION_NAME"); awsLambdaFunctionNameDefined && len(awsLambdaFunctionName) > 0 {
67+
return awsLambdaFunctionName
6568
}
6669
return ""
6770
}

collector/extension/solarwindsapmsettingsextension/config_test.go

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111
"go.opentelemetry.io/collector/component"
12+
"go.opentelemetry.io/collector/config/configgrpc"
1213
"go.opentelemetry.io/collector/confmap/confmaptest"
1314

1415
"github.com/open-telemetry/opentelemetry-lambda/collector/extension/solarwindsapmsettingsextension/internal/metadata"
@@ -28,183 +29,229 @@ func TestLoadConfig(t *testing.T) {
2829
{
2930
id: component.NewIDWithName(metadata.Type, "1"),
3031
expected: &Config{
31-
Endpoint: "apm.collector.na-01.cloud.solarwinds.com:443",
32+
ClientConfig: configgrpc.ClientConfig{
33+
Endpoint: "apm.collector.na-01.cloud.solarwinds.com:443",
34+
},
3235
Key: "something:name",
3336
Interval: time.Duration(10) * time.Second,
3437
},
3538
},
3639
{
3740
id: component.NewIDWithName(metadata.Type, "2"),
3841
expected: &Config{
39-
Endpoint: "apm.collector.na-02.cloud.solarwinds.com:443",
42+
ClientConfig: configgrpc.ClientConfig{
43+
Endpoint: "apm.collector.na-02.cloud.solarwinds.com:443",
44+
},
4045
Key: "something:name",
4146
Interval: time.Duration(10) * time.Second,
4247
},
4348
},
4449
{
4550
id: component.NewIDWithName(metadata.Type, "3"),
4651
expected: &Config{
47-
Endpoint: "apm.collector.eu-01.cloud.solarwinds.com:443",
52+
ClientConfig: configgrpc.ClientConfig{
53+
Endpoint: "apm.collector.eu-01.cloud.solarwinds.com:443",
54+
},
4855
Key: "something:name",
4956
Interval: time.Duration(10) * time.Second,
5057
},
5158
},
5259
{
5360
id: component.NewIDWithName(metadata.Type, "4"),
5461
expected: &Config{
55-
Endpoint: "apm.collector.apj-01.cloud.solarwinds.com:443",
62+
ClientConfig: configgrpc.ClientConfig{
63+
Endpoint: "apm.collector.apj-01.cloud.solarwinds.com:443",
64+
},
5665
Key: "something:name",
5766
Interval: time.Duration(10) * time.Second,
5867
},
5968
},
6069
{
6170
id: component.NewIDWithName(metadata.Type, "5"),
6271
expected: &Config{
63-
Endpoint: "apm.collector.na-01.st-ssp.solarwinds.com:443",
72+
ClientConfig: configgrpc.ClientConfig{
73+
Endpoint: "apm.collector.na-01.st-ssp.solarwinds.com:443",
74+
},
6475
Key: "something:name",
6576
Interval: time.Duration(10) * time.Second,
6677
},
6778
},
6879
{
6980
id: component.NewIDWithName(metadata.Type, "6"),
7081
expected: &Config{
71-
Endpoint: "apm.collector.na-01.dev-ssp.solarwinds.com:443",
82+
ClientConfig: configgrpc.ClientConfig{
83+
Endpoint: "apm.collector.na-01.dev-ssp.solarwinds.com:443",
84+
},
7285
Key: "something:name",
7386
Interval: time.Duration(10) * time.Second,
7487
},
7588
},
7689
{
7790
id: component.NewIDWithName(metadata.Type, "7"),
7891
expected: &Config{
79-
Endpoint: DefaultEndpoint,
92+
ClientConfig: configgrpc.ClientConfig{
93+
Endpoint: DefaultEndpoint,
94+
},
8095
Key: "something:name",
8196
Interval: time.Duration(10) * time.Second,
8297
},
8398
},
8499
{
85100
id: component.NewIDWithName(metadata.Type, "8"),
86101
expected: &Config{
87-
Endpoint: DefaultEndpoint,
102+
ClientConfig: configgrpc.ClientConfig{
103+
Endpoint: DefaultEndpoint,
104+
},
88105
Key: "something:name",
89106
Interval: time.Duration(10) * time.Second,
90107
},
91108
},
92109
{
93110
id: component.NewIDWithName(metadata.Type, "9"),
94111
expected: &Config{
95-
Endpoint: DefaultEndpoint,
112+
ClientConfig: configgrpc.ClientConfig{
113+
Endpoint: DefaultEndpoint,
114+
},
96115
Key: "something:name",
97116
Interval: time.Duration(10) * time.Second,
98117
},
99118
},
100119
{
101120
id: component.NewIDWithName(metadata.Type, "10"),
102121
expected: &Config{
103-
Endpoint: DefaultEndpoint,
122+
ClientConfig: configgrpc.ClientConfig{
123+
Endpoint: DefaultEndpoint,
124+
},
104125
Key: "something:name",
105126
Interval: time.Duration(10) * time.Second,
106127
},
107128
},
108129
{
109130
id: component.NewIDWithName(metadata.Type, "11"),
110131
expected: &Config{
111-
Endpoint: DefaultEndpoint,
132+
ClientConfig: configgrpc.ClientConfig{
133+
Endpoint: DefaultEndpoint,
134+
},
112135
Key: "something:name",
113136
Interval: time.Duration(10) * time.Second,
114137
},
115138
},
116139
{
117140
id: component.NewIDWithName(metadata.Type, "12"),
118141
expected: &Config{
119-
Endpoint: DefaultEndpoint,
142+
ClientConfig: configgrpc.ClientConfig{
143+
Endpoint: DefaultEndpoint,
144+
},
120145
Key: "something:name",
121146
Interval: time.Duration(10) * time.Second,
122147
},
123148
},
124149
{
125150
id: component.NewIDWithName(metadata.Type, "13"),
126151
expected: &Config{
127-
Endpoint: DefaultEndpoint,
152+
ClientConfig: configgrpc.ClientConfig{
153+
Endpoint: DefaultEndpoint,
154+
},
128155
Key: "something:name",
129156
Interval: time.Duration(10) * time.Second,
130157
},
131158
},
132159
{
133160
id: component.NewIDWithName(metadata.Type, "14"),
134161
expected: &Config{
135-
Endpoint: DefaultEndpoint,
162+
ClientConfig: configgrpc.ClientConfig{
163+
Endpoint: DefaultEndpoint,
164+
},
136165
Key: "something:name",
137166
Interval: time.Duration(10) * time.Second,
138167
},
139168
},
140169
{
141170
id: component.NewIDWithName(metadata.Type, "15"),
142171
expected: &Config{
143-
Endpoint: DefaultEndpoint,
172+
ClientConfig: configgrpc.ClientConfig{
173+
Endpoint: DefaultEndpoint,
174+
},
144175
Key: "something:name",
145176
Interval: time.Duration(10) * time.Second,
146177
},
147178
},
148179
{
149180
id: component.NewIDWithName(metadata.Type, "16"),
150181
expected: &Config{
151-
Endpoint: DefaultEndpoint,
182+
ClientConfig: configgrpc.ClientConfig{
183+
Endpoint: DefaultEndpoint,
184+
},
152185
Key: "",
153186
Interval: time.Duration(10) * time.Second,
154187
},
155188
},
156189
{
157190
id: component.NewIDWithName(metadata.Type, "17"),
158191
expected: &Config{
159-
Endpoint: DefaultEndpoint,
192+
ClientConfig: configgrpc.ClientConfig{
193+
Endpoint: DefaultEndpoint,
194+
},
160195
Key: ":",
161196
Interval: time.Duration(10) * time.Second,
162197
},
163198
},
164199
{
165200
id: component.NewIDWithName(metadata.Type, "18"),
166201
expected: &Config{
167-
Endpoint: DefaultEndpoint,
202+
ClientConfig: configgrpc.ClientConfig{
203+
Endpoint: DefaultEndpoint,
204+
},
168205
Key: "::",
169206
Interval: time.Duration(10) * time.Second,
170207
},
171208
},
172209
{
173210
id: component.NewIDWithName(metadata.Type, "19"),
174211
expected: &Config{
175-
Endpoint: DefaultEndpoint,
212+
ClientConfig: configgrpc.ClientConfig{
213+
Endpoint: DefaultEndpoint,
214+
},
176215
Key: ":name",
177216
Interval: time.Duration(10) * time.Second,
178217
},
179218
},
180219
{
181220
id: component.NewIDWithName(metadata.Type, "20"),
182221
expected: &Config{
183-
Endpoint: DefaultEndpoint,
222+
ClientConfig: configgrpc.ClientConfig{
223+
Endpoint: DefaultEndpoint,
224+
},
184225
Key: "token:",
185226
Interval: time.Duration(10) * time.Second,
186227
},
187228
},
188229
{
189230
id: component.NewIDWithName(metadata.Type, "21"),
190231
expected: &Config{
191-
Endpoint: DefaultEndpoint,
232+
ClientConfig: configgrpc.ClientConfig{
233+
Endpoint: DefaultEndpoint,
234+
},
192235
Key: "token:name",
193236
Interval: MinimumInterval,
194237
},
195238
},
196239
{
197240
id: component.NewIDWithName(metadata.Type, "22"),
198241
expected: &Config{
199-
Endpoint: DefaultEndpoint,
242+
ClientConfig: configgrpc.ClientConfig{
243+
Endpoint: DefaultEndpoint,
244+
},
200245
Key: "token:name",
201246
Interval: MaximumInterval,
202247
},
203248
},
204249
{
205250
id: component.NewIDWithName(metadata.Type, "23"),
206251
expected: &Config{
207-
Endpoint: DefaultEndpoint,
252+
ClientConfig: configgrpc.ClientConfig{
253+
Endpoint: DefaultEndpoint,
254+
},
208255
Key: "token:name",
209256
Interval: MinimumInterval,
210257
},
@@ -218,7 +265,7 @@ func TestLoadConfig(t *testing.T) {
218265
cfg := factory.CreateDefaultConfig()
219266
sub, err := cm.Sub(tt.id.String())
220267
require.NoError(t, err)
221-
require.NoError(t, component.UnmarshalConfig(sub, cfg))
268+
require.NoError(t, sub.Unmarshal(cfg))
222269
assert.NoError(t, component.ValidateConfig(cfg))
223270
assert.Equal(t, tt.expected, cfg)
224271
})

0 commit comments

Comments
 (0)