1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package rabbitmqreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver"
- import (
- "errors"
- "fmt"
- "net/url"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/config/configopaque"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "go.uber.org/multierr"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver/internal/metadata"
- )
- // Predefined error responses for configuration validation failures
- var (
- errMissingUsername = errors.New(`"username" not specified in config`)
- errMissingPassword = errors.New(`"password" not specified in config`)
- errInvalidEndpoint = errors.New(`"endpoint" must be in the form of <scheme>://<hostname>:<port>`)
- )
- const defaultEndpoint = "http://localhost:15672"
- // Config defines the configuration for the various elements of the receiver agent.
- type Config struct {
- scraperhelper.ScraperControllerSettings `mapstructure:",squash"`
- confighttp.HTTPClientSettings `mapstructure:",squash"`
- Username string `mapstructure:"username"`
- Password configopaque.String `mapstructure:"password"`
- metadata.MetricsBuilderConfig `mapstructure:",squash"`
- }
- // Validate validates the configuration by checking for missing or invalid fields
- func (cfg *Config) Validate() error {
- var err error
- if cfg.Username == "" {
- err = multierr.Append(err, errMissingUsername)
- }
- if cfg.Password == "" {
- err = multierr.Append(err, errMissingPassword)
- }
- _, parseErr := url.Parse(cfg.Endpoint)
- if parseErr != nil {
- wrappedErr := fmt.Errorf("%s: %w", errInvalidEndpoint.Error(), parseErr)
- err = multierr.Append(err, wrappedErr)
- }
- return err
- }
|