Skip to content

Commit a277117

Browse files
sakulalijmsnll
authored andcommitted
[receiver/pulsar] do not expose method (open-telemetry#27029)
**Description:** Do not export functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers`, add tests for that and pass checkapi **Link to tracking Issue:** open-telemetry#26304 **Testing:** go run cmd/checkapi/main.go . make chlog-validate go test for pulsarreceiver **Documentation:**
1 parent 27497a5 commit a277117

File tree

4 files changed

+126
-7
lines changed

4 files changed

+126
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: breaking
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: pulsarreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Do not export the functions `WithLogsUnmarshalers`, `WithMetricsUnmarshalers`, `WithTracesUnmarshalers`, add tests and pass checkapi.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [26304]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [api]

cmd/checkapi/allowlist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@ receiver/dockerstatsreceiver
88
receiver/journaldreceiver
99
receiver/kafkareceiver
1010
receiver/podmanreceiver
11-
receiver/pulsarreceiver
1211
receiver/windowseventlogreceiver

receiver/pulsarreceiver/factory.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ const (
2626
// FactoryOption applies changes to PulsarExporterFactory.
2727
type FactoryOption func(factory *pulsarReceiverFactory)
2828

29-
// WithTracesUnmarshalers adds Unmarshalers.
30-
func WithTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption {
29+
// withTracesUnmarshalers adds Unmarshalers.
30+
func withTracesUnmarshalers(tracesUnmarshalers ...TracesUnmarshaler) FactoryOption {
3131
return func(factory *pulsarReceiverFactory) {
3232
for _, unmarshaler := range tracesUnmarshalers {
3333
factory.tracesUnmarshalers[unmarshaler.Encoding()] = unmarshaler
3434
}
3535
}
3636
}
3737

38-
// WithMetricsUnmarshalers adds MetricsUnmarshalers.
39-
func WithMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption {
38+
// withMetricsUnmarshalers adds MetricsUnmarshalers.
39+
func withMetricsUnmarshalers(metricsUnmarshalers ...MetricsUnmarshaler) FactoryOption {
4040
return func(factory *pulsarReceiverFactory) {
4141
for _, unmarshaler := range metricsUnmarshalers {
4242
factory.metricsUnmarshalers[unmarshaler.Encoding()] = unmarshaler
4343
}
4444
}
4545
}
4646

47-
// WithLogsUnmarshalers adds LogsUnmarshalers.
48-
func WithLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption {
47+
// withLogsUnmarshalers adds LogsUnmarshalers.
48+
func withLogsUnmarshalers(logsUnmarshalers ...LogsUnmarshaler) FactoryOption {
4949
return func(factory *pulsarReceiverFactory) {
5050
for _, unmarshaler := range logsUnmarshalers {
5151
factory.logsUnmarshalers[unmarshaler.Encoding()] = unmarshaler

receiver/pulsarreceiver/factory_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99

1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12+
"go.opentelemetry.io/collector/pdata/plog"
13+
"go.opentelemetry.io/collector/pdata/pmetric"
14+
"go.opentelemetry.io/collector/pdata/ptrace"
1215
"go.opentelemetry.io/collector/receiver/receivertest"
1316
)
1417

@@ -53,6 +56,25 @@ func Test_CreateTraceReceiver(t *testing.T) {
5356
assert.NotNil(t, recv)
5457
}
5558

59+
func TestWithTracesUnmarshalers(t *testing.T) {
60+
unmarshaler := &customTracesUnmarshaler{}
61+
f := NewFactory(withTracesUnmarshalers(unmarshaler))
62+
cfg := createDefaultConfig().(*Config)
63+
64+
t.Run("custom_encoding", func(t *testing.T) {
65+
cfg.Encoding = unmarshaler.Encoding()
66+
receiver, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
67+
require.NoError(t, err)
68+
require.NotNil(t, receiver)
69+
})
70+
t.Run("default_encoding", func(t *testing.T) {
71+
cfg.Encoding = defaultEncoding
72+
receiver, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
73+
require.NoError(t, err)
74+
assert.NotNil(t, receiver)
75+
})
76+
}
77+
5678
// metrics
5779
func TestCreateMetricsReceiver_err_addr(t *testing.T) {
5880
cfg := createDefaultConfig().(*Config)
@@ -83,6 +105,25 @@ func Test_CreateMetricsReceiver(t *testing.T) {
83105
assert.NotNil(t, recv)
84106
}
85107

108+
func TestWithMetricsUnmarshalers(t *testing.T) {
109+
unmarshaler := &customMetricsUnmarshaler{}
110+
f := NewFactory(withMetricsUnmarshalers(unmarshaler))
111+
cfg := createDefaultConfig().(*Config)
112+
113+
t.Run("custom_encoding", func(t *testing.T) {
114+
cfg.Encoding = unmarshaler.Encoding()
115+
receiver, err := f.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
116+
require.NoError(t, err)
117+
require.NotNil(t, receiver)
118+
})
119+
t.Run("default_encoding", func(t *testing.T) {
120+
cfg.Encoding = defaultEncoding
121+
receiver, err := f.CreateMetricsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
122+
require.NoError(t, err)
123+
assert.NotNil(t, receiver)
124+
})
125+
}
126+
86127
// logs
87128
func TestCreateLogsReceiver_err_addr(t *testing.T) {
88129
cfg := createDefaultConfig().(*Config)
@@ -113,3 +154,55 @@ func Test_CreateLogsReceiver(t *testing.T) {
113154
require.NoError(t, err)
114155
assert.NotNil(t, recv)
115156
}
157+
158+
func TestWithLogsUnmarshalers(t *testing.T) {
159+
unmarshaler := &customLogsUnmarshaler{}
160+
f := NewFactory(withLogsUnmarshalers(unmarshaler))
161+
cfg := createDefaultConfig().(*Config)
162+
163+
t.Run("custom_encoding", func(t *testing.T) {
164+
cfg.Encoding = unmarshaler.Encoding()
165+
exporter, err := f.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
166+
require.NoError(t, err)
167+
require.NotNil(t, exporter)
168+
})
169+
t.Run("default_encoding", func(t *testing.T) {
170+
cfg.Encoding = defaultEncoding
171+
exporter, err := f.CreateLogsReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
172+
require.NoError(t, err)
173+
assert.NotNil(t, exporter)
174+
})
175+
}
176+
177+
type customTracesUnmarshaler struct {
178+
}
179+
180+
type customMetricsUnmarshaler struct {
181+
}
182+
183+
type customLogsUnmarshaler struct {
184+
}
185+
186+
func (c customTracesUnmarshaler) Unmarshal([]byte) (ptrace.Traces, error) {
187+
panic("implement me")
188+
}
189+
190+
func (c customTracesUnmarshaler) Encoding() string {
191+
return "custom"
192+
}
193+
194+
func (c customMetricsUnmarshaler) Unmarshal([]byte) (pmetric.Metrics, error) {
195+
panic("implement me")
196+
}
197+
198+
func (c customMetricsUnmarshaler) Encoding() string {
199+
return "custom"
200+
}
201+
202+
func (c customLogsUnmarshaler) Unmarshal([]byte) (plog.Logs, error) {
203+
panic("implement me")
204+
}
205+
206+
func (c customLogsUnmarshaler) Encoding() string {
207+
return "custom"
208+
}

0 commit comments

Comments
 (0)