factory.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package rabbitmqreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver"
  4. import (
  5. "context"
  6. "errors"
  7. "time"
  8. "go.opentelemetry.io/collector/component"
  9. "go.opentelemetry.io/collector/config/confighttp"
  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/rabbitmqreceiver/internal/metadata"
  14. )
  15. var errConfigNotRabbit = errors.New("config was not a RabbitMQ receiver config")
  16. // NewFactory creates a new receiver factory
  17. func NewFactory() receiver.Factory {
  18. return receiver.NewFactory(
  19. metadata.Type,
  20. createDefaultConfig,
  21. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  22. }
  23. func createDefaultConfig() component.Config {
  24. cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
  25. cfg.CollectionInterval = 10 * time.Second
  26. return &Config{
  27. ScraperControllerSettings: cfg,
  28. HTTPClientSettings: confighttp.HTTPClientSettings{
  29. Endpoint: defaultEndpoint,
  30. Timeout: 10 * time.Second,
  31. },
  32. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  33. }
  34. }
  35. func createMetricsReceiver(_ context.Context, params receiver.CreateSettings, rConf component.Config, consumer consumer.Metrics) (receiver.Metrics, error) {
  36. cfg, ok := rConf.(*Config)
  37. if !ok {
  38. return nil, errConfigNotRabbit
  39. }
  40. rabbitScraper := newScraper(params.Logger, cfg, params)
  41. scraper, err := scraperhelper.NewScraper(metadata.Type, rabbitScraper.scrape, scraperhelper.WithStart(rabbitScraper.start))
  42. if err != nil {
  43. return nil, err
  44. }
  45. return scraperhelper.NewScraperControllerReceiver(&cfg.ScraperControllerSettings, params, consumer, scraperhelper.AddScraper(scraper))
  46. }