factory.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package k8sclusterreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver"
  4. import (
  5. "time"
  6. "go.opentelemetry.io/collector/component"
  7. "go.opentelemetry.io/collector/receiver"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
  9. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata"
  11. )
  12. const (
  13. // supported distributions
  14. distributionKubernetes = "kubernetes"
  15. distributionOpenShift = "openshift"
  16. // Default config values.
  17. defaultCollectionInterval = 10 * time.Second
  18. defaultDistribution = distributionKubernetes
  19. defaultMetadataCollectionInterval = 5 * time.Minute
  20. )
  21. var defaultNodeConditionsToReport = []string{"Ready"}
  22. func createDefaultConfig() component.Config {
  23. return &Config{
  24. Distribution: defaultDistribution,
  25. CollectionInterval: defaultCollectionInterval,
  26. NodeConditionTypesToReport: defaultNodeConditionsToReport,
  27. APIConfig: k8sconfig.APIConfig{
  28. AuthType: k8sconfig.AuthTypeServiceAccount,
  29. },
  30. MetadataCollectionInterval: defaultMetadataCollectionInterval,
  31. MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
  32. }
  33. }
  34. // NewFactory creates a factory for k8s_cluster receiver.
  35. func NewFactory() receiver.Factory {
  36. return receiver.NewFactory(
  37. metadata.Type,
  38. createDefaultConfig,
  39. receiver.WithMetrics(newMetricsReceiver, metadata.MetricsStability),
  40. receiver.WithLogs(newLogsReceiver, metadata.MetricsStability),
  41. )
  42. }
  43. // This is the map of already created k8scluster receivers for particular configurations.
  44. // We maintain this map because the Factory is asked log and metric receivers separately
  45. // when it gets CreateLogsReceiver() and CreateMetricsReceiver() but they must not
  46. // create separate objects, they must use one receiver object per configuration.
  47. var receivers = sharedcomponent.NewSharedComponents()