factory.go 1.9 KB

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