config.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package purefareceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver"
  4. import (
  5. "errors"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/confighttp"
  9. "go.uber.org/multierr"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/purefareceiver/internal"
  11. )
  12. var _ component.Config = (*Config)(nil)
  13. // Config relating to Array Metric Scraper.
  14. type Config struct {
  15. confighttp.HTTPClientSettings `mapstructure:",squash"`
  16. // Settings contains settings for the individual scrapers
  17. Settings *Settings `mapstructure:"settings"`
  18. // Array represents the list of arrays to query
  19. Array []internal.ScraperConfig `mapstructure:"array"`
  20. // Hosts represents the list of hosts to query
  21. Hosts []internal.ScraperConfig `mapstructure:"hosts"`
  22. // Directories represents the list of directories to query
  23. Directories []internal.ScraperConfig `mapstructure:"directories"`
  24. // Pods represents the list of pods to query
  25. Pods []internal.ScraperConfig `mapstructure:"pods"`
  26. // Volumes represents the list of volumes to query
  27. Volumes []internal.ScraperConfig `mapstructure:"volumes"`
  28. // Env represents the respective environment value valid to scrape
  29. Env string `mapstructure:"env"`
  30. // ArrayName represents the display name that is appended to the received metrics, as the `host` label if not provided by OpenMetrics output, and to the `fa_array_name` label always.
  31. ArrayName string `mapstructure:"fa_array_name"`
  32. }
  33. type Settings struct {
  34. ReloadIntervals *ReloadIntervals `mapstructure:"reload_intervals"`
  35. }
  36. type ReloadIntervals struct {
  37. Array time.Duration `mapstructure:"array"`
  38. Hosts time.Duration `mapstructure:"hosts"`
  39. Directories time.Duration `mapstructure:"directories"`
  40. Pods time.Duration `mapstructure:"pods"`
  41. Volumes time.Duration `mapstructure:"volumes"`
  42. }
  43. func (c *Config) Validate() error {
  44. var errs error
  45. if c.ArrayName == "" {
  46. errs = multierr.Append(errs, errors.New("the array's pretty name as 'fa_array_name' must be provided"))
  47. }
  48. if c.Settings.ReloadIntervals.Array == 0 {
  49. errs = multierr.Append(errs, errors.New("reload interval for 'array' must be provided"))
  50. }
  51. if c.Settings.ReloadIntervals.Hosts == 0 {
  52. errs = multierr.Append(errs, errors.New("reload interval for 'hosts' must be provided"))
  53. }
  54. if c.Settings.ReloadIntervals.Directories == 0 {
  55. errs = multierr.Append(errs, errors.New("reload interval for 'directories' must be provided"))
  56. }
  57. if c.Settings.ReloadIntervals.Pods == 0 {
  58. errs = multierr.Append(errs, errors.New("reload interval for 'pods' must be provided"))
  59. }
  60. if c.Settings.ReloadIntervals.Volumes == 0 {
  61. errs = multierr.Append(errs, errors.New("reload interval for 'volumes' must be provided"))
  62. }
  63. return errs
  64. }