udp.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package udplogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/udplogreceiver"
  4. import (
  5. "go.opentelemetry.io/collector/component"
  6. "go.opentelemetry.io/collector/receiver"
  7. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/adapter"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
  9. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/udp"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/udplogreceiver/internal/metadata"
  11. )
  12. // NewFactory creates a factory for udp receiver
  13. func NewFactory() receiver.Factory {
  14. return adapter.NewFactory(ReceiverType{}, metadata.LogsStability)
  15. }
  16. // ReceiverType implements adapter.LogReceiverType
  17. // to create a udp receiver
  18. type ReceiverType struct{}
  19. // Type is the receiver type
  20. func (f ReceiverType) Type() component.Type {
  21. return metadata.Type
  22. }
  23. // CreateDefaultConfig creates a config with type and version
  24. func (f ReceiverType) CreateDefaultConfig() component.Config {
  25. return &UDPLogConfig{
  26. BaseConfig: adapter.BaseConfig{
  27. Operators: []operator.Config{},
  28. },
  29. InputConfig: *udp.NewConfig(),
  30. }
  31. }
  32. // BaseConfig gets the base config from config, for now
  33. func (f ReceiverType) BaseConfig(cfg component.Config) adapter.BaseConfig {
  34. return cfg.(*UDPLogConfig).BaseConfig
  35. }
  36. // UDPLogConfig defines configuration for the udp receiver
  37. type UDPLogConfig struct {
  38. InputConfig udp.Config `mapstructure:",squash"`
  39. adapter.BaseConfig `mapstructure:",squash"`
  40. }
  41. // InputConfig unmarshals the input operator
  42. func (f ReceiverType) InputConfig(cfg component.Config) operator.Config {
  43. return operator.NewConfig(&cfg.(*UDPLogConfig).InputConfig)
  44. }