factory.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package prometheusreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver"
  4. import (
  5. "context"
  6. promconfig "github.com/prometheus/prometheus/config"
  7. _ "github.com/prometheus/prometheus/discovery/install" // init() of this package registers service discovery impl.
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/featuregate"
  11. "go.opentelemetry.io/collector/receiver"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver/internal/metadata"
  13. )
  14. // This file implements config for Prometheus receiver.
  15. var useCreatedMetricGate = featuregate.GlobalRegistry().MustRegister(
  16. "receiver.prometheusreceiver.UseCreatedMetric",
  17. featuregate.StageAlpha,
  18. featuregate.WithRegisterDescription("When enabled, the Prometheus receiver will"+
  19. " retrieve the start time for Summary, Histogram and Sum metrics from _created metric"),
  20. )
  21. // NewFactory creates a new Prometheus receiver factory.
  22. func NewFactory() receiver.Factory {
  23. return receiver.NewFactory(
  24. metadata.Type,
  25. createDefaultConfig,
  26. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  27. }
  28. func createDefaultConfig() component.Config {
  29. return &Config{
  30. PrometheusConfig: &promconfig.Config{
  31. GlobalConfig: promconfig.DefaultGlobalConfig,
  32. },
  33. }
  34. }
  35. func createMetricsReceiver(
  36. _ context.Context,
  37. set receiver.CreateSettings,
  38. cfg component.Config,
  39. nextConsumer consumer.Metrics,
  40. ) (receiver.Metrics, error) {
  41. configWarnings(set.Logger, cfg.(*Config))
  42. return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil
  43. }