config.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package redisreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver"
  4. import (
  5. "fmt"
  6. "net"
  7. "go.opentelemetry.io/collector/config/confignet"
  8. "go.opentelemetry.io/collector/config/configopaque"
  9. "go.opentelemetry.io/collector/config/configtls"
  10. "go.opentelemetry.io/collector/receiver/scraperhelper"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver/internal/metadata"
  12. )
  13. type Config struct {
  14. scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
  15. // TODO: Use one of the configs from core.
  16. // The target endpoint.
  17. confignet.NetAddr `mapstructure:",squash"`
  18. // TODO allow users to add additional resource key value pairs?
  19. // Optional username. Use the specified Username to authenticate the current connection
  20. // with one of the connections defined in the ACL list when connecting
  21. // to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
  22. Username string `mapstructure:"username"`
  23. // Optional password. Must match the password specified in the
  24. // requirepass server configuration option, or the user's password when connecting
  25. // to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
  26. Password configopaque.String `mapstructure:"password"`
  27. TLS configtls.TLSClientSetting `mapstructure:"tls,omitempty"`
  28. MetricsBuilderConfig metadata.MetricsBuilderConfig `mapstructure:",squash"`
  29. }
  30. // configInfo holds configuration information to be used as resource/metrics attributes.
  31. type configInfo struct {
  32. Address string
  33. Port string
  34. }
  35. func newConfigInfo(cfg *Config) (configInfo, error) {
  36. address, port, err := net.SplitHostPort(cfg.Endpoint)
  37. if err != nil {
  38. return configInfo{}, fmt.Errorf("invalid endpoint %q: %w", cfg.Endpoint, err)
  39. }
  40. return configInfo{Address: address, Port: port}, nil
  41. }