factory.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confignet"
  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/redisreceiver/internal/metadata"
  14. )
  15. // NewFactory creates a factory for Redis receiver.
  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. scs := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
  24. scs.CollectionInterval = 10 * time.Second
  25. return &Config{
  26. NetAddr: confignet.NetAddr{
  27. Transport: "tcp",
  28. },
  29. TLS: configtls.TLSClientSetting{
  30. Insecure: true,
  31. },
  32. ScraperControllerSettings: scs,
  33. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  34. }
  35. }
  36. func createMetricsReceiver(
  37. _ context.Context,
  38. set receiver.CreateSettings,
  39. cfg component.Config,
  40. consumer consumer.Metrics,
  41. ) (receiver.Metrics, error) {
  42. oCfg := cfg.(*Config)
  43. scrp, err := newRedisScraper(oCfg, set)
  44. if err != nil {
  45. return nil, err
  46. }
  47. return scraperhelper.NewScraperControllerReceiver(&oCfg.ScraperControllerSettings, set, consumer, scraperhelper.AddScraper(scrp))
  48. }