factory.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package simpleprometheusreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confighttp"
  9. "go.opentelemetry.io/collector/config/configtls"
  10. "go.opentelemetry.io/collector/consumer"
  11. "go.opentelemetry.io/collector/receiver"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/simpleprometheusreceiver/internal/metadata"
  13. )
  14. // This file implements factory for prometheus_simple receiver
  15. const (
  16. defaultEndpoint = "localhost:9090"
  17. defaultMetricsPath = "/metrics"
  18. )
  19. var defaultCollectionInterval = 10 * time.Second
  20. // NewFactory creates a factory for "Simple" Prometheus receiver.
  21. func NewFactory() receiver.Factory {
  22. return receiver.NewFactory(
  23. metadata.Type,
  24. createDefaultConfig,
  25. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  26. }
  27. func createDefaultConfig() component.Config {
  28. return &Config{
  29. HTTPClientSettings: confighttp.HTTPClientSettings{
  30. Endpoint: defaultEndpoint,
  31. TLSSetting: configtls.TLSClientSetting{
  32. Insecure: true,
  33. },
  34. },
  35. MetricsPath: defaultMetricsPath,
  36. CollectionInterval: defaultCollectionInterval,
  37. }
  38. }
  39. func createMetricsReceiver(
  40. _ context.Context,
  41. params receiver.CreateSettings,
  42. cfg component.Config,
  43. nextConsumer consumer.Metrics,
  44. ) (receiver.Metrics, error) {
  45. rCfg := cfg.(*Config)
  46. return newPrometheusReceiverWrapper(params, rCfg, nextConsumer), nil
  47. }