MCPcopy Index your code
hub / github.com/prometheus/prometheus / LoadFile

Function LoadFile

config/config.go:131–157  ·  view source on GitHub ↗

LoadFile parses and validates the given YAML file into a read-only Config. Callers should never write to or shallow copy the returned Config.

(filename string, agentMode bool, logger *slog.Logger)

Source from the content-addressed store, hash-verified

129// LoadFile parses and validates the given YAML file into a read-only Config.
130// Callers should never write to or shallow copy the returned Config.
131func LoadFile(filename string, agentMode bool, logger *slog.Logger) (*Config, error) {
132 content, err := os.ReadFile(filename)
133 if err != nil {
134 return nil, err
135 }
136 cfg, err := Load(string(content), logger)
137 if err != nil {
138 return nil, fmt.Errorf("parsing YAML file %s: %w", filename, err)
139 }
140
141 if agentMode {
142 if len(cfg.AlertingConfig.AlertmanagerConfigs) > 0 || len(cfg.AlertingConfig.AlertRelabelConfigs) > 0 {
143 return nil, errors.New("field alerting is not allowed in agent mode")
144 }
145
146 if len(cfg.RuleFiles) > 0 {
147 return nil, errors.New("field rule_files is not allowed in agent mode")
148 }
149
150 if len(cfg.RemoteReadConfigs) > 0 {
151 return nil, errors.New("field remote_read is not allowed in agent mode")
152 }
153 }
154
155 cfg.SetDirectory(filepath.Dir(filename))
156 return cfg, nil
157}
158
159func boolPtr(b bool) *bool {
160 return &b

Callers 15

mainFunction · 0.92
reloadConfigFunction · 0.92
CheckSDFunction · 0.92
checkConfigFunction · 0.92
TestYAMLRoundtripFunction · 0.85

Calls 3

LoadFunction · 0.85
SetDirectoryMethod · 0.45
DirMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…