in confgenerator/config.go [164:196]
func ReadConfigFromFile(ctx context.Context, path string) (*RunMonitoringConfig, error) {
config := DefaultRunMonitoringConfig()
// Fetch metadata from the available environment variables.
config.Env = fetchMetadata()
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
log.Println("confgenerator: no user config file found, using default config")
return config, nil
}
return nil, fmt.Errorf("failed to retrieve the user config file %q: %w", path, err)
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
log.Printf("confgenerator: using RunMonitoring config:\n%s", string(data))
// Unmarshal the user config over the default config. If some options are unspecified
// the collector uses the default settings for those options. For example, if not specified
// targetLabels is set to {"revision", "service", "configuration"}
if err := yaml.UnmarshalContext(ctx, data, config, yaml.Strict()); err != nil {
return nil, err
}
// Validate the RunMonitoring config
if err := config.Validate(); err != nil {
return nil, err
}
return config, nil
}