sourcesFromFile reads and parses one acquisition file into DataSources.
( ctx context.Context, acquisFile string, metricsLevel metrics.AcquisitionMetricsLevel, hub *cwhub.Hub, )
| 317 | |
| 318 | // sourcesFromFile reads and parses one acquisition file into DataSources. |
| 319 | func sourcesFromFile( |
| 320 | ctx context.Context, |
| 321 | acquisFile string, |
| 322 | metricsLevel metrics.AcquisitionMetricsLevel, |
| 323 | hub *cwhub.Hub, |
| 324 | ) ([]types.DataSource, error) { |
| 325 | var sources []types.DataSource |
| 326 | |
| 327 | log.Infof("loading acquisition file : %s", acquisFile) |
| 328 | |
| 329 | yamlFile, err := os.Open(acquisFile) |
| 330 | if err != nil { |
| 331 | return nil, err |
| 332 | } |
| 333 | |
| 334 | defer yamlFile.Close() |
| 335 | |
| 336 | acquisContent, err := io.ReadAll(yamlFile) |
| 337 | if err != nil { |
| 338 | return nil, fmt.Errorf("failed to read %s: %w", acquisFile, err) |
| 339 | } |
| 340 | |
| 341 | expandedAcquis := csstring.StrictExpand(string(acquisContent), os.LookupEnv) |
| 342 | |
| 343 | documents, err := csyaml.SplitDocuments(strings.NewReader(expandedAcquis)) |
| 344 | if err != nil { |
| 345 | return nil, err |
| 346 | } |
| 347 | |
| 348 | idx := -1 |
| 349 | |
| 350 | for _, yamlDoc := range documents { |
| 351 | idx += 1 |
| 352 | |
| 353 | loc := formatConfigLocation(acquisFile, len(documents) > 1, idx) |
| 354 | |
| 355 | parsed, err := ParseSourceConfig(ctx, yamlDoc, metricsLevel, hub) |
| 356 | |
| 357 | // report data source detection, it can be required to understand an error |
| 358 | if parsed != nil { |
| 359 | if parsed.SourceMissing { |
| 360 | log.Debugf("%s: datasource type missing, detected 'source=%s'", loc, parsed.Common.Source) |
| 361 | } |
| 362 | |
| 363 | if parsed.SourceOverridden != "" { |
| 364 | log.Warnf("%s: datasource type mismatch: found '%s' but should probably be '%s'", loc, parsed.SourceOverridden, parsed.Common.Source) |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if err != nil { |
| 369 | if errors.Is(err, ErrEmptyYAMLDocument) { |
| 370 | continue |
| 371 | } |
| 372 | |
| 373 | var dserr *DataSourceUnavailableError |
| 374 | if errors.As(err, &dserr) { |
| 375 | log.Error(fmt.Errorf("%s: %w", loc, err)) |
| 376 | continue |
no test coverage detected
searching dependent graphs…