| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package processortest // import "go.opentelemetry.io/collector/processor/processortest" |
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
|
| 9 |
"go.opentelemetry.io/collector/component" |
| 10 |
"go.opentelemetry.io/collector/component/componentstatus" |
| 11 |
"go.opentelemetry.io/collector/consumer" |
| 12 |
"go.opentelemetry.io/collector/consumer/consumertest" |
| 13 |
"go.opentelemetry.io/collector/processor" |
| 14 |
) |
| 15 |
|
| 16 |
// NewUnhealthyProcessorFactory returns a processor.Factory that constructs nop processors. |
| 17 |
func NewUnhealthyProcessorFactory() processor.Factory { |
| 18 |
return processor.NewFactory( |
| 19 |
component.MustNewType("unhealthy"), |
| 20 |
func() component.Config { |
| 21 |
return &struct{}{} |
| 22 |
}, |
| 23 |
processor.WithTraces(createUnhealthyTraces, component.StabilityLevelStable), |
| 24 |
processor.WithMetrics(createUnhealthyMetrics, component.StabilityLevelStable), |
| 25 |
processor.WithLogs(createUnhealthyLogs, component.StabilityLevelStable), |
| 26 |
) |
| 27 |
} |
| 28 |
|
| 29 |
func createUnhealthyTraces(_ context.Context, set processor.Settings, _ component.Config, _ consumer.Traces) (processor.Traces, error) { |
| 30 |
return &unhealthy{ |
| 31 |
Consumer: consumertest.NewNop(), |
| 32 |
telemetry: set.TelemetrySettings, |
| 33 |
}, nil |
| 34 |
} |
| 35 |
|
| 36 |
func createUnhealthyMetrics(_ context.Context, set processor.Settings, _ component.Config, _ consumer.Metrics) (processor.Metrics, error) { |
| 37 |
return &unhealthy{ |
| 38 |
Consumer: consumertest.NewNop(), |
| 39 |
telemetry: set.TelemetrySettings, |
| 40 |
}, nil |
| 41 |
} |
| 42 |
|
| 43 |
func createUnhealthyLogs(_ context.Context, set processor.Settings, _ component.Config, _ consumer.Logs) (processor.Logs, error) { |
| 44 |
return &unhealthy{ |
| 45 |
Consumer: consumertest.NewNop(), |
| 46 |
telemetry: set.TelemetrySettings, |
| 47 |
}, nil |
| 48 |
} |
| 49 |
|
| 50 |
type unhealthy struct { |
| 51 |
component.StartFunc |
| 52 |
component.ShutdownFunc |
| 53 |
consumertest.Consumer |
| 54 |
telemetry component.TelemetrySettings |
| 55 |
} |
| 56 |
|
| 57 |
func (p unhealthy) Start(_ context.Context, host component.Host) error { |
| 58 |
go func() { |
| 59 |
componentstatus.ReportStatus(host, componentstatus.NewEvent(componentstatus.StatusRecoverableError)) |
| 60 |
}() |
| 61 |
return nil |
| 62 |
} |