Skip to content

Commit 3e38397

Browse files
Upgrade uses of configgrpc/confighttp (#44591)
#### Description Follow up to open-telemetry/opentelemetry-collector#14190, which introduced an API breaking change: instead of passing a `host component.Host` to `configgrpc` and `confighttp`'s `ToClient` / `ToServer` methods, components should instead pass the result of `host.GetComponents()`. Tests that don't make use of authentication or middleware extensions, as well as custom component hosts which don't support extensions (such as the OpAMP supervisor), can simply pass nil instead of using a no-op host. Replacing `host` by `host.GetComponents()` is fairly straightforward, as long as you don't pass in a `nil` host, which unfortunately a lot of tests do, so I had to fix that as well. This will be merged into the update-otel PR at #44581.
1 parent ab60cf0 commit 3e38397

File tree

118 files changed

+175
-158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+175
-158
lines changed

cmd/opampsupervisor/supervisor/supervisor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ func (s *Supervisor) startHealthCheckServer() error {
764764
healthCheckServerPort := s.config.HealthCheck.Port()
765765
server, err := s.config.HealthCheck.ToServer(
766766
s.runCtx,
767-
nopHost{},
767+
nil,
768768
s.telemetrySettings.TelemetrySettings,
769769
mux,
770770
)

connector/grafanacloudconnector/connector_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88
"time"
99

10+
"go.opentelemetry.io/collector/component/componenttest"
1011
"go.opentelemetry.io/collector/connector/connectortest"
1112
"go.opentelemetry.io/collector/consumer/consumertest"
1213
"go.opentelemetry.io/collector/pdata/ptrace"
@@ -141,7 +142,7 @@ func TestConsumeTraces(t *testing.T) {
141142
assert.NilError(t, err)
142143

143144
ctx := t.Context()
144-
assert.NilError(t, c.Start(ctx, nil))
145+
assert.NilError(t, c.Start(ctx, componenttest.NewNopHost()))
145146
err = c.ConsumeTraces(ctx, tc.input)
146147
assert.NilError(t, err)
147148
assert.NilError(t, c.Shutdown(ctx))

exporter/alertmanagerexporter/alertmanager_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (s *alertmanagerExporter) pushTraces(ctx context.Context, td ptrace.Traces)
189189
}
190190

191191
func (s *alertmanagerExporter) start(ctx context.Context, host component.Host) error {
192-
client, err := s.config.ToClient(ctx, host, s.settings)
192+
client, err := s.config.ToClient(ctx, host.GetExtensions(), s.settings)
193193
if err != nil {
194194
return fmt.Errorf("failed to create HTTP Client: %w", err)
195195
}

exporter/azuremonitorexporter/azuremonitor_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (exporter *azureMonitorExporter) Start(ctx context.Context, host component.
3434
exporter.config.InstrumentationKey = configopaque.String(connectionVars.InstrumentationKey)
3535
exporter.config.ClientConfig.Endpoint = connectionVars.IngestionURL
3636
telemetryConfiguration := appinsights.NewTelemetryConfiguration(connectionVars.InstrumentationKey)
37-
telemetryConfiguration.Client, err = exporter.config.ClientConfig.ToClient(ctx, host, exporter.settings)
37+
telemetryConfiguration.Client, err = exporter.config.ClientConfig.ToClient(ctx, host.GetExtensions(), exporter.settings)
3838
if err != nil {
3939
return err
4040
}

exporter/bmchelixexporter/internal/operationsmanagement/metrics_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type MetricsClient struct {
2626

2727
// NewMetricsClient creates a new MetricsClient
2828
func NewMetricsClient(ctx context.Context, clientConfig confighttp.ClientConfig, apiKey configopaque.String, host component.Host, settings component.TelemetrySettings, logger *zap.Logger) (*MetricsClient, error) {
29-
httpClient, err := clientConfig.ToClient(ctx, host, settings)
29+
httpClient, err := clientConfig.ToClient(ctx, host.GetExtensions(), settings)
3030
if err != nil {
3131
return nil, err
3232
}

exporter/coralogixexporter/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c *TransportConfig) ToHTTPClient(ctx context.Context, host component.Host,
4949
Headers: c.Headers,
5050
Compression: c.Compression,
5151
}
52-
return httpClientConfig.ToClient(ctx, host, settings)
52+
return httpClientConfig.ToClient(ctx, host.GetExtensions(), settings)
5353
}
5454

5555
// Config defines configuration for Coralogix exporter.

exporter/coralogixexporter/signals.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type signalConfigWrapper struct {
3636
}
3737

3838
func (w *signalConfigWrapper) ToClientConn(ctx context.Context, host component.Host, settings component.TelemetrySettings, opts ...configgrpc.ToClientConnOption) (*grpc.ClientConn, error) {
39-
return w.config.ToClientConn(ctx, host, settings, opts...)
39+
return w.config.ToClientConn(ctx, host.GetExtensions(), settings, opts...)
4040
}
4141

4242
func (w *signalConfigWrapper) ToHTTPClient(ctx context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
@@ -146,7 +146,7 @@ func (e *signalExporter) startSignalExporter(ctx context.Context, host component
146146
return err
147147
}
148148
} else {
149-
if e.clientConn, err = transportConfig.ToClientConn(ctx, host, e.settings, configgrpc.WithGrpcDialOption(grpc.WithUserAgent(e.userAgent))); err != nil {
149+
if e.clientConn, err = transportConfig.ToClientConn(ctx, host.GetExtensions(), e.settings, configgrpc.WithGrpcDialOption(grpc.WithUserAgent(e.userAgent))); err != nil {
150150
return err
151151
}
152152
e.callOptions = []grpc.CallOption{

exporter/datadogexporter/factory_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/stretchr/testify/assert"
1717
"github.com/stretchr/testify/require"
1818
"go.opentelemetry.io/collector/component"
19+
"go.opentelemetry.io/collector/component/componenttest"
1920
"go.opentelemetry.io/collector/config/confignet"
2021
"go.opentelemetry.io/collector/config/configretry"
2122
"go.opentelemetry.io/collector/confmap/confmaptest"
@@ -236,7 +237,7 @@ func TestOnlyMetadata(t *testing.T) {
236237
assert.NoError(t, err)
237238
assert.NotNil(t, expMetrics)
238239

239-
err = expTraces.Start(ctx, nil)
240+
err = expTraces.Start(ctx, componenttest.NewNopHost())
240241
assert.NoError(t, err)
241242
defer func() {
242243
assert.NoError(t, expTraces.Shutdown(ctx))
@@ -284,9 +285,9 @@ func TestStopExporters(t *testing.T) {
284285
assert.NoError(t, err)
285286
assert.NotNil(t, expMetrics)
286287

287-
err = expTraces.Start(ctx, nil)
288+
err = expTraces.Start(ctx, componenttest.NewNopHost())
288289
assert.NoError(t, err)
289-
err = expMetrics.Start(ctx, nil)
290+
err = expMetrics.Start(ctx, componenttest.NewNopHost())
290291
assert.NoError(t, err)
291292

292293
finishShutdown := make(chan bool)

exporter/datadogexporter/logs_exporter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/DataDog/datadog-agent/comp/otelcol/otlp/testutil"
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
17+
"go.opentelemetry.io/collector/component/componenttest"
1718
"go.opentelemetry.io/collector/config/confignet"
1819
"go.opentelemetry.io/collector/exporter/exportertest"
1920
"go.opentelemetry.io/collector/pdata/pcommon"
@@ -433,7 +434,7 @@ func TestLogsExporterHostMetadata(t *testing.T) {
433434
assert.NotNil(t, exp)
434435

435436
// Test 2: Verify exporter can start successfully (this initializes metadata infrastructure)
436-
err = exp.Start(t.Context(), nil)
437+
err = exp.Start(t.Context(), componenttest.NewNopHost())
437438
require.NoError(t, err)
438439
defer func() {
439440
assert.NoError(t, exp.Shutdown(t.Context()))
@@ -495,7 +496,7 @@ func TestLogsExporterHostMetadataOnlyMode(t *testing.T) {
495496
require.NoError(t, err)
496497
assert.NotNil(t, exp)
497498

498-
err = exp.Start(t.Context(), nil)
499+
err = exp.Start(t.Context(), componenttest.NewNopHost())
499500
require.NoError(t, err)
500501
defer func() {
501502
assert.NoError(t, exp.Shutdown(t.Context()))

exporter/dorisexporter/exporter_common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func streamLoadRequest(ctx context.Context, cfg *Config, table string, data []by
111111
}
112112

113113
func createDorisHTTPClient(ctx context.Context, cfg *Config, host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
114-
client, err := cfg.ToClient(ctx, host, settings)
114+
client, err := cfg.ToClient(ctx, host.GetExtensions(), settings)
115115
if err != nil {
116116
return nil, err
117117
}

0 commit comments

Comments
 (0)