factory.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package memoryscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper"
  4. import (
  5. "context"
  6. "go.opentelemetry.io/collector/receiver"
  7. "go.opentelemetry.io/collector/receiver/scraperhelper"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
  9. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata"
  10. )
  11. // This file implements Factory for Memory scraper.
  12. const (
  13. // TypeStr the value of "type" key in configuration.
  14. TypeStr = "memory"
  15. )
  16. // Factory is the Factory for scraper.
  17. type Factory struct {
  18. }
  19. // CreateDefaultConfig creates the default configuration for the Scraper.
  20. func (f *Factory) CreateDefaultConfig() internal.Config {
  21. return &Config{
  22. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  23. }
  24. }
  25. // CreateMetricsScraper creates a scraper based on provided config.
  26. func (f *Factory) CreateMetricsScraper(
  27. ctx context.Context,
  28. settings receiver.CreateSettings,
  29. config internal.Config,
  30. ) (scraperhelper.Scraper, error) {
  31. cfg := config.(*Config)
  32. s := newMemoryScraper(ctx, settings, cfg)
  33. return scraperhelper.NewScraper(
  34. TypeStr, s.scrape, scraperhelper.WithStart(s.start))
  35. }