Debian Codegraph @

service/telemetry/internal/migration/v0.2.0_test.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package migration
5
6 import (
7 "path/filepath"
8 "testing"
9
10 "github.com/stretchr/testify/require"
11 config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
12
13 "go.opentelemetry.io/collector/config/configtelemetry"
14 "go.opentelemetry.io/collector/confmap/confmaptest"
15 )
16
17 func TestUnmarshalLogsConfigV020(t *testing.T) {
18 cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_logs.yaml"))
19 require.NoError(t, err)
20
21 cfg := LogsConfigV030{
22 Encoding: "console",
23 }
24 require.NoError(t, cm.Unmarshal(&cfg))
25 require.Len(t, cfg.Processors, 3)
26 // check the endpoint is prefixed w/ https
27 require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
28 // check the endpoint is prefixed w/ http
29 require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
30 // ensure defaults set in the original config object are not lost
31 require.Equal(t, "console", cfg.Encoding)
32 }
33
34 func TestUnmarshalTracesConfigV020(t *testing.T) {
35 cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_traces.yaml"))
36 require.NoError(t, err)
37
38 cfg := TracesConfigV030{
39 Level: configtelemetry.LevelNone,
40 }
41 require.NoError(t, cm.Unmarshal(&cfg))
42 require.Len(t, cfg.Processors, 3)
43 // check the endpoint is prefixed w/ https
44 require.Equal(t, "https://127.0.0.1:4317", *cfg.Processors[0].Batch.Exporter.OTLP.Endpoint)
45 // check the endpoint is prefixed w/ http
46 require.Equal(t, "http://127.0.0.1:4317", *cfg.Processors[2].Simple.Exporter.OTLP.Endpoint)
47 // ensure defaults set in the original config object are not lost
48 require.Equal(t, configtelemetry.LevelNone, cfg.Level)
49 }
50
51 func TestUnmarshalMetricsConfigV020(t *testing.T) {
52 cm, err := confmaptest.LoadConf(filepath.Join("testdata", "v0.2.0_metrics.yaml"))
53 require.NoError(t, err)
54
55 cfg := MetricsConfigV030{
56 Level: configtelemetry.LevelBasic,
57 }
58 require.NoError(t, cm.Unmarshal(&cfg))
59 require.Len(t, cfg.Readers, 2)
60 // check the endpoint is prefixed w/ https
61 require.Equal(t, "https://127.0.0.1:4317", *cfg.Readers[0].Periodic.Exporter.OTLP.Endpoint)
62 require.ElementsMatch(t, []config.NameStringValuePair{{Name: "key1", Value: ptr("value1")}, {Name: "key2", Value: ptr("value2")}}, cfg.Readers[0].Periodic.Exporter.OTLP.Headers)
63 // ensure defaults set in the original config object are not lost
64 require.Equal(t, configtelemetry.LevelBasic, cfg.Level)
65 }
66
67 func ptr[T any](v T) *T {
68 return &v
69 }