in collector/receiver/prometheusreceiver/config.go [133:160]
func checkSDFile(filename string) error {
content, err := os.ReadFile(filepath.Clean(filename))
if err != nil {
return err
}
var targetGroups []*targetgroup.Group
switch ext := filepath.Ext(filename); strings.ToLower(ext) {
case ".json":
if err := json.Unmarshal(content, &targetGroups); err != nil {
return fmt.Errorf("error in unmarshaling json file extension: %w", err)
}
case ".yml", ".yaml":
if err := yaml.UnmarshalStrict(content, &targetGroups); err != nil {
return fmt.Errorf("error in unmarshaling yaml file extension: %w", err)
}
default:
return fmt.Errorf("invalid file extension: %q", ext)
}
for i, tg := range targetGroups {
if tg == nil {
return fmt.Errorf("nil target group item found (index %d)", i)
}
}
return nil
}