-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
config_test.go
88 lines (78 loc) · 2.42 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package googlemanagedprometheusexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlemanagedprometheusexporter"
import (
"path/filepath"
"testing"
"time"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector"
"github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/otelcol/otelcoltest"
"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/googlemanagedprometheusexporter/internal/metadata"
)
func TestLoadConfig(t *testing.T) {
factories, err := otelcoltest.NopFactories()
assert.NoError(t, err)
factory := NewFactory()
factories.Exporters[metadata.Type] = factory
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/33594
// nolint:staticcheck
cfg, err := otelcoltest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories)
require.NoError(t, err)
require.NotNil(t, cfg)
assert.Len(t, cfg.Exporters, 2)
r0 := cfg.Exporters[component.NewID(metadata.Type)].(*Config)
assert.Equal(t, r0, factory.CreateDefaultConfig().(*Config))
r1 := cfg.Exporters[component.NewIDWithName(metadata.Type, "customname")].(*Config)
assert.Equal(t, &Config{
TimeoutSettings: exporterhelper.TimeoutConfig{
Timeout: 20 * time.Second,
},
GMPConfig: GMPConfig{
ProjectID: "my-project",
UserAgent: "opentelemetry-collector-contrib {{version}}",
MetricConfig: MetricConfig{
Config: googlemanagedprometheus.Config{
AddMetricSuffixes: false,
ExtraMetricsConfig: googlemanagedprometheus.ExtraMetricsConfig{
EnableTargetInfo: false,
EnableScopeInfo: false,
},
},
Prefix: "my-metric-domain.com",
ResourceFilters: []collector.ResourceFilter{
{
Prefix: "cloud",
},
{
Prefix: "k8s",
},
{
Prefix: "faas",
},
{
Regex: "container.id",
},
{
Regex: "process.pid",
},
{
Regex: "host.name",
},
{
Regex: "host.id",
},
},
},
},
QueueSettings: exporterhelper.QueueConfig{
Enabled: true,
NumConsumers: 2,
QueueSize: 10,
},
}, r1)
}