MCPcopy
hub / github.com/grafana/tempo / Run

Method Run

cmd/tempo-cli/cmd-migrate-overrides-config.go:21–80  ·  view source on GitHub ↗
(*globalOptions)

Source from the content-addressed store, hash-verified

19}
20
21func (cmd *migrateOverridesConfigCmd) Run(*globalOptions) error {
22 cfg := app.Config{}
23 cfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{})
24
25 // Build the default overrides config for comparison from a separate instance
26 // to avoid shared pointers between defaultOverrides and cfg.Overrides.
27 defaultCfg := app.Config{}
28 defaultCfg.RegisterFlagsAndApplyDefaults("", &flag.FlagSet{})
29 defaultOverrides := defaultCfg.Overrides
30
31 buff, err := os.ReadFile(cmd.ConfigFile)
32 if err != nil {
33 return fmt.Errorf("failed to read configFile %s: %w", cmd.ConfigFile, err)
34 }
35
36 // Legacy overrides are automatically converted to a new format during unmarshaling
37 // via Config.UnmarshalYAML.
38 if err := yaml.UnmarshalStrict(buff, &cfg); err != nil {
39 return fmt.Errorf("failed to parse configFile %s: %w", cmd.ConfigFile, err)
40 }
41
42 // Marshal both configs to maps so we can diff them.
43 loadedMap, err := toMap(cfg.Overrides)
44 if err != nil {
45 return fmt.Errorf("failed to convert loaded overrides to map: %w", err)
46 }
47
48 defaultMap, err := toMap(defaultOverrides)
49 if err != nil {
50 return fmt.Errorf("failed to convert default overrides to map: %w", err)
51 }
52
53 // Remove keys that match the defaults so we only output user-set values.
54 removeDefaults(loadedMap, defaultMap)
55
56 result := map[string]interface{}{
57 "overrides": loadedMap,
58 }
59
60 outputBytes, err := yaml.Marshal(result)
61 if err != nil {
62 return fmt.Errorf("failed to marshal overrides: %w", err)
63 }
64
65 printWarnings(os.Stderr)
66
67 if cmd.ConfigDest != "" {
68 if err := os.WriteFile(cmd.ConfigDest, outputBytes, 0o600); err != nil {
69 return fmt.Errorf("failed to write output file: %w", err)
70 }
71 fmt.Fprintf(os.Stderr, "Migrated overrides written to %s\n", cmd.ConfigDest)
72 fmt.Fprintln(os.Stderr, "Replace the overrides section in your config file with the contents of this file.")
73 } else {
74 fmt.Fprintln(os.Stderr, "Migrated overrides config. Replace the overrides section in your config file with the output below:")
75 fmt.Fprintln(os.Stderr, "---")
76 fmt.Print(string(outputBytes))
77 }
78

Callers 1

Calls 5

toMapFunction · 0.85
removeDefaultsFunction · 0.85
printWarningsFunction · 0.85
MarshalMethod · 0.65

Tested by 1