config.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package logicmonitorexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logicmonitorexporter"
  4. import (
  5. "fmt"
  6. "net/url"
  7. "go.opentelemetry.io/collector/config/confighttp"
  8. "go.opentelemetry.io/collector/config/configopaque"
  9. "go.opentelemetry.io/collector/exporter/exporterhelper"
  10. "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/resourcetotelemetry"
  11. )
  12. // Config defines configuration for LogicMonitor exporter.
  13. type Config struct {
  14. confighttp.HTTPClientSettings `mapstructure:",squash"`
  15. exporterhelper.QueueSettings `mapstructure:"sending_queue"`
  16. exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
  17. ResourceToTelemetrySettings resourcetotelemetry.Settings `mapstructure:"resource_to_telemetry_conversion"`
  18. // ApiToken of Logicmonitor Platform
  19. APIToken APIToken `mapstructure:"api_token"`
  20. }
  21. type APIToken struct {
  22. AccessID string `mapstructure:"access_id"`
  23. AccessKey configopaque.String `mapstructure:"access_key"`
  24. }
  25. func (c *Config) Validate() error {
  26. if c.Endpoint == "" {
  27. return fmt.Errorf("Endpoint should not be empty")
  28. }
  29. u, err := url.Parse(c.Endpoint)
  30. if err != nil || u.Scheme == "" || u.Host == "" {
  31. return fmt.Errorf("Endpoint must be valid")
  32. }
  33. return nil
  34. }