factory.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package mysqlreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confignet"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/receiver"
  11. "go.opentelemetry.io/collector/receiver/scraperhelper"
  12. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata"
  13. )
  14. func NewFactory() receiver.Factory {
  15. return receiver.NewFactory(
  16. metadata.Type,
  17. createDefaultConfig,
  18. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  19. }
  20. func createDefaultConfig() component.Config {
  21. cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
  22. cfg.CollectionInterval = 10 * time.Second
  23. return &Config{
  24. ScraperControllerSettings: cfg,
  25. AllowNativePasswords: true,
  26. Username: "root",
  27. NetAddr: confignet.NetAddr{
  28. Endpoint: "localhost:3306",
  29. Transport: "tcp",
  30. },
  31. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  32. StatementEvents: StatementEventsConfig{
  33. DigestTextLimit: defaultStatementEventsDigestTextLimit,
  34. Limit: defaultStatementEventsLimit,
  35. TimeLimit: defaultStatementEventsTimeLimit,
  36. },
  37. }
  38. }
  39. func createMetricsReceiver(
  40. _ context.Context,
  41. params receiver.CreateSettings,
  42. rConf component.Config,
  43. consumer consumer.Metrics,
  44. ) (receiver.Metrics, error) {
  45. cfg := rConf.(*Config)
  46. ns := newMySQLScraper(params, cfg)
  47. scraper, err := scraperhelper.NewScraper(metadata.Type, ns.scrape, scraperhelper.WithStart(ns.start),
  48. scraperhelper.WithShutdown(ns.shutdown))
  49. if err != nil {
  50. return nil, err
  51. }
  52. return scraperhelper.NewScraperControllerReceiver(
  53. &cfg.ScraperControllerSettings, params, consumer,
  54. scraperhelper.AddScraper(scraper),
  55. )
  56. }