factory.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package wavefrontreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver"
  4. import (
  5. "context"
  6. "fmt"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confignet"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/receiver"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver/internal/metadata"
  13. )
  14. // This file implements factory for the Wavefront receiver.
  15. // NewFactory creates a factory for WaveFront receiver.
  16. func NewFactory() receiver.Factory {
  17. return receiver.NewFactory(
  18. metadata.Type,
  19. createDefaultConfig,
  20. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  21. }
  22. func createDefaultConfig() component.Config {
  23. return &Config{
  24. TCPAddr: confignet.TCPAddr{
  25. Endpoint: "localhost:2003",
  26. },
  27. TCPIdleTimeout: transport.TCPIdleTimeoutDefault,
  28. }
  29. }
  30. func createMetricsReceiver(
  31. _ context.Context,
  32. params receiver.CreateSettings,
  33. cfg component.Config,
  34. consumer consumer.Metrics,
  35. ) (receiver.Metrics, error) {
  36. rCfg, ok := cfg.(*Config)
  37. if !ok {
  38. return nil, fmt.Errorf("a wavefront receiver config was expected by the receiver factory, but got %T", rCfg)
  39. }
  40. return newMetricsReceiver(rCfg, params, consumer), nil
  41. }