tcp.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package tcplogreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver"
  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/tcp"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tcplogreceiver/internal/metadata"
  11. )
  12. // NewFactory creates a factory for tcp receiver
  13. func NewFactory() receiver.Factory {
  14. return adapter.NewFactory(ReceiverType{}, metadata.LogsStability)
  15. }
  16. // ReceiverType implements adapter.LogReceiverType
  17. // to create a tcp 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 &TCPLogConfig{
  26. BaseConfig: adapter.BaseConfig{
  27. Operators: []operator.Config{},
  28. },
  29. InputConfig: *tcp.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.(*TCPLogConfig).BaseConfig
  35. }
  36. // TCPLogConfig defines configuration for the tcp receiver
  37. type TCPLogConfig struct {
  38. InputConfig tcp.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.(*TCPLogConfig).InputConfig)
  44. }