factory.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlecloudspannerreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/googlecloudspannerreceiver"
  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/googlecloudspannerreceiver/internal/metadata"
  12. )
  13. const (
  14. defaultCollectionInterval = 60 * time.Second
  15. defaultTopMetricsQueryMaxRows = 100
  16. defaultBackfillEnabled = false
  17. defaultHideTopnLockstatsRowrangestartkey = false
  18. defaultTruncateText = false
  19. )
  20. func NewFactory() receiver.Factory {
  21. return receiver.NewFactory(
  22. metadata.Type,
  23. createDefaultConfig,
  24. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  25. }
  26. func createDefaultConfig() component.Config {
  27. return &Config{
  28. ScraperControllerSettings: scraperhelper.NewDefaultScraperControllerSettings(metadata.Type),
  29. TopMetricsQueryMaxRows: defaultTopMetricsQueryMaxRows,
  30. BackfillEnabled: defaultBackfillEnabled,
  31. HideTopnLockstatsRowrangestartkey: defaultHideTopnLockstatsRowrangestartkey,
  32. TruncateText: defaultTruncateText,
  33. }
  34. }
  35. func createMetricsReceiver(
  36. _ context.Context,
  37. settings receiver.CreateSettings,
  38. baseCfg component.Config,
  39. consumer consumer.Metrics,
  40. ) (receiver.Metrics, error) {
  41. rCfg := baseCfg.(*Config)
  42. r := newGoogleCloudSpannerReceiver(settings.Logger, rCfg)
  43. scraper, err := scraperhelper.NewScraper(metadata.Type, r.Scrape, scraperhelper.WithStart(r.Start),
  44. scraperhelper.WithShutdown(r.Shutdown))
  45. if err != nil {
  46. return nil, err
  47. }
  48. return scraperhelper.NewScraperControllerReceiver(&rCfg.ScraperControllerSettings, settings, consumer,
  49. scraperhelper.AddScraper(scraper))
  50. }