config.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package mezmoexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/mezmoexporter"
  4. import (
  5. "fmt"
  6. "net/url"
  7. "time"
  8. "go.opentelemetry.io/collector/config/confighttp"
  9. "go.opentelemetry.io/collector/config/configopaque"
  10. "go.opentelemetry.io/collector/exporter/exporterhelper"
  11. )
  12. const (
  13. // defaultTimeout
  14. defaultTimeout time.Duration = 5 * time.Second
  15. // defaultIngestURL
  16. defaultIngestURL = "https://logs.mezmo.com/otel/ingest/rest"
  17. // See https://docs.mezmo.com/docs/Mezmo-ingestion-service-limits for details
  18. // Maximum payload in bytes that can be POST'd to the REST endpoint
  19. maxBodySize = 10 * 1024 * 1024
  20. maxMessageSize = 16 * 1024
  21. maxMetaDataSize = 32 * 1024
  22. maxAppnameLen = 512
  23. maxLogLevelLen = 80
  24. )
  25. // Config defines configuration for Mezmo exporter.
  26. type Config struct {
  27. confighttp.HTTPClientSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct.
  28. exporterhelper.QueueSettings `mapstructure:"sending_queue"`
  29. exporterhelper.RetrySettings `mapstructure:"retry_on_failure"`
  30. // IngestURL is the URL to send telemetry to.
  31. IngestURL string `mapstructure:"ingest_url"`
  32. // Token is the authentication token provided by Mezmo.
  33. IngestKey configopaque.String `mapstructure:"ingest_key"`
  34. }
  35. // returns default http client settings
  36. func createDefaultHTTPClientSettings() confighttp.HTTPClientSettings {
  37. return confighttp.HTTPClientSettings{
  38. Timeout: defaultTimeout,
  39. }
  40. }
  41. func (c *Config) Validate() error {
  42. var err error
  43. var parsed *url.URL
  44. parsed, err = url.Parse(c.IngestURL)
  45. if c.IngestURL == "" || err != nil {
  46. return fmt.Errorf(`"ingest_url" must be a valid URL`)
  47. }
  48. if parsed.Host == "" {
  49. return fmt.Errorf(`"ingest_url" must contain a valid host`)
  50. }
  51. return nil
  52. }