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

Function applyConfigOverlay

integration/util/harness_config_overlay.go:122–184  ·  view source on GitHub ↗

applyConfigOverlay applies a config overlay file onto the shared config.yaml file, with optional template rendering. The overlay is merged onto the existing shared config and written back to shared config.yaml.

(s *e2e.Scenario, overlayPath string, templateData map[string]any)

Source from the content-addressed store, hash-verified

120// with optional template rendering. The overlay is merged onto the existing shared config
121// and written back to shared config.yaml.
122func applyConfigOverlay(s *e2e.Scenario, overlayPath string, templateData map[string]any) error {
123 configPath := sharedContainerPath(s, tempoConfigFile)
124
125 // Read and parse current shared config
126 baseBuff, err := os.ReadFile(configPath)
127 if err != nil {
128 return fmt.Errorf("failed to read shared config file: %w", err)
129 }
130
131 var baseMap map[any]any
132 err = yaml.Unmarshal(baseBuff, &baseMap)
133 if err != nil {
134 return fmt.Errorf("failed to parse shared config file: %w", err)
135 }
136
137 // If there's an overlay, apply it
138 if overlayPath != "" {
139 // Read overlay file
140 overlayBuff, err := os.ReadFile(overlayPath)
141 if err != nil {
142 return fmt.Errorf("failed to read config overlay file: %w", err)
143 }
144
145 // Apply template rendering if template data is provided
146 if len(templateData) > 0 {
147 tmpl, err := template.New("config").Parse(string(overlayBuff))
148 if err != nil {
149 return fmt.Errorf("failed to parse config overlay template: %w", err)
150 }
151
152 var renderedBuff bytes.Buffer
153 err = tmpl.Execute(&renderedBuff, templateData)
154 if err != nil {
155 return fmt.Errorf("failed to execute config overlay template: %w", err)
156 }
157
158 overlayBuff = renderedBuff.Bytes()
159 }
160
161 // Parse overlay
162 var overlayMap map[any]any
163 err = yaml.Unmarshal(overlayBuff, &overlayMap)
164 if err != nil {
165 return fmt.Errorf("failed to parse config overlay file: %w", err)
166 }
167
168 // Merge overlay onto base
169 baseMap = mergeMaps(baseMap, overlayMap)
170 }
171
172 // Marshal and write the result back to shared config
173 outputBytes, err := yaml.Marshal(baseMap)
174 if err != nil {
175 return fmt.Errorf("failed to marshal merged config: %w", err)
176 }
177
178 err = os.WriteFile(configPath, outputBytes, 0o644) // nolint:gosec // G306: Expect WriteFile permissions to be 0600 or less
179 if err != nil {

Callers 2

setupConfigFunction · 0.85

Calls 6

sharedContainerPathFunction · 0.85
BytesMethod · 0.80
mergeMapsFunction · 0.70
UnmarshalMethod · 0.65
ParseMethod · 0.65
MarshalMethod · 0.65

Tested by

no test coverage detected