validateMigratedConfig marshals the map back to YAML and attempts to unmarshal it into Tempo's Config struct for semantic validation. Returns warnings and an error if validation fails for reasons other than env var placeholders.
(m map[string]interface{})
| 339 | // it into Tempo's Config struct for semantic validation. |
| 340 | // Returns warnings and an error if validation fails for reasons other than env var placeholders. |
| 341 | func validateMigratedConfig(m map[string]interface{}) ([]string, error) { |
| 342 | var warnings []string |
| 343 | |
| 344 | yamlBytes, err := yaml.Marshal(m) |
| 345 | if err != nil { |
| 346 | return nil, fmt.Errorf("failed to marshal migrated config for validation: %w", err) |
| 347 | } |
| 348 | |
| 349 | cfg := app.Config{} |
| 350 | cfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{}) |
| 351 | |
| 352 | if err := yaml.UnmarshalStrict(yamlBytes, &cfg); err != nil { |
| 353 | if isEnvVarTypeError(err) { |
| 354 | // ${VAR} placeholders cause type errors for non-string fields. |
| 355 | // This is expected — report as warning, not fatal. |
| 356 | warnings = append(warnings, fmt.Sprintf("validation skipped for env var placeholders: %v", err)) |
| 357 | return warnings, nil |
| 358 | } |
| 359 | return nil, fmt.Errorf("migrated config failed validation: %w", err) |
| 360 | } |
| 361 | |
| 362 | if cfg.Target != "" && !validTargets[cfg.Target] { |
| 363 | targets := make([]string, 0, len(validTargets)) |
| 364 | for t := range validTargets { |
| 365 | targets = append(targets, t) |
| 366 | } |
| 367 | return nil, fmt.Errorf("migrated config has unsupported target %q; valid values are: %s", |
| 368 | cfg.Target, strings.Join(targets, ", ")) |
| 369 | } |
| 370 | |
| 371 | for _, w := range cfg.CheckConfig() { |
| 372 | warnings = append(warnings, fmt.Sprintf("validation: %s", w.Message)) |
| 373 | } |
| 374 | |
| 375 | return warnings, nil |
| 376 | } |
| 377 | |
| 378 | // validTargets is the set of valid Tempo 3.0 target values. |
| 379 | var validTargets = map[string]bool{ |