factory.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package splunkenterprisereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/splunkenterprisereceiver"
  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/configopaque"
  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/splunkenterprisereceiver/internal/metadata"
  14. )
  15. const (
  16. defaultInterval = 10 * time.Minute
  17. defaultMaxSearchWaitTime = 60 * time.Second
  18. )
  19. func createDefaultConfig() component.Config {
  20. // Default HttpClient settings
  21. httpCfg := confighttp.NewDefaultHTTPClientSettings()
  22. httpCfg.Headers = map[string]configopaque.String{
  23. "Content-Type": "application/x-www-form-urlencoded",
  24. }
  25. // Default ScraperController settings
  26. scfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
  27. scfg.CollectionInterval = defaultInterval
  28. scfg.Timeout = defaultMaxSearchWaitTime
  29. return &Config{
  30. HTTPClientSettings: httpCfg,
  31. ScraperControllerSettings: scfg,
  32. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  33. }
  34. }
  35. func NewFactory() receiver.Factory {
  36. return receiver.NewFactory(
  37. metadata.Type,
  38. createDefaultConfig,
  39. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability),
  40. )
  41. }
  42. func createMetricsReceiver(
  43. _ context.Context,
  44. params receiver.CreateSettings,
  45. baseCfg component.Config,
  46. consumer consumer.Metrics,
  47. ) (receiver.Metrics, error) {
  48. cfg := baseCfg.(*Config)
  49. splunkScraper := newSplunkMetricsScraper(params, cfg)
  50. scraper, err := scraperhelper.NewScraper(metadata.Type,
  51. splunkScraper.scrape,
  52. scraperhelper.WithStart(splunkScraper.start))
  53. if err != nil {
  54. return nil, err
  55. }
  56. return scraperhelper.NewScraperControllerReceiver(
  57. &cfg.ScraperControllerSettings,
  58. params,
  59. consumer,
  60. scraperhelper.AddScraper(scraper),
  61. )
  62. }