MCPcopy Index your code
hub / github.com/cortexproject/cortex / LoadConfig

Function LoadConfig

cmd/cortex/main.go:246–268  ·  view source on GitHub ↗

LoadConfig read YAML-formatted config from filename into cfg.

(filename string, expandENV bool, cfg *cortex.Config)

Source from the content-addressed store, hash-verified

244
245// LoadConfig read YAML-formatted config from filename into cfg.
246func LoadConfig(filename string, expandENV bool, cfg *cortex.Config) error {
247 buf, err := os.ReadFile(filename)
248 if err != nil {
249 return errors.Wrap(err, "Error reading config file")
250 }
251
252 // create a sha256 hash of the config before expansion and expose it via
253 // the config_info metric
254 hash := sha256.Sum256(buf)
255 configHash.Reset()
256 configHash.WithLabelValues(fmt.Sprintf("%x", hash)).Set(1)
257
258 if expandENV {
259 buf = expandEnv(buf)
260 }
261
262 err = yaml.UnmarshalStrict(buf, cfg)
263 if err != nil {
264 return errors.Wrap(err, "Error parsing config file")
265 }
266
267 return nil
268}
269
270func DumpYaml(cfg *cortex.Config) {
271 out, err := yaml.Marshal(cfg)

Callers 1

mainFunction · 0.70

Calls 4

expandEnvFunction · 0.85
WrapMethod · 0.65
SetMethod · 0.65
ResetMethod · 0.45

Tested by

no test coverage detected