factory.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package couchdbreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/couchdbreceiver"
  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. "go.opentelemetry.io/collector/receiver/scraperhelper"
  13. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/couchdbreceiver/internal/metadata"
  14. )
  15. // NewFactory creates the couchdbreceiver factory
  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. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  25. ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
  26. HTTPClientSettings: confighttp.HTTPClientSettings{
  27. TLSSetting: configtls.TLSClientSetting{},
  28. Endpoint: defaultEndpoint,
  29. Timeout: 1 * time.Minute,
  30. },
  31. }
  32. }
  33. func createMetricsReceiver(
  34. _ context.Context,
  35. params receiver.CreateSettings,
  36. rConf component.Config,
  37. consumer consumer.Metrics,
  38. ) (receiver.Metrics, error) {
  39. cfg := rConf.(*Config)
  40. ns := newCouchdbScraper(params, cfg)
  41. scraper, err := scraperhelper.NewScraper(metadata.Type, ns.scrape, scraperhelper.WithStart(ns.start))
  42. if err != nil {
  43. return nil, err
  44. }
  45. return scraperhelper.NewScraperControllerReceiver(
  46. &cfg.ScraperControllerSettings, params, consumer,
  47. scraperhelper.AddScraper(scraper),
  48. )
  49. }