From 02fccbe3cd4edc48bf4ee2330cbd0eeb95dd951e Mon Sep 17 00:00:00 2001 From: sakulali Date: Tue, 14 Nov 2023 23:23:34 +0800 Subject: [PATCH] [chore][receiver/journald] remove duplicate function NewFactory and pass checkapi (#29005) **Description:** Remove duplicate function NewFactory and pass checkapi since we should only keep one NewFactory. **Link to tracking Issue:** https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/26304 **Testing:** go run cmd/checkapi/main.go . go test for journaldreceiver **Documentation:** Signed-off-by: sakulali --- cmd/checkapi/allowlist.txt | 1 - receiver/journaldreceiver/factory.go | 13 +++++++++++++ receiver/journaldreceiver/factory_test.go | 19 +++++++++++++++++++ receiver/journaldreceiver/journald.go | 4 ++-- .../journaldreceiver/journald_nonlinux.go | 4 ++-- receiver/journaldreceiver/journald_test.go | 4 ++-- 6 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 receiver/journaldreceiver/factory.go create mode 100644 receiver/journaldreceiver/factory_test.go diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index a7b4f0d35baf..b791c2c59028 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -2,5 +2,4 @@ connector/servicegraphconnector extension/encoding extension/observer processor/servicegraphprocessor -receiver/journaldreceiver receiver/kafkareceiver diff --git a/receiver/journaldreceiver/factory.go b/receiver/journaldreceiver/factory.go new file mode 100644 index 000000000000..33077bee2eac --- /dev/null +++ b/receiver/journaldreceiver/factory.go @@ -0,0 +1,13 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package journaldreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/journaldreceiver" + +import ( + "go.opentelemetry.io/collector/receiver" +) + +// NewFactory creates a factory for journald receiver +func NewFactory() receiver.Factory { + return newFactoryAdapter() +} diff --git a/receiver/journaldreceiver/factory_test.go b/receiver/journaldreceiver/factory_test.go new file mode 100644 index 000000000000..8781423b721c --- /dev/null +++ b/receiver/journaldreceiver/factory_test.go @@ -0,0 +1,19 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package journaldreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/journaldreceiver" + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/journaldreceiver/internal/metadata" +) + +func TestNewFactory(t *testing.T) { + t.Run("NewFactoryCorrectType", func(t *testing.T) { + factory := NewFactory() + require.EqualValues(t, metadata.Type, factory.Type()) + }) +} diff --git a/receiver/journaldreceiver/journald.go b/receiver/journaldreceiver/journald.go index f18049bc8d0e..ad92712de219 100644 --- a/receiver/journaldreceiver/journald.go +++ b/receiver/journaldreceiver/journald.go @@ -17,8 +17,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/journaldreceiver/internal/metadata" ) -// NewFactory creates a factory for journald receiver -func NewFactory() receiver.Factory { +// newFactoryAdapter creates a factory for journald receiver +func newFactoryAdapter() receiver.Factory { return adapter.NewFactory(ReceiverType{}, metadata.LogsStability) } diff --git a/receiver/journaldreceiver/journald_nonlinux.go b/receiver/journaldreceiver/journald_nonlinux.go index 6aea6ceae280..dd2f9cad904c 100644 --- a/receiver/journaldreceiver/journald_nonlinux.go +++ b/receiver/journaldreceiver/journald_nonlinux.go @@ -19,8 +19,8 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/journaldreceiver/internal/metadata" ) -// NewFactory creates a dummy factory. -func NewFactory() receiver.Factory { +// newFactoryAdapter creates a dummy factory. +func newFactoryAdapter() receiver.Factory { return receiver.NewFactory( metadata.Type, createDefaultConfig, diff --git a/receiver/journaldreceiver/journald_test.go b/receiver/journaldreceiver/journald_test.go index 2634a7f99778..16cb0f7338ba 100644 --- a/receiver/journaldreceiver/journald_test.go +++ b/receiver/journaldreceiver/journald_test.go @@ -28,7 +28,7 @@ import ( func TestLoadConfig(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - factory := NewFactory() + factory := newFactoryAdapter() cfg := factory.CreateDefaultConfig() sub, err := cm.Sub(component.NewIDWithName(metadata.Type, "").String()) @@ -40,7 +40,7 @@ func TestLoadConfig(t *testing.T) { func TestInputConfigFailure(t *testing.T) { sink := new(consumertest.LogsSink) - factory := NewFactory() + factory := newFactoryAdapter() badCfg := &JournaldConfig{ BaseConfig: adapter.BaseConfig{ Operators: []operator.Config{},