Skip to content

Commit bae6c10

Browse files
[chore] follow the contract of createDefaultConfig (#40541)
This will help when we scan for the Config struct with checkapi. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 1ee5b68 commit bae6c10

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

receiver/kafkareceiver/factory.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@ const (
2929
func NewFactory() receiver.Factory {
3030
return receiver.NewFactory(
3131
metadata.Type,
32-
func() component.Config {
33-
return createDefaultConfig()
34-
},
32+
createDefaultConfig,
3533
receiver.WithTraces(createTracesReceiver, metadata.TracesStability),
3634
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
3735
receiver.WithLogs(createLogsReceiver, metadata.LogsStability),
3836
)
3937
}
4038

41-
func createDefaultConfig() *Config {
39+
func createDefaultConfig() component.Config {
4240
return &Config{
4341
ClientConfig: configkafka.NewDefaultClientConfig(),
4442
ConsumerConfig: configkafka.NewDefaultConsumerConfig(),

receiver/kafkareceiver/factory_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
)
1818

1919
func TestCreateDefaultConfig(t *testing.T) {
20-
cfg := createDefaultConfig()
20+
cfg := createDefaultConfig().(*Config)
2121
assert.NotNil(t, cfg, "failed to create default config")
2222
assert.NoError(t, componenttest.CheckConfigStruct(cfg))
2323
assert.Equal(t, configkafka.NewDefaultClientConfig(), cfg.ClientConfig)
2424
assert.Equal(t, configkafka.NewDefaultConsumerConfig(), cfg.ConsumerConfig)
2525
}
2626

2727
func TestCreateTraces(t *testing.T) {
28-
cfg := createDefaultConfig()
28+
cfg := createDefaultConfig().(*Config)
2929
cfg.Brokers = []string{"invalid:9092"}
3030
cfg.ProtocolVersion = "2.0.0"
3131
r, err := createTracesReceiver(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
@@ -38,7 +38,7 @@ func TestWithTracesUnmarshalers(t *testing.T) {
3838
f := NewFactory()
3939

4040
t.Run("custom_encoding", func(t *testing.T) {
41-
cfg := createDefaultConfig()
41+
cfg := createDefaultConfig().(*Config)
4242
cfg.Traces.Encoding = "custom"
4343
receiver, err := f.CreateTraces(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
4444
tracesConsumer, ok := receiver.(*kafkaConsumer)
@@ -59,7 +59,7 @@ func TestWithTracesUnmarshalers(t *testing.T) {
5959
}
6060

6161
func TestCreateMetrics(t *testing.T) {
62-
cfg := createDefaultConfig()
62+
cfg := createDefaultConfig().(*Config)
6363
cfg.Brokers = []string{"invalid:9092"}
6464
cfg.ProtocolVersion = "2.0.0"
6565
r, err := createMetricsReceiver(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
@@ -72,7 +72,7 @@ func TestWithMetricsUnmarshalers(t *testing.T) {
7272
f := NewFactory()
7373

7474
t.Run("custom_encoding", func(t *testing.T) {
75-
cfg := createDefaultConfig()
75+
cfg := createDefaultConfig().(*Config)
7676
cfg.Metrics.Encoding = "custom"
7777
receiver, err := f.CreateMetrics(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
7878
metricsConsumer, ok := receiver.(*kafkaConsumer)
@@ -93,7 +93,7 @@ func TestWithMetricsUnmarshalers(t *testing.T) {
9393
}
9494

9595
func TestCreateLogs(t *testing.T) {
96-
cfg := createDefaultConfig()
96+
cfg := createDefaultConfig().(*Config)
9797
cfg.Brokers = []string{"invalid:9092"}
9898
cfg.ProtocolVersion = "2.0.0"
9999
r, err := createLogsReceiver(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
@@ -106,7 +106,7 @@ func TestWithLogsUnmarshalers(t *testing.T) {
106106
f := NewFactory()
107107

108108
t.Run("custom_encoding", func(t *testing.T) {
109-
cfg := createDefaultConfig()
109+
cfg := createDefaultConfig().(*Config)
110110
cfg.Logs.Encoding = "custom"
111111
receiver, err := f.CreateLogs(context.Background(), receivertest.NewNopSettings(metadata.Type), cfg, nil)
112112
logsConsumer, ok := receiver.(*kafkaConsumer)

receiver/kafkareceiver/kafka_receiver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ func mustNewFakeCluster(tb testing.TB, opts ...kfake.Opt) (*kgo.Client, *Config)
597597
kafkaClient := mustNewClient(tb, cluster)
598598
tb.Cleanup(func() { deleteConsumerGroups(tb, kafkaClient) })
599599

600-
cfg := createDefaultConfig()
600+
cfg := createDefaultConfig().(*Config)
601601
cfg.ClientConfig = clientConfig
602602
cfg.InitialOffset = "earliest"
603603
cfg.MaxFetchWait = time.Millisecond

0 commit comments

Comments
 (0)