| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package migration |
| 5 |
|
| 6 |
import ( |
| 7 |
"time" |
| 8 |
|
| 9 |
config "go.opentelemetry.io/contrib/otelconf/v0.3.0" |
| 10 |
"go.uber.org/zap/zapcore" |
| 11 |
|
| 12 |
"go.opentelemetry.io/collector/config/configtelemetry" |
| 13 |
"go.opentelemetry.io/collector/confmap" |
| 14 |
) |
| 15 |
|
| 16 |
type TracesConfigV030 struct { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
Level configtelemetry.Level `mapstructure:"level"` |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
Propagators []string `mapstructure:"propagators"` |
| 25 |
|
| 26 |
config.TracerProvider `mapstructure:",squash"` |
| 27 |
} |
| 28 |
|
| 29 |
func (c *TracesConfigV030) Unmarshal(conf *confmap.Conf) error { |
| 30 |
unmarshaled := *c |
| 31 |
if err := conf.Unmarshal(c); err != nil { |
| 32 |
v2TracesConfig := tracesConfigV020{ |
| 33 |
Level: unmarshaled.Level, |
| 34 |
Propagators: unmarshaled.Propagators, |
| 35 |
} |
| 36 |
|
| 37 |
if e := conf.Unmarshal(&v2TracesConfig); e != nil { |
| 38 |
|
| 39 |
|
| 40 |
return err |
| 41 |
} |
| 42 |
|
| 43 |
return tracesConfigV02ToV03(v2TracesConfig, c) |
| 44 |
} |
| 45 |
|
| 46 |
for _, r := range c.Processors { |
| 47 |
if r.Batch != nil { |
| 48 |
if r.Batch.Exporter.OTLP != nil { |
| 49 |
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure) |
| 50 |
} |
| 51 |
} |
| 52 |
if r.Simple != nil { |
| 53 |
if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil { |
| 54 |
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure) |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
return nil |
| 59 |
} |
| 60 |
|
| 61 |
type MetricsConfigV030 struct { |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
Level configtelemetry.Level `mapstructure:"level"` |
| 68 |
|
| 69 |
config.MeterProvider `mapstructure:",squash"` |
| 70 |
} |
| 71 |
|
| 72 |
func (c *MetricsConfigV030) Unmarshal(conf *confmap.Conf) error { |
| 73 |
unmarshaled := *c |
| 74 |
if err := conf.Unmarshal(c); err != nil { |
| 75 |
v02 := metricsConfigV020{ |
| 76 |
Level: unmarshaled.Level, |
| 77 |
} |
| 78 |
|
| 79 |
if e := conf.Unmarshal(&v02); e != nil { |
| 80 |
|
| 81 |
|
| 82 |
return err |
| 83 |
} |
| 84 |
|
| 85 |
return metricsConfigV02ToV03(v02, c) |
| 86 |
} |
| 87 |
|
| 88 |
for _, r := range c.Readers { |
| 89 |
if r.Periodic != nil { |
| 90 |
if r.Periodic.Exporter.OTLP != nil && r.Periodic.Exporter.OTLP.Endpoint != nil { |
| 91 |
r.Periodic.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Periodic.Exporter.OTLP.Endpoint, r.Periodic.Exporter.OTLP.Insecure) |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
return nil |
| 96 |
} |
| 97 |
|
| 98 |
type LogsConfigV030 struct { |
| 99 |
|
| 100 |
|
| 101 |
Level zapcore.Level `mapstructure:"level"` |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
Development bool `mapstructure:"development,omitempty"` |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
Encoding string `mapstructure:"encoding"` |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
DisableCaller bool `mapstructure:"disable_caller,omitempty"` |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
DisableStacktrace bool `mapstructure:"disable_stacktrace,omitempty"` |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
Sampling *LogsSamplingConfig `mapstructure:"sampling"` |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
OutputPaths []string `mapstructure:"output_paths"` |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
ErrorOutputPaths []string `mapstructure:"error_output_paths"` |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
InitialFields map[string]any `mapstructure:"initial_fields,omitempty"` |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
Processors []config.LogRecordProcessor `mapstructure:"processors,omitempty"` |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
type LogsSamplingConfig struct { |
| 171 |
|
| 172 |
Enabled bool `mapstructure:"enabled"` |
| 173 |
|
| 174 |
Tick time.Duration `mapstructure:"tick"` |
| 175 |
|
| 176 |
Initial int `mapstructure:"initial"` |
| 177 |
|
| 178 |
|
| 179 |
Thereafter int `mapstructure:"thereafter"` |
| 180 |
} |
| 181 |
|
| 182 |
func (c *LogsConfigV030) Unmarshal(conf *confmap.Conf) error { |
| 183 |
unmarshaled := *c |
| 184 |
if err := conf.Unmarshal(c); err != nil { |
| 185 |
v02 := logsConfigV020{ |
| 186 |
Level: unmarshaled.Level, |
| 187 |
Development: unmarshaled.Development, |
| 188 |
Encoding: unmarshaled.Encoding, |
| 189 |
DisableCaller: unmarshaled.DisableCaller, |
| 190 |
DisableStacktrace: unmarshaled.DisableStacktrace, |
| 191 |
Sampling: unmarshaled.Sampling, |
| 192 |
OutputPaths: unmarshaled.OutputPaths, |
| 193 |
ErrorOutputPaths: unmarshaled.ErrorOutputPaths, |
| 194 |
InitialFields: unmarshaled.InitialFields, |
| 195 |
} |
| 196 |
|
| 197 |
if e := conf.Unmarshal(&v02); e != nil { |
| 198 |
|
| 199 |
|
| 200 |
return err |
| 201 |
} |
| 202 |
|
| 203 |
return logsConfigV02ToV03(v02, c) |
| 204 |
} |
| 205 |
|
| 206 |
for _, r := range c.Processors { |
| 207 |
if r.Batch != nil { |
| 208 |
if r.Batch.Exporter.OTLP != nil { |
| 209 |
r.Batch.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Batch.Exporter.OTLP.Endpoint, r.Batch.Exporter.OTLP.Insecure) |
| 210 |
} |
| 211 |
} |
| 212 |
if r.Simple != nil { |
| 213 |
if r.Simple.Exporter.OTLP != nil && r.Simple.Exporter.OTLP.Endpoint != nil { |
| 214 |
r.Simple.Exporter.OTLP.Endpoint = normalizeEndpoint(*r.Simple.Exporter.OTLP.Endpoint, r.Simple.Exporter.OTLP.Insecure) |
| 215 |
} |
| 216 |
} |
| 217 |
} |
| 218 |
return nil |
| 219 |
} |