Skip to content

Commit 15495fc

Browse files
authored
[chore] Fix loadbalancing exporter tests (#38305)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fixes loadbalancing exporter tests by setting the right Type on the IDs when creating an OTLP exporter.
1 parent 682fcd6 commit 15495fc

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

Diff for: exporter/loadbalancingexporter/factory.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ func buildExporterConfig(cfg *Config, endpoint string) otlpexporter.Config {
5454
return oCfg
5555
}
5656

57-
func buildExporterSettings(params exporter.Settings, endpoint string) exporter.Settings {
57+
func buildExporterSettings(typ component.Type, params exporter.Settings, endpoint string) exporter.Settings {
5858
// Override child exporter ID to segregate metrics from loadbalancing top level
59-
childName := endpoint
60-
if params.ID.Name() != "" {
61-
childName = fmt.Sprintf("%s_%s", params.ID.Name(), childName)
62-
}
63-
params.ID = component.NewIDWithName(params.ID.Type(), childName)
59+
childName := fmt.Sprintf("%s_%s", params.ID, endpoint)
60+
params.ID = component.NewIDWithName(typ, childName)
6461
// Add "endpoint" attribute to child exporter logger to segregate logs from loadbalancing top level
6562
params.Logger = params.Logger.With(zap.String(zapEndpointKey, endpoint))
6663

Diff for: exporter/loadbalancingexporter/factory_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ func TestBuildExporterSettings(t *testing.T) {
104104
testEndpoint := "the-endpoint"
105105
observedZapCore, observedLogs := observer.New(zap.InfoLevel)
106106
creationParams.Logger = zap.New(observedZapCore)
107+
typ := component.MustNewType("type")
107108

108109
// test
109-
exporterParams := buildExporterSettings(creationParams, testEndpoint)
110+
exporterParams := buildExporterSettings(typ, creationParams, testEndpoint)
110111
exporterParams.Logger.Info("test")
111112

112113
// verify
113114
expectedID := component.NewIDWithName(
114-
creationParams.ID.Type(),
115-
fmt.Sprintf("%s_%s", creationParams.ID.Name(), testEndpoint),
115+
typ,
116+
fmt.Sprintf("%s_%s", creationParams.ID, testEndpoint),
116117
)
117118
assert.Equal(t, expectedID, exporterParams.ID)
118119

Diff for: exporter/loadbalancingexporter/loadbalancer_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func TestAddMissingExporters(t *testing.T) {
276276
fn := func(ctx context.Context, endpoint string) (component.Component, error) {
277277
oCfg := cfg.Protocol.OTLP
278278
oCfg.Endpoint = endpoint
279-
return exporterFactory.CreateTraces(ctx, exportertest.NewNopSettings(metadata.Type), &oCfg)
279+
return exporterFactory.CreateTraces(ctx, exportertest.NewNopSettings(exporterFactory.Type()), &oCfg)
280280
}
281281

282282
p, err := newLoadBalancer(ts.Logger, cfg, fn, tb)

Diff for: exporter/loadbalancingexporter/log_exporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func newLogsExporter(params exporter.Settings, cfg component.Config) (*logExport
4343
exporterFactory := otlpexporter.NewFactory()
4444
cfFunc := func(ctx context.Context, endpoint string) (component.Component, error) {
4545
oCfg := buildExporterConfig(cfg.(*Config), endpoint)
46-
oParams := buildExporterSettings(params, endpoint)
46+
oParams := buildExporterSettings(exporterFactory.Type(), params, endpoint)
4747

4848
return exporterFactory.CreateLogs(ctx, oParams, &oCfg)
4949
}

Diff for: exporter/loadbalancingexporter/metrics_exporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func newMetricsExporter(params exporter.Settings, cfg component.Config) (*metric
4545
exporterFactory := otlpexporter.NewFactory()
4646
cfFunc := func(ctx context.Context, endpoint string) (component.Component, error) {
4747
oCfg := buildExporterConfig(cfg.(*Config), endpoint)
48-
oParams := buildExporterSettings(params, endpoint)
48+
oParams := buildExporterSettings(exporterFactory.Type(), params, endpoint)
4949

5050
return exporterFactory.CreateMetrics(ctx, oParams, &oCfg)
5151
}

Diff for: exporter/loadbalancingexporter/trace_exporter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func newTracesExporter(params exporter.Settings, cfg component.Config) (*traceEx
4747
exporterFactory := otlpexporter.NewFactory()
4848
cfFunc := func(ctx context.Context, endpoint string) (component.Component, error) {
4949
oCfg := buildExporterConfig(cfg.(*Config), endpoint)
50-
oParams := buildExporterSettings(params, endpoint)
50+
oParams := buildExporterSettings(exporterFactory.Type(), params, endpoint)
5151

5252
return exporterFactory.CreateTraces(ctx, oParams, &oCfg)
5353
}

0 commit comments

Comments
 (0)