1
- // Code created by gotmpl. DO NOT MODIFY.
2
- // source: internal/shared/otlp/otlpmetric/oconf/options.go.tmpl
3
-
4
1
// Copyright The OpenTelemetry Authors
5
2
// SPDX-License-Identifier: Apache-2.0
6
3
47
44
// This type is compatible with `http.Transport.Proxy` and can be used to set a custom proxy function to the OTLP HTTP client.
48
45
HTTPTransportProxyFunc func (* http.Request ) (* url.URL , error )
49
46
47
+ // SignalConfig represents signal specific configuration.
50
48
SignalConfig struct {
51
49
Endpoint string
52
50
Insecure bool
65
63
Proxy HTTPTransportProxyFunc
66
64
}
67
65
66
+ // Config represents exporter configuration.
68
67
Config struct {
69
- // Signal specific configurations
70
68
Metrics SignalConfig
71
69
72
70
RetryConfig retry.Config
@@ -79,29 +77,6 @@ type (
79
77
}
80
78
)
81
79
82
- // NewHTTPConfig returns a new Config with all settings applied from opts and
83
- // any unset setting using the default HTTP config values.
84
- func NewHTTPConfig (opts ... HTTPOption ) Config {
85
- cfg := Config {
86
- Metrics : SignalConfig {
87
- Endpoint : fmt .Sprintf ("%s:%d" , DefaultCollectorHost , DefaultCollectorHTTPPort ),
88
- URLPath : DefaultMetricsPath ,
89
- Compression : NoCompression ,
90
- Timeout : DefaultTimeout ,
91
-
92
- TemporalitySelector : metric .DefaultTemporalitySelector ,
93
- AggregationSelector : metric .DefaultAggregationSelector ,
94
- },
95
- RetryConfig : retry .DefaultConfig ,
96
- }
97
- cfg = ApplyHTTPEnvConfigs (cfg )
98
- for _ , opt := range opts {
99
- cfg = opt .ApplyHTTPOption (cfg )
100
- }
101
- cfg .Metrics .URLPath = cleanPath (cfg .Metrics .URLPath , DefaultMetricsPath )
102
- return cfg
103
- }
104
-
105
80
// cleanPath returns a path with all spaces trimmed and all redundancies
106
81
// removed. If urlPath is empty or cleaning it results in an empty string,
107
82
// defaultPath is returned instead.
@@ -164,93 +139,14 @@ func NewGRPCConfig(opts ...GRPCOption) Config {
164
139
return cfg
165
140
}
166
141
167
- type (
168
- // GenericOption applies an option to the HTTP or gRPC driver.
169
- GenericOption interface {
170
- ApplyHTTPOption (Config ) Config
171
- ApplyGRPCOption (Config ) Config
172
-
173
- // A private method to prevent users implementing the
174
- // interface and so future additions to it will not
175
- // violate compatibility.
176
- private ()
177
- }
178
-
179
- // HTTPOption applies an option to the HTTP driver.
180
- HTTPOption interface {
181
- ApplyHTTPOption (Config ) Config
142
+ // GRPCOption applies an option to the gRPC driver.
143
+ type GRPCOption interface {
144
+ ApplyGRPCOption (Config ) Config
182
145
183
- // A private method to prevent users implementing the
184
- // interface and so future additions to it will not
185
- // violate compatibility.
186
- private ()
187
- }
188
-
189
- // GRPCOption applies an option to the gRPC driver.
190
- GRPCOption interface {
191
- ApplyGRPCOption (Config ) Config
192
-
193
- // A private method to prevent users implementing the
194
- // interface and so future additions to it will not
195
- // violate compatibility.
196
- private ()
197
- }
198
- )
199
-
200
- // genericOption is an option that applies the same logic
201
- // for both gRPC and HTTP.
202
- type genericOption struct {
203
- fn func (Config ) Config
204
- }
205
-
206
- func (g * genericOption ) ApplyGRPCOption (cfg Config ) Config {
207
- return g .fn (cfg )
208
- }
209
-
210
- func (g * genericOption ) ApplyHTTPOption (cfg Config ) Config {
211
- return g .fn (cfg )
212
- }
213
-
214
- func (genericOption ) private () {}
215
-
216
- func newGenericOption (fn func (cfg Config ) Config ) GenericOption {
217
- return & genericOption {fn : fn }
218
- }
219
-
220
- // splitOption is an option that applies different logics
221
- // for gRPC and HTTP.
222
- type splitOption struct {
223
- httpFn func (Config ) Config
224
- grpcFn func (Config ) Config
225
- }
226
-
227
- func (g * splitOption ) ApplyGRPCOption (cfg Config ) Config {
228
- return g .grpcFn (cfg )
229
- }
230
-
231
- func (g * splitOption ) ApplyHTTPOption (cfg Config ) Config {
232
- return g .httpFn (cfg )
233
- }
234
-
235
- func (splitOption ) private () {}
236
-
237
- func newSplitOption (httpFn func (cfg Config ) Config , grpcFn func (cfg Config ) Config ) GenericOption {
238
- return & splitOption {httpFn : httpFn , grpcFn : grpcFn }
239
- }
240
-
241
- // httpOption is an option that is only applied to the HTTP driver.
242
- type httpOption struct {
243
- fn func (Config ) Config
244
- }
245
-
246
- func (h * httpOption ) ApplyHTTPOption (cfg Config ) Config {
247
- return h .fn (cfg )
248
- }
249
-
250
- func (httpOption ) private () {}
251
-
252
- func NewHTTPOption (fn func (cfg Config ) Config ) HTTPOption {
253
- return & httpOption {fn : fn }
146
+ // A private method to prevent users implementing the
147
+ // interface and so future additions to it will not
148
+ // violate compatibility.
149
+ private ()
254
150
}
255
151
256
152
// grpcOption is an option that is only applied to the gRPC driver.
@@ -270,15 +166,15 @@ func NewGRPCOption(fn func(cfg Config) Config) GRPCOption {
270
166
271
167
// Generic Options
272
168
273
- func WithEndpoint (endpoint string ) GenericOption {
274
- return newGenericOption (func (cfg Config ) Config {
169
+ func WithEndpoint (endpoint string ) GRPCOption {
170
+ return NewGRPCOption (func (cfg Config ) Config {
275
171
cfg .Metrics .Endpoint = endpoint
276
172
return cfg
277
173
})
278
174
}
279
175
280
- func WithEndpointURL (v string ) GenericOption {
281
- return newGenericOption (func (cfg Config ) Config {
176
+ func WithEndpointURL (v string ) GRPCOption {
177
+ return NewGRPCOption (func (cfg Config ) Config {
282
178
u , err := url .Parse (v )
283
179
if err != nil {
284
180
global .Error (err , "otlpmetric: parse endpoint url" , "url" , v )
@@ -295,81 +191,78 @@ func WithEndpointURL(v string) GenericOption {
295
191
})
296
192
}
297
193
298
- func WithCompression (compression Compression ) GenericOption {
299
- return newGenericOption (func (cfg Config ) Config {
194
+ func WithCompression (compression Compression ) GRPCOption {
195
+ return NewGRPCOption (func (cfg Config ) Config {
300
196
cfg .Metrics .Compression = compression
301
197
return cfg
302
198
})
303
199
}
304
200
305
- func WithURLPath (urlPath string ) GenericOption {
306
- return newGenericOption (func (cfg Config ) Config {
201
+ func WithURLPath (urlPath string ) GRPCOption {
202
+ return NewGRPCOption (func (cfg Config ) Config {
307
203
cfg .Metrics .URLPath = urlPath
308
204
return cfg
309
205
})
310
206
}
311
207
312
- func WithRetry (rc retry.Config ) GenericOption {
313
- return newGenericOption (func (cfg Config ) Config {
208
+ func WithRetry (rc retry.Config ) GRPCOption {
209
+ return NewGRPCOption (func (cfg Config ) Config {
314
210
cfg .RetryConfig = rc
315
211
return cfg
316
212
})
317
213
}
318
214
319
- func WithTLSClientConfig (tlsCfg * tls.Config ) GenericOption {
320
- return newSplitOption (func (cfg Config ) Config {
321
- cfg .Metrics .TLSCfg = tlsCfg .Clone ()
322
- return cfg
323
- }, func (cfg Config ) Config {
215
+ func WithTLSClientConfig (tlsCfg * tls.Config ) GRPCOption {
216
+ return NewGRPCOption (func (cfg Config ) Config {
324
217
cfg .Metrics .GRPCCredentials = credentials .NewTLS (tlsCfg )
325
218
return cfg
326
219
})
327
220
}
328
221
329
- func WithInsecure () GenericOption {
330
- return newGenericOption (func (cfg Config ) Config {
222
+ func WithInsecure () GRPCOption {
223
+ return NewGRPCOption (func (cfg Config ) Config {
331
224
cfg .Metrics .Insecure = true
332
225
return cfg
333
226
})
334
227
}
335
228
336
- func WithSecure () GenericOption {
337
- return newGenericOption (func (cfg Config ) Config {
229
+ func WithSecure () GRPCOption {
230
+ return NewGRPCOption (func (cfg Config ) Config {
338
231
cfg .Metrics .Insecure = false
339
232
return cfg
340
233
})
341
234
}
342
235
343
- func WithHeaders (headers map [string ]string ) GenericOption {
344
- return newGenericOption (func (cfg Config ) Config {
236
+ func WithHeaders (headers map [string ]string ) GRPCOption {
237
+ return NewGRPCOption (func (cfg Config ) Config {
345
238
cfg .Metrics .Headers = headers
346
239
return cfg
347
240
})
348
241
}
349
242
350
- func WithTimeout (duration time.Duration ) GenericOption {
351
- return newGenericOption (func (cfg Config ) Config {
243
+ func WithTimeout (duration time.Duration ) GRPCOption {
244
+ return NewGRPCOption (func (cfg Config ) Config {
352
245
cfg .Metrics .Timeout = duration
353
246
return cfg
354
247
})
355
248
}
356
249
357
- func WithTemporalitySelector (selector metric.TemporalitySelector ) GenericOption {
358
- return newGenericOption (func (cfg Config ) Config {
250
+ func WithTemporalitySelector (selector metric.TemporalitySelector ) GRPCOption {
251
+ return NewGRPCOption (func (cfg Config ) Config {
359
252
cfg .Metrics .TemporalitySelector = selector
360
253
return cfg
361
254
})
362
255
}
363
256
364
- func WithAggregationSelector (selector metric.AggregationSelector ) GenericOption {
365
- return newGenericOption (func (cfg Config ) Config {
257
+ func WithAggregationSelector (selector metric.AggregationSelector ) GRPCOption {
258
+ return NewGRPCOption (func (cfg Config ) Config {
366
259
cfg .Metrics .AggregationSelector = selector
367
260
return cfg
368
261
})
369
262
}
370
263
371
- func WithProxy (pf HTTPTransportProxyFunc ) GenericOption {
372
- return newGenericOption (func (cfg Config ) Config {
264
+ func WithProxy (pf HTTPTransportProxyFunc ) GRPCOption {
265
+ return NewGRPCOption (func (cfg Config ) Config {
373
266
cfg .Metrics .Proxy = pf
374
267
return cfg
375
268
})
0 commit comments