factory.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package statsdreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver"
  4. import (
  5. "context"
  6. "time"
  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/statsdreceiver/internal/metadata"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver/internal/protocol"
  13. )
  14. const (
  15. defaultBindEndpoint = "localhost:8125"
  16. defaultTransport = "udp"
  17. defaultAggregationInterval = 60 * time.Second
  18. defaultEnableMetricType = false
  19. defaultIsMonotonicCounter = false
  20. )
  21. var (
  22. defaultTimerHistogramMapping = []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}, {StatsdType: "distribution", ObserverType: "gauge"}}
  23. )
  24. // NewFactory creates a factory for the StatsD receiver.
  25. func NewFactory() receiver.Factory {
  26. return receiver.NewFactory(
  27. metadata.Type,
  28. createDefaultConfig,
  29. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
  30. )
  31. }
  32. func createDefaultConfig() component.Config {
  33. return &Config{
  34. NetAddr: confignet.NetAddr{
  35. Endpoint: defaultBindEndpoint,
  36. Transport: defaultTransport,
  37. },
  38. AggregationInterval: defaultAggregationInterval,
  39. EnableMetricType: defaultEnableMetricType,
  40. IsMonotonicCounter: defaultIsMonotonicCounter,
  41. TimerHistogramMapping: defaultTimerHistogramMapping,
  42. }
  43. }
  44. func createMetricsReceiver(
  45. _ context.Context,
  46. params receiver.CreateSettings,
  47. cfg component.Config,
  48. consumer consumer.Metrics,
  49. ) (receiver.Metrics, error) {
  50. c := cfg.(*Config)
  51. return newReceiver(params, *c, consumer)
  52. }