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

Function setupConfig

integration/util/harness_config_overlay.go:63–117  ·  view source on GitHub ↗

setupConfig loads and merges config files, creates the overrides file, and validates the config

(t *testing.T, s *e2e.Scenario, config *TestHarnessConfig, requestedBackend string, harness *TempoHarness)

Source from the content-addressed store, hash-verified

61
62// setupConfig loads and merges config files, creates the overrides file, and validates the config
63func setupConfig(t *testing.T, s *e2e.Scenario, config *TestHarnessConfig, requestedBackend string, harness *TempoHarness) app.Config {
64 t.Helper()
65
66 // Initialize template data if needed
67 if config.ConfigTemplateData == nil {
68 config.ConfigTemplateData = make(map[string]any)
69 }
70
71 // Call ConfigTemplateFunc if provided to populate template data
72 if config.PreStartHook != nil {
73 err := config.PreStartHook(s, config.ConfigTemplateData)
74 require.NoError(t, err, "failed to execute config template function")
75 }
76
77 // Copy base config to shared directory
78 baseConfigPath := baseConfigFile
79 err := CopyFileToSharedDir(s, baseConfigPath, tempoConfigFile)
80 require.NoError(t, err, "failed to copy base config to shared dir")
81
82 // Apply single binary specific config if in single binary mode
83 if config.DeploymentMode == DeploymentModeSingleBinary {
84 err := applyConfigOverlay(s, singleBinaryConfigFile, nil)
85 require.NoError(t, err, "failed to apply single binary config overlay")
86 }
87
88 // backend overlay
89 if requestedBackend != backend.Local {
90 backendOverlay := fmt.Sprintf(backendConfigFile, requestedBackend)
91 err := applyConfigOverlay(s, backendOverlay, nil)
92 require.NoError(t, err, "failed to apply backend config overlay", requestedBackend)
93 }
94
95 // Apply config overlay if provided
96 if config.ConfigOverlay != "" {
97 err := applyConfigOverlay(s, config.ConfigOverlay, config.ConfigTemplateData)
98 require.NoError(t, err, "failed to apply config overlay")
99 }
100
101 // Create empty overrides file
102 overridesPath := sharedContainerPath(s, tempoOverridesFile)
103 err = os.WriteFile(overridesPath, []byte("overrides: {}\n"), 0o644) // nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
104 require.NoError(t, err, "failed to write initial overrides file")
105 harness.overridesPath = overridesPath
106
107 // Read and parse the final config
108 configPath := sharedContainerPath(s, tempoConfigFile)
109 configBytes, err := os.ReadFile(configPath)
110 require.NoError(t, err, "failed to read merged config file")
111
112 var cfg app.Config
113 err = yaml.UnmarshalStrict(configBytes, &cfg)
114 require.NoError(t, err, "failed to unmarshal merged config into app.Config")
115
116 return cfg
117}
118
119// applyConfigOverlay applies a config overlay file onto the shared config.yaml file,
120// with optional template rendering. The overlay is merged onto the existing shared config

Callers 1

runTempoHarnessFunction · 0.85

Calls 3

CopyFileToSharedDirFunction · 0.85
applyConfigOverlayFunction · 0.85
sharedContainerPathFunction · 0.85

Tested by

no test coverage detected