chore: pass context aware logger to collectors (#1582)

This commit is contained in:
Jan-Otto Kröpke
2024-08-24 19:14:38 +02:00
committed by GitHub
parent fbead0fb79
commit 89c832feb0
65 changed files with 876 additions and 1164 deletions

View File

@@ -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)
}