From cfdb021c28eb4a5003bd57e0c0199057b06c2e6d Mon Sep 17 00:00:00 2001 From: Jared Tan Date: Tue, 12 Sep 2023 10:51:14 +0800 Subject: [PATCH 1/2] unexport WithLogsUnmarshalers --- .chloggen/kafkareceiver-checkapi.yaml | 27 +++++++++++++++++++ cmd/checkapi/allowlist.txt | 1 - receiver/kafkareceiver/factory.go | 14 +++++----- receiver/kafkareceiver/factory_test.go | 6 ++--- receiver/kafkareceiver/kafka_receiver_test.go | 24 ++++++++--------- receiver/kafkareceiver/metrics.go | 4 +-- receiver/kafkareceiver/metrics_test.go | 2 +- 7 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 .chloggen/kafkareceiver-checkapi.yaml diff --git a/.chloggen/kafkareceiver-checkapi.yaml b/.chloggen/kafkareceiver-checkapi.yaml new file mode 100644 index 000000000000..98b8e7df1a3c --- /dev/null +++ b/.chloggen/kafkareceiver-checkapi.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: kafkareceiver + +# 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 `WithTracesUnmarshalers`, `WithMetricsUnmarshalers`, `WithLogsUnmarshalers` + +# 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] diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index 478e5e2d9166..2cae2175ce00 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -26,7 +26,6 @@ receiver/dockerstatsreceiver receiver/fluentforwardreceiver receiver/jaegerreceiver receiver/journaldreceiver -receiver/kafkareceiver receiver/mongodbatlasreceiver receiver/mongodbreceiver receiver/mysqlreceiver diff --git a/receiver/kafkareceiver/factory.go b/receiver/kafkareceiver/factory.go index 00ff43e4fa98..1e511e0a07b5 100644 --- a/receiver/kafkareceiver/factory.go +++ b/receiver/kafkareceiver/factory.go @@ -40,8 +40,8 @@ const ( // FactoryOption applies changes to kafkaExporterFactory. type FactoryOption func(factory *kafkaReceiverFactory) -// WithTracesUnmarshalers adds Unmarshalers. -func WithTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { +// withTracesUnmarshalers adds Unmarshalers. +func withTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption { return func(factory *kafkaReceiverFactory) { for _, unmarshaler := range tracesUnmarshalers { factory.tracesUnmarshalers[unmarshaler.Encoding()] = unmarshaler @@ -49,8 +49,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 *kafkaReceiverFactory) { for _, unmarshaler := range metricsUnmarshalers { factory.metricsUnmarshalers[unmarshaler.Encoding()] = unmarshaler @@ -58,8 +58,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 *kafkaReceiverFactory) { for _, unmarshaler := range logsUnmarshalers { factory.logsUnmarshalers[unmarshaler.Encoding()] = unmarshaler @@ -69,7 +69,7 @@ func WithLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption { // NewFactory creates Kafka receiver factory. func NewFactory(options ...FactoryOption) receiver.Factory { - _ = view.Register(MetricViews()...) + _ = view.Register(metricViews()...) f := &kafkaReceiverFactory{ tracesUnmarshalers: defaultTracesUnmarshalers(), diff --git a/receiver/kafkareceiver/factory_test.go b/receiver/kafkareceiver/factory_test.go index 6df28bdef17a..8dbcff101f96 100644 --- a/receiver/kafkareceiver/factory_test.go +++ b/receiver/kafkareceiver/factory_test.go @@ -51,7 +51,7 @@ func TestCreateTracesReceiver_error(t *testing.T) { func TestWithTracesUnmarshalers(t *testing.T) { unmarshaler := &customTracesUnmarshaler{} - f := NewFactory(WithTracesUnmarshalers(unmarshaler)) + f := NewFactory(withTracesUnmarshalers(unmarshaler)) cfg := createDefaultConfig().(*Config) // disable contacting broker cfg.Metadata.Full = false @@ -95,7 +95,7 @@ func TestCreateMetricsReceiver_error(t *testing.T) { func TestWithMetricsUnmarshalers(t *testing.T) { unmarshaler := &customMetricsUnmarshaler{} - f := NewFactory(WithMetricsUnmarshalers(unmarshaler)) + f := NewFactory(withMetricsUnmarshalers(unmarshaler)) cfg := createDefaultConfig().(*Config) // disable contacting broker cfg.Metadata.Full = false @@ -139,7 +139,7 @@ func TestCreateLogsReceiver_error(t *testing.T) { func TestWithLogsUnmarshalers(t *testing.T) { unmarshaler := &customLogsUnmarshaler{} - f := NewFactory(WithLogsUnmarshalers(unmarshaler)) + f := NewFactory(withLogsUnmarshalers(unmarshaler)) cfg := createDefaultConfig().(*Config) // disable contacting broker cfg.Metadata.Full = false diff --git a/receiver/kafkareceiver/kafka_receiver_test.go b/receiver/kafkareceiver/kafka_receiver_test.go index 26c388cca71e..6314852b8d7b 100644 --- a/receiver/kafkareceiver/kafka_receiver_test.go +++ b/receiver/kafkareceiver/kafka_receiver_test.go @@ -131,8 +131,8 @@ func TestTracesReceiver_error(t *testing.T) { } func TestTracesConsumerGroupHandler(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) @@ -180,8 +180,8 @@ func TestTracesConsumerGroupHandler(t *testing.T) { } func TestTracesConsumerGroupHandler_session_done(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) @@ -388,8 +388,8 @@ func TestMetricsReceiver_error(t *testing.T) { } func TestMetricsConsumerGroupHandler(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) @@ -437,8 +437,8 @@ func TestMetricsConsumerGroupHandler(t *testing.T) { } func TestMetricsConsumerGroupHandler_session_done(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) @@ -643,8 +643,8 @@ func TestLogsReceiver_error(t *testing.T) { } func TestLogsConsumerGroupHandler(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) @@ -692,8 +692,8 @@ func TestLogsConsumerGroupHandler(t *testing.T) { } func TestLogsConsumerGroupHandler_session_done(t *testing.T) { - view.Unregister(MetricViews()...) - views := MetricViews() + view.Unregister(metricViews()...) + views := metricViews() require.NoError(t, view.Register(views...)) defer view.Unregister(views...) diff --git a/receiver/kafkareceiver/metrics.go b/receiver/kafkareceiver/metrics.go index f197180713a9..d9053533bc70 100644 --- a/receiver/kafkareceiver/metrics.go +++ b/receiver/kafkareceiver/metrics.go @@ -20,8 +20,8 @@ var ( statPartitionClose = stats.Int64("kafka_receiver_partition_close", "Number of finished partitions", stats.UnitDimensionless) ) -// MetricViews return metric views for Kafka receiver. -func MetricViews() []*view.View { +// metricViews return metric views for Kafka receiver. +func metricViews() []*view.View { tagKeys := []tag.Key{tagInstanceName} countMessages := &view.View{ diff --git a/receiver/kafkareceiver/metrics_test.go b/receiver/kafkareceiver/metrics_test.go index b5585a2d63ad..2b9f7d369661 100644 --- a/receiver/kafkareceiver/metrics_test.go +++ b/receiver/kafkareceiver/metrics_test.go @@ -10,7 +10,7 @@ import ( ) func TestMetrics(t *testing.T) { - metricViews := MetricViews() + metricViews := metricViews() viewNames := []string{ "kafka_receiver_messages", "kafka_receiver_current_offset", From bb6912cb70916beccb22d564b3d15e893363448c Mon Sep 17 00:00:00 2001 From: Jared Tan Date: Sun, 5 Nov 2023 00:32:28 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: sakulali --- cmd/checkapi/allowlist.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index da65fb3fa4e8..83ced2b3d09c 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -6,5 +6,4 @@ receiver/carbonreceiver receiver/collectdreceiver receiver/dockerstatsreceiver receiver/journaldreceiver -receiver/kafkareceiver receiver/windowseventlogreceiver \ No newline at end of file