config_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package googlemanagedprometheusexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlemanagedprometheusexporter"
  4. import (
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. "go.opentelemetry.io/collector/component"
  12. "go.opentelemetry.io/collector/exporter/exporterhelper"
  13. "go.opentelemetry.io/collector/otelcol/otelcoltest"
  14. "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlemanagedprometheusexporter/internal/metadata"
  15. )
  16. func TestLoadConfig(t *testing.T) {
  17. factories, err := otelcoltest.NopFactories()
  18. assert.Nil(t, err)
  19. factory := NewFactory()
  20. factories.Exporters[metadata.Type] = factory
  21. cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)
  22. require.NoError(t, err)
  23. require.NotNil(t, cfg)
  24. assert.Equal(t, len(cfg.Exporters), 2)
  25. r0 := cfg.Exporters[component.NewID(metadata.Type)].(*Config)
  26. assert.Equal(t, r0, factory.CreateDefaultConfig().(*Config))
  27. r1 := cfg.Exporters[component.NewIDWithName(metadata.Type, "customname")].(*Config)
  28. assert.Equal(t, r1,
  29. &Config{
  30. TimeoutSettings: exporterhelper.TimeoutSettings{
  31. Timeout: 20 * time.Second,
  32. },
  33. GMPConfig: GMPConfig{
  34. ProjectID: "my-project",
  35. UserAgent: "opentelemetry-collector-contrib {{version}}",
  36. MetricConfig: MetricConfig{
  37. Config: googlemanagedprometheus.Config{
  38. AddMetricSuffixes: false,
  39. ExtraMetricsConfig: googlemanagedprometheus.ExtraMetricsConfig{
  40. EnableTargetInfo: false,
  41. EnableScopeInfo: false,
  42. },
  43. },
  44. Prefix: "my-metric-domain.com",
  45. },
  46. },
  47. QueueSettings: exporterhelper.QueueSettings{
  48. Enabled: true,
  49. NumConsumers: 2,
  50. QueueSize: 10,
  51. },
  52. })
  53. }