From 2ca93394e522182e025f13e1bae948310428279e Mon Sep 17 00:00:00 2001 From: sakulali Date: Wed, 20 Sep 2023 23:36:37 +0800 Subject: [PATCH 1/6] [receiver/pulsar] do not expose method --- .chloggen/pulsarreceiver-checkapi-26304.yaml | 27 ++++++++++++++++++++ cmd/checkapi/allowlist.txt | 1 - receiver/pulsarreceiver/factory.go | 12 ++++----- 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100755 .chloggen/pulsarreceiver-checkapi-26304.yaml diff --git a/.chloggen/pulsarreceiver-checkapi-26304.yaml b/.chloggen/pulsarreceiver-checkapi-26304.yaml new file mode 100755 index 000000000000..bc3234b8ec6c --- /dev/null +++ b/.chloggen/pulsarreceiver-checkapi-26304.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pulsarreceiver + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Do not export the function `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers` and pass checkapi. + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [26304] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] \ No newline at end of file diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index 5e977a91b43d..387b3ad07648 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -23,5 +23,4 @@ receiver/journaldreceiver receiver/kafkareceiver receiver/mongodbatlasreceiver receiver/podmanreceiver -receiver/pulsarreceiver receiver/windowseventlogreceiver diff --git a/receiver/pulsarreceiver/factory.go b/receiver/pulsarreceiver/factory.go index 75f2c3758d30..e084d6473a31 100644 --- a/receiver/pulsarreceiver/factory.go +++ b/receiver/pulsarreceiver/factory.go @@ -26,8 +26,8 @@ const ( // FactoryOption applies changes to PulsarExporterFactory. type FactoryOption func(factory *pulsarReceiverFactory) -// WithTracesUnmarshalers adds Unmarshalers. -func WithTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { +// withTracesUnmarshalers adds Unmarshalers. +func withTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { return func(factory *pulsarReceiverFactory) { for _, unmarshaler := range tracesUnmarshalers { factory.tracesUnmarshalers[unmarshaler.Encoding()] = unmarshaler @@ -35,8 +35,8 @@ func WithTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOpti } } -// WithMetricsUnmarshalers adds MetricsUnmarshalers. -func WithMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption { +// withMetricsUnmarshalers adds MetricsUnmarshalers. +func withMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption { return func(factory *pulsarReceiverFactory) { for _, unmarshaler := range metricsUnmarshalers { factory.metricsUnmarshalers[unmarshaler.Encoding()] = unmarshaler @@ -44,8 +44,8 @@ func WithMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryO } } -// WithLogsUnmarshalers adds LogsUnmarshalers. -func WithLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption { +// withLogsUnmarshalers adds LogsUnmarshalers. +func withLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption { return func(factory *pulsarReceiverFactory) { for _, unmarshaler := range logsUnmarshalers { factory.logsUnmarshalers[unmarshaler.Encoding()] = unmarshaler From 0e30c9916f1e1cac1beae5f712c22519fb24212b Mon Sep 17 00:00:00 2001 From: sakulali Date: Thu, 21 Sep 2023 00:30:26 +0800 Subject: [PATCH 2/6] fix: remove unused method --- receiver/pulsarreceiver/factory.go | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/receiver/pulsarreceiver/factory.go b/receiver/pulsarreceiver/factory.go index e084d6473a31..de363685aa6b 100644 --- a/receiver/pulsarreceiver/factory.go +++ b/receiver/pulsarreceiver/factory.go @@ -26,33 +26,6 @@ const ( // FactoryOption applies changes to PulsarExporterFactory. type FactoryOption func(factory *pulsarReceiverFactory) -// withTracesUnmarshalers adds Unmarshalers. -func withTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { - return func(factory *pulsarReceiverFactory) { - for _, unmarshaler := range tracesUnmarshalers { - factory.tracesUnmarshalers[unmarshaler.Encoding()] = unmarshaler - } - } -} - -// withMetricsUnmarshalers adds MetricsUnmarshalers. -func withMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption { - return func(factory *pulsarReceiverFactory) { - for _, unmarshaler := range metricsUnmarshalers { - factory.metricsUnmarshalers[unmarshaler.Encoding()] = unmarshaler - } - } -} - -// withLogsUnmarshalers adds LogsUnmarshalers. -func withLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption { - return func(factory *pulsarReceiverFactory) { - for _, unmarshaler := range logsUnmarshalers { - factory.logsUnmarshalers[unmarshaler.Encoding()] = unmarshaler - } - } -} - // NewFactory creates Pulsar receiver factory. func NewFactory(options ...FactoryOption) receiver.Factory { From bdde4dc3610b77c815f9c8966361f4ffbd987c4f Mon Sep 17 00:00:00 2001 From: sakulali Date: Thu, 21 Sep 2023 13:27:22 +0800 Subject: [PATCH 3/6] chore: fix the wrong note of chlog file --- .chloggen/pulsarreceiver-checkapi-26304.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/pulsarreceiver-checkapi-26304.yaml b/.chloggen/pulsarreceiver-checkapi-26304.yaml index bc3234b8ec6c..71242235a8c2 100755 --- a/.chloggen/pulsarreceiver-checkapi-26304.yaml +++ b/.chloggen/pulsarreceiver-checkapi-26304.yaml @@ -7,7 +7,7 @@ change_type: breaking component: pulsarreceiver # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Do not export the function `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers` and pass checkapi. +note: Remove the unused functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers` and pass checkapi. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [26304] From 18e506c238176aab58a249a73880997bb4e86f57 Mon Sep 17 00:00:00 2001 From: sakulali Date: Thu, 21 Sep 2023 15:44:31 +0800 Subject: [PATCH 4/6] fix: reserve `withTracesUnmarshalers` and other for custom factory option --- .chloggen/pulsarreceiver-checkapi-26304.yaml | 2 +- receiver/pulsarreceiver/factory.go | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.chloggen/pulsarreceiver-checkapi-26304.yaml b/.chloggen/pulsarreceiver-checkapi-26304.yaml index 71242235a8c2..6c2522c6c6df 100755 --- a/.chloggen/pulsarreceiver-checkapi-26304.yaml +++ b/.chloggen/pulsarreceiver-checkapi-26304.yaml @@ -7,7 +7,7 @@ change_type: breaking component: pulsarreceiver # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Remove the unused functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers` and pass checkapi. +note: Do not export the functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers` and `WithTracesUnmarshalers`. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [26304] diff --git a/receiver/pulsarreceiver/factory.go b/receiver/pulsarreceiver/factory.go index de363685aa6b..e084d6473a31 100644 --- a/receiver/pulsarreceiver/factory.go +++ b/receiver/pulsarreceiver/factory.go @@ -26,6 +26,33 @@ const ( // FactoryOption applies changes to PulsarExporterFactory. type FactoryOption func(factory *pulsarReceiverFactory) +// withTracesUnmarshalers adds Unmarshalers. +func withTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { + return func(factory *pulsarReceiverFactory) { + for _, unmarshaler := range tracesUnmarshalers { + factory.tracesUnmarshalers[unmarshaler.Encoding()] = unmarshaler + } + } +} + +// withMetricsUnmarshalers adds MetricsUnmarshalers. +func withMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption { + return func(factory *pulsarReceiverFactory) { + for _, unmarshaler := range metricsUnmarshalers { + factory.metricsUnmarshalers[unmarshaler.Encoding()] = unmarshaler + } + } +} + +// withLogsUnmarshalers adds LogsUnmarshalers. +func withLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption { + return func(factory *pulsarReceiverFactory) { + for _, unmarshaler := range logsUnmarshalers { + factory.logsUnmarshalers[unmarshaler.Encoding()] = unmarshaler + } + } +} + // NewFactory creates Pulsar receiver factory. func NewFactory(options ...FactoryOption) receiver.Factory { From d5b1e3b4f9530dc42011dcfcd5ec6c9d5b35d308 Mon Sep 17 00:00:00 2001 From: sakulali Date: Thu, 21 Sep 2023 16:42:23 +0800 Subject: [PATCH 5/6] fix: add tests for `withTracesUnmarshalers` and other --- receiver/pulsarreceiver/factory_test.go | 93 +++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/receiver/pulsarreceiver/factory_test.go b/receiver/pulsarreceiver/factory_test.go index 5ba17a5bb21c..cffcd4840d87 100644 --- a/receiver/pulsarreceiver/factory_test.go +++ b/receiver/pulsarreceiver/factory_test.go @@ -9,6 +9,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/plog" + "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/collector/pdata/ptrace" "go.opentelemetry.io/collector/receiver/receivertest" ) @@ -53,6 +56,25 @@ func Test_CreateTraceReceiver(t *testing.T) { assert.NotNil(t, recv) } +func TestWithTracesUnmarshalers(t *testing.T) { + unmarshaler := &customTracesUnmarshaler{} + f := NewFactory(withTracesUnmarshalers(unmarshaler)) + cfg := createDefaultConfig().(*Config) + + t.Run("custom_encoding", func(t *testing.T) { + cfg.Encoding = unmarshaler.Encoding() + receiver, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + require.NotNil(t, receiver) + }) + t.Run("default_encoding", func(t *testing.T) { + cfg.Encoding = defaultEncoding + receiver, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + assert.NotNil(t, receiver) + }) +} + // metrics func TestCreateMetricsReceiver_err_addr(t *testing.T) { cfg := createDefaultConfig().(*Config) @@ -83,6 +105,25 @@ func Test_CreateMetricsReceiver(t *testing.T) { assert.NotNil(t, recv) } +func TestWithMetricsUnmarshalers(t *testing.T) { + unmarshaler := &customMetricsUnmarshaler{} + f := NewFactory(withMetricsUnmarshalers(unmarshaler)) + cfg := createDefaultConfig().(*Config) + + t.Run("custom_encoding", func(t *testing.T) { + cfg.Encoding = unmarshaler.Encoding() + receiver, err := f.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + require.NotNil(t, receiver) + }) + t.Run("default_encoding", func(t *testing.T) { + cfg.Encoding = defaultEncoding + receiver, err := f.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + assert.NotNil(t, receiver) + }) +} + // logs func TestCreateLogsReceiver_err_addr(t *testing.T) { cfg := createDefaultConfig().(*Config) @@ -113,3 +154,55 @@ func Test_CreateLogsReceiver(t *testing.T) { require.NoError(t, err) assert.NotNil(t, recv) } + +func TestWithLogsUnmarshalers(t *testing.T) { + unmarshaler := &customLogsUnmarshaler{} + f := NewFactory(withLogsUnmarshalers(unmarshaler)) + cfg := createDefaultConfig().(*Config) + + t.Run("custom_encoding", func(t *testing.T) { + cfg.Encoding = unmarshaler.Encoding() + exporter, err := f.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + require.NotNil(t, exporter) + }) + t.Run("default_encoding", func(t *testing.T) { + cfg.Encoding = defaultEncoding + exporter, err := f.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil) + require.NoError(t, err) + assert.NotNil(t, exporter) + }) +} + +type customTracesUnmarshaler struct { +} + +type customMetricsUnmarshaler struct { +} + +type customLogsUnmarshaler struct { +} + +func (c customTracesUnmarshaler) Unmarshal([]byte) (ptrace.Traces, error) { + panic("implement me") +} + +func (c customTracesUnmarshaler) Encoding() string { + return "custom" +} + +func (c customMetricsUnmarshaler) Unmarshal([]byte) (pmetric.Metrics, error) { + panic("implement me") +} + +func (c customMetricsUnmarshaler) Encoding() string { + return "custom" +} + +func (c customLogsUnmarshaler) Unmarshal([]byte) (plog.Logs, error) { + panic("implement me") +} + +func (c customLogsUnmarshaler) Encoding() string { + return "custom" +} From 73cfe45e8821efec580bd04f43c9be761407d9e8 Mon Sep 17 00:00:00 2001 From: sakulali Date: Thu, 21 Sep 2023 16:46:42 +0800 Subject: [PATCH 6/6] chore: fix note in chlog file --- .chloggen/pulsarreceiver-checkapi-26304.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/pulsarreceiver-checkapi-26304.yaml b/.chloggen/pulsarreceiver-checkapi-26304.yaml index 6c2522c6c6df..2c0bf49c7ec7 100755 --- a/.chloggen/pulsarreceiver-checkapi-26304.yaml +++ b/.chloggen/pulsarreceiver-checkapi-26304.yaml @@ -7,7 +7,7 @@ change_type: breaking component: pulsarreceiver # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Do not export the functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers` and `WithTracesUnmarshalers`. +note: Do not export the functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers`, add tests and pass checkapi. # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [26304]