Debian Codegraph @

processor/processortest/shutdown_verifier_test.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package processortest
5
6 import (
7 "context"
8 "testing"
9
10 "go.opentelemetry.io/collector/component"
11 "go.opentelemetry.io/collector/consumer"
12 "go.opentelemetry.io/collector/pdata/plog"
13 "go.opentelemetry.io/collector/pdata/pmetric"
14 "go.opentelemetry.io/collector/pdata/ptrace"
15 "go.opentelemetry.io/collector/processor"
16 )
17
18 func TestShutdownVerifier(t *testing.T) {
19 f := processor.NewFactory(
20 component.MustNewType("passthrough"),
21 func() component.Config { return struct{}{} },
22 processor.WithTraces(createPassthroughTraces, component.StabilityLevelStable),
23 processor.WithMetrics(createPassthroughMetrics, component.StabilityLevelStable),
24 processor.WithLogs(createPassthroughLogs, component.StabilityLevelStable),
25 )
26 VerifyShutdown(t, f, &struct{}{})
27 }
28
29 func TestShutdownVerifierLogsOnly(t *testing.T) {
30 f := processor.NewFactory(
31 component.MustNewType("passthrough"),
32 func() component.Config { return struct{}{} },
33 processor.WithLogs(createPassthroughLogs, component.StabilityLevelStable),
34 )
35 VerifyShutdown(t, f, &struct{}{})
36 }
37
38 func TestShutdownVerifierMetricsOnly(t *testing.T) {
39 f := processor.NewFactory(
40 component.MustNewType("passthrough"),
41 func() component.Config { return struct{}{} },
42 processor.WithMetrics(createPassthroughMetrics, component.StabilityLevelStable),
43 )
44 VerifyShutdown(t, f, &struct{}{})
45 }
46
47 func TestShutdownVerifierTracesOnly(t *testing.T) {
48 f := processor.NewFactory(
49 component.MustNewType("passthrough"),
50 func() component.Config { return struct{}{} },
51 processor.WithTraces(createPassthroughTraces, component.StabilityLevelStable),
52 )
53 VerifyShutdown(t, f, &struct{}{})
54 }
55
56 type passthrough struct {
57 processor.Traces
58 nextLogs consumer.Logs
59 nextMetrics consumer.Metrics
60 nextTraces consumer.Traces
61 }
62
63 func (passthrough) Start(context.Context, component.Host) error {
64 return nil
65 }
66
67 func (passthrough) Shutdown(context.Context) error {
68 return nil
69 }
70
71 func (passthrough) Capabilities() consumer.Capabilities {
72 return consumer.Capabilities{}
73 }
74
75 func createPassthroughLogs(_ context.Context, _ processor.Settings, _ component.Config, logs consumer.Logs) (processor.Logs, error) {
76 return passthrough{
77 nextLogs: logs,
78 }, nil
79 }
80
81 func createPassthroughMetrics(_ context.Context, _ processor.Settings, _ component.Config, metrics consumer.Metrics) (processor.Metrics, error) {
82 return passthrough{
83 nextMetrics: metrics,
84 }, nil
85 }
86
87 func createPassthroughTraces(_ context.Context, _ processor.Settings, _ component.Config, traces consumer.Traces) (processor.Traces, error) {
88 return passthrough{
89 nextTraces: traces,
90 }, nil
91 }
92
93 func (p passthrough) ConsumeTraces(ctx context.Context, td ptrace.Traces) error {
94 return p.nextTraces.ConsumeTraces(ctx, td)
95 }
96
97 func (p passthrough) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
98 return p.nextMetrics.ConsumeMetrics(ctx, md)
99 }
100
101 func (p passthrough) ConsumeLogs(ctx context.Context, ld plog.Logs) error {
102 return p.nextLogs.ConsumeLogs(ctx, ld)
103 }