journald.go 2.0 KB

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