Debian Codegraph @

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

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package migration // import "go.opentelemetry.io/collector/service/telemetry/internal/migration"
5
6 import (
7 configv02 "go.opentelemetry.io/contrib/otelconf/v0.2.0"
8 config "go.opentelemetry.io/contrib/otelconf/v0.3.0"
9 "go.uber.org/zap/zapcore"
10
11 "go.opentelemetry.io/collector/config/configtelemetry"
12 )
13
14 type tracesConfigV020 struct {
15 Level configtelemetry.Level `mapstructure:"level"`
16 Propagators []string `mapstructure:"propagators"`
17 Processors []configv02.SpanProcessor `mapstructure:"processors"`
18 }
19
20 type metricsConfigV020 struct {
21 Level configtelemetry.Level `mapstructure:"level"`
22 Readers []configv02.MetricReader `mapstructure:"readers"`
23 }
24
25 type logsConfigV020 struct {
26 Level zapcore.Level `mapstructure:"level"`
27 Development bool `mapstructure:"development"`
28 Encoding string `mapstructure:"encoding"`
29 DisableCaller bool `mapstructure:"disable_caller"`
30 DisableStacktrace bool `mapstructure:"disable_stacktrace"`
31 Sampling *LogsSamplingConfig `mapstructure:"sampling"`
32 OutputPaths []string `mapstructure:"output_paths"`
33 ErrorOutputPaths []string `mapstructure:"error_output_paths"`
34 InitialFields map[string]any `mapstructure:"initial_fields"`
35 Processors []configv02.LogRecordProcessor `mapstructure:"processors"`
36 }
37
38 func headersV02ToV03(in configv02.Headers) []config.NameStringValuePair {
39 headers := make([]config.NameStringValuePair, 0, len(in))
40 for k, v := range in {
41 headers = append(headers, config.NameStringValuePair{
42 Name: k,
43 Value: &v,
44 })
45 }
46 return headers
47 }
48
49 func otlpV02ToV03(in *configv02.OTLP) *config.OTLP {
50 if in == nil {
51 return nil
52 }
53 return &config.OTLP{
54 Certificate: in.Certificate,
55 ClientCertificate: in.ClientCertificate,
56 ClientKey: in.ClientKey,
57 Compression: in.Compression,
58 Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure),
59 Insecure: in.Insecure,
60 Protocol: &in.Protocol,
61 Timeout: in.Timeout,
62 Headers: headersV02ToV03(in.Headers),
63 }
64 }
65
66 func otlpMetricV02ToV03(in *configv02.OTLPMetric) *config.OTLPMetric {
67 if in == nil {
68 return nil
69 }
70 return &config.OTLPMetric{
71 Certificate: in.Certificate,
72 ClientCertificate: in.ClientCertificate,
73 ClientKey: in.ClientKey,
74 Compression: in.Compression,
75 Endpoint: normalizeEndpoint(in.Endpoint, in.Insecure),
76 Insecure: in.Insecure,
77 Protocol: &in.Protocol,
78 Timeout: in.Timeout,
79 Headers: headersV02ToV03(in.Headers),
80 }
81 }
82
83 func zipkinV02ToV03(in *configv02.Zipkin) *config.Zipkin {
84 if in == nil {
85 return nil
86 }
87 return &config.Zipkin{
88 Endpoint: &in.Endpoint,
89 Timeout: in.Timeout,
90 }
91 }
92
93 func tracesConfigV02ToV03(v2 tracesConfigV020, v3 *TracesConfigV030) error {
94 processors := make([]config.SpanProcessor, len(v2.Processors))
95 for idx, p := range v2.Processors {
96 processors[idx] = config.SpanProcessor{}
97 if p.Batch != nil {
98 processors[idx].Batch = &config.BatchSpanProcessor{
99 ExportTimeout: p.Batch.ExportTimeout,
100 MaxExportBatchSize: p.Batch.MaxExportBatchSize,
101 MaxQueueSize: p.Batch.MaxQueueSize,
102 ScheduleDelay: p.Batch.ScheduleDelay,
103 Exporter: config.SpanExporter{
104 Console: config.Console(p.Batch.Exporter.Console),
105 OTLP: otlpV02ToV03(p.Batch.Exporter.OTLP),
106 Zipkin: zipkinV02ToV03(p.Batch.Exporter.Zipkin),
107 AdditionalProperties: p.Batch.Exporter.AdditionalProperties,
108 },
109 }
110 }
111 if p.Simple != nil {
112 processors[idx].Simple = &config.SimpleSpanProcessor{
113 Exporter: config.SpanExporter{
114 Console: config.Console(p.Simple.Exporter.Console),
115 OTLP: otlpV02ToV03(p.Simple.Exporter.OTLP),
116 Zipkin: zipkinV02ToV03(p.Simple.Exporter.Zipkin),
117 AdditionalProperties: p.Simple.Exporter.AdditionalProperties,
118 },
119 }
120 }
121 processors[idx].AdditionalProperties = p.AdditionalProperties
122 }
123 v3.Level = v2.Level
124 v3.Propagators = v2.Propagators
125 v3.Processors = processors
126 return nil
127 }
128
129 func prometheusV02ToV03(in *configv02.Prometheus) *config.Prometheus {
130 if in == nil {
131 return nil
132 }
133 return &config.Prometheus{
134 Host: in.Host,
135 Port: in.Port,
136 WithoutScopeInfo: in.WithoutScopeInfo,
137 WithoutUnits: in.WithoutUnits,
138 WithoutTypeSuffix: in.WithoutTypeSuffix,
139 WithResourceConstantLabels: (*config.IncludeExclude)(in.WithResourceConstantLabels),
140 }
141 }
142
143 func metricsConfigV02ToV03(v2 metricsConfigV020, v3 *MetricsConfigV030) error {
144 readers := make([]config.MetricReader, len(v2.Readers))
145 for idx, p := range v2.Readers {
146 readers[idx] = config.MetricReader{}
147 if p.Periodic != nil {
148 readers[idx].Periodic = &config.PeriodicMetricReader{
149 Interval: p.Periodic.Interval,
150 Timeout: p.Periodic.Timeout,
151 Exporter: config.PushMetricExporter{
152 Console: config.Console(p.Periodic.Exporter.Console),
153 OTLP: otlpMetricV02ToV03(p.Periodic.Exporter.OTLP),
154 AdditionalProperties: p.Periodic.Exporter.AdditionalProperties,
155 },
156 }
157 }
158 if p.Pull != nil {
159 readers[idx].Pull = &config.PullMetricReader{
160 Exporter: config.PullMetricExporter{
161 Prometheus: prometheusV02ToV03(p.Pull.Exporter.Prometheus),
162 AdditionalProperties: p.Pull.Exporter.AdditionalProperties,
163 },
164 }
165 }
166 }
167 v3.Level = v2.Level
168 v3.Readers = readers
169 return nil
170 }
171
172 func logsConfigV02ToV03(v2 logsConfigV020, v3 *LogsConfigV030) error {
173 processors := make([]config.LogRecordProcessor, len(v2.Processors))
174 for idx, p := range v2.Processors {
175 processors[idx] = config.LogRecordProcessor{}
176 if p.Batch != nil {
177 processors[idx].Batch = &config.BatchLogRecordProcessor{
178 ExportTimeout: p.Batch.ExportTimeout,
179 MaxExportBatchSize: p.Batch.MaxExportBatchSize,
180 MaxQueueSize: p.Batch.MaxQueueSize,
181 ScheduleDelay: p.Batch.ScheduleDelay,
182 Exporter: config.LogRecordExporter{
183 Console: config.Console(p.Batch.Exporter.Console),
184 OTLP: otlpV02ToV03(p.Batch.Exporter.OTLP),
185 AdditionalProperties: p.Batch.Exporter.AdditionalProperties,
186 },
187 }
188 }
189 if p.Simple != nil {
190 processors[idx].Simple = &config.SimpleLogRecordProcessor{
191 Exporter: config.LogRecordExporter{
192 Console: config.Console(p.Simple.Exporter.Console),
193 OTLP: otlpV02ToV03(p.Simple.Exporter.OTLP),
194 AdditionalProperties: p.Simple.Exporter.AdditionalProperties,
195 },
196 }
197 }
198 processors[idx].AdditionalProperties = p.AdditionalProperties
199 }
200 v3.Level = v2.Level
201 v3.Development = v2.Development
202 v3.Encoding = v2.Encoding
203 v3.DisableCaller = v2.DisableCaller
204 v3.DisableStacktrace = v2.DisableStacktrace
205 v3.Sampling = v2.Sampling
206 v3.OutputPaths = v2.OutputPaths
207 v3.ErrorOutputPaths = v2.ErrorOutputPaths
208 v3.InitialFields = v2.InitialFields
209 v3.Processors = processors
210 return nil
211 }