factory.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package podmanreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/podmanreceiver"
  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/podmanreceiver/internal/metadata"
  12. )
  13. const (
  14. defaultAPIVersion = "3.3.1"
  15. )
  16. func NewFactory() receiver.Factory {
  17. return receiver.NewFactory(
  18. metadata.Type,
  19. createDefaultReceiverConfig,
  20. receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
  21. }
  22. func createDefaultConfig() *Config {
  23. cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type)
  24. cfg.CollectionInterval = 10 * time.Second
  25. cfg.Timeout = 5 * time.Second
  26. return &Config{
  27. ScraperControllerSettings: cfg,
  28. Endpoint: "unix:///run/podman/podman.sock",
  29. APIVersion: defaultAPIVersion,
  30. }
  31. }
  32. func createDefaultReceiverConfig() component.Config {
  33. return createDefaultConfig()
  34. }
  35. func createMetricsReceiver(
  36. ctx context.Context,
  37. params receiver.CreateSettings,
  38. config component.Config,
  39. consumer consumer.Metrics,
  40. ) (receiver.Metrics, error) {
  41. podmanConfig := config.(*Config)
  42. dsr, err := newMetricsReceiver(ctx, params, podmanConfig, consumer, nil)
  43. if err != nil {
  44. return nil, err
  45. }
  46. return dsr, nil
  47. }