mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-02 00:26:35 +00:00
chore: pass context aware logger to collectors (#1582)
This commit is contained in:
@@ -19,15 +19,16 @@ var baseDir = "../../../tools/textfile-test"
|
||||
func TestMultipleDirectories(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := log.NewLogfmtLogger(os.Stdout)
|
||||
testDir := baseDir + "/multiple-dirs"
|
||||
testDirs := fmt.Sprintf("%[1]s/dir1,%[1]s/dir2,%[1]s/dir3", testDir)
|
||||
|
||||
textFileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
||||
textFileCollector := textfile.New(&textfile.Config{
|
||||
TextFileDirectories: strings.Split(testDirs, ","),
|
||||
})
|
||||
|
||||
collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector})
|
||||
require.NoError(t, collectors.Build())
|
||||
require.NoError(t, collectors.Build(logger))
|
||||
|
||||
scrapeContext, err := collectors.PrepareScrapeContext()
|
||||
if err != nil {
|
||||
@@ -47,7 +48,7 @@ func TestMultipleDirectories(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
err = textFileCollector.Collect(scrapeContext, metrics)
|
||||
err = textFileCollector.Collect(scrapeContext, logger, metrics)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %s", err)
|
||||
}
|
||||
@@ -62,13 +63,14 @@ func TestMultipleDirectories(t *testing.T) {
|
||||
func TestDuplicateFileName(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
logger := log.NewLogfmtLogger(os.Stdout)
|
||||
testDir := baseDir + "/duplicate-filename"
|
||||
textFileCollector := textfile.New(log.NewLogfmtLogger(os.Stdout), &textfile.Config{
|
||||
textFileCollector := textfile.New(&textfile.Config{
|
||||
TextFileDirectories: []string{testDir},
|
||||
})
|
||||
|
||||
collectors := collector.New(map[string]collector.Collector{textfile.Name: textFileCollector})
|
||||
require.NoError(t, collectors.Build())
|
||||
require.NoError(t, collectors.Build(logger))
|
||||
|
||||
scrapeContext, err := collectors.PrepareScrapeContext()
|
||||
if err != nil {
|
||||
@@ -87,7 +89,7 @@ func TestDuplicateFileName(t *testing.T) {
|
||||
got += metric.String()
|
||||
}
|
||||
}()
|
||||
err = textFileCollector.Collect(scrapeContext, metrics)
|
||||
err = textFileCollector.Collect(scrapeContext, logger, metrics)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %s", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user