factory.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package aerospikereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/consumer"
  9. "go.opentelemetry.io/collector/receiver"
  10. "go.opentelemetry.io/collector/receiver/scraperhelper"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver/internal/metadata"
  12. )
  13. const (
  14. defaultEndpoint = "localhost:3000"
  15. defaultTimeout = 20 * time.Second
  16. defaultCollectClusterMetrics = false
  17. )
  18. // NewFactory creates a new ReceiverFactory with default configuration
  19. func NewFactory() receiver.Factory {
  20. return receiver.NewFactory(
  21. metadata.Type,
  22. createDefaultConfig,
  23. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
  24. )
  25. }
  26. // createMetricsReceiver creates a new MetricsReceiver using scraperhelper
  27. func createMetricsReceiver(
  28. _ context.Context,
  29. params receiver.CreateSettings,
  30. rConf component.Config,
  31. consumer consumer.Metrics,
  32. ) (receiver.Metrics, error) {
  33. cfg := rConf.(*Config)
  34. receiver, err := newAerospikeReceiver(params, cfg, consumer)
  35. if err != nil {
  36. return nil, err
  37. }
  38. scraper, err := scraperhelper.NewScraper(
  39. metadata.Type,
  40. receiver.scrape,
  41. scraperhelper.WithStart(receiver.start),
  42. scraperhelper.WithShutdown(receiver.shutdown),
  43. )
  44. if err != nil {
  45. return nil, err
  46. }
  47. return scraperhelper.NewScraperControllerReceiver(
  48. &cfg.ScraperControllerSettings, params, consumer,
  49. scraperhelper.AddScraper(scraper),
  50. )
  51. }
  52. func createDefaultConfig() component.Config {
  53. return &Config{
  54. ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
  55. Endpoint: defaultEndpoint,
  56. Timeout: defaultTimeout,
  57. CollectClusterMetrics: defaultCollectClusterMetrics,
  58. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  59. }
  60. }