config.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. "fmt"
  6. "time"
  7. "github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
  8. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/metadata"
  9. )
  10. // Config defines configuration for kubernetes cluster receiver.
  11. type Config struct {
  12. k8sconfig.APIConfig `mapstructure:",squash"`
  13. // Collection interval for metrics.
  14. CollectionInterval time.Duration `mapstructure:"collection_interval"`
  15. // Node condition types to report. See all condition types, see
  16. // here: https://kubernetes.io/docs/concepts/architecture/nodes/#condition.
  17. NodeConditionTypesToReport []string `mapstructure:"node_conditions_to_report"`
  18. // Allocate resource types to report. See all resource types, see
  19. // here: https://kubernetes.io/docs/concepts/architecture/nodes/#capacity
  20. AllocatableTypesToReport []string `mapstructure:"allocatable_types_to_report"`
  21. // List of exporters to which metadata from this receiver should be forwarded to.
  22. MetadataExporters []string `mapstructure:"metadata_exporters"`
  23. // Whether OpenShift support should be enabled or not.
  24. Distribution string `mapstructure:"distribution"`
  25. // Collection interval for metadata.
  26. // Metadata of the particular entity in the cluster is collected when the entity changes.
  27. // In addition metadata of all entities is collected periodically even if no changes happen.
  28. // Setting the duration to 0 will disable periodic collection (however will not impact
  29. // metadata collection on changes).
  30. MetadataCollectionInterval time.Duration `mapstructure:"metadata_collection_interval"`
  31. // MetricsBuilderConfig allows customizing scraped metrics/attributes representation.
  32. metadata.MetricsBuilderConfig `mapstructure:",squash"`
  33. }
  34. func (cfg *Config) Validate() error {
  35. switch cfg.Distribution {
  36. case distributionOpenShift:
  37. case distributionKubernetes:
  38. default:
  39. return fmt.Errorf("\"%s\" is not a supported distribution. Must be one of: \"openshift\", \"kubernetes\"", cfg.Distribution)
  40. }
  41. return nil
  42. }