From b4ee1ac942e7c5201d04ec22a7af9185c7af244b Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Fri, 1 Nov 2024 12:49:45 +0000 Subject: [PATCH] Remove obsolete translations for converting log.printf to error messages Signed-off-by: Richard Wall --- pkg/logs/logs.go | 7 +----- pkg/logs/logs_test.go | 52 +++++++++---------------------------------- 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/pkg/logs/logs.go b/pkg/logs/logs.go index 9dd988b8..b16c62e1 100644 --- a/pkg/logs/logs.go +++ b/pkg/logs/logs.go @@ -147,12 +147,7 @@ func (w LogToSlogWriter) Write(p []byte) (n int, err error) { message := string(p) if strings.Contains(message, "error") || - strings.Contains(message, "failed") || - strings.Contains(message, "fatal") || - strings.Contains(message, "Failed") || - strings.Contains(message, "While evaluating configuration") || - strings.Contains(message, "data-path override present") || - strings.Contains(message, "Cannot marshal readings") { + strings.Contains(message, "failed") { w.Slog.With("source", w.Source).Error(message) } else { w.Slog.With("source", w.Source).Info(message) diff --git a/pkg/logs/logs_test.go b/pkg/logs/logs_test.go index 3ddd6da1..58a74725 100644 --- a/pkg/logs/logs_test.go +++ b/pkg/logs/logs_test.go @@ -375,52 +375,22 @@ func Test_replaceWithStaticTimestamps(t *testing.T) { } func TestLogToSlogWriter(t *testing.T) { - // This test makes sure that all the agent's Log.Fatalf calls are correctly - // translated to slog.Error calls. + // This test makes sure that all the agent's remaining Log calls are correctly + // translated to slog.Error calls where appropriate. // // This list was generated using: - // grep -r "Log\.Fatalf" ./cmd ./pkg + // git grep -i "log\.\(print\|fatal\)" pkg/ cmd/ | fgrep -e error -e failed given := strings.TrimPrefix(` -Failed to load config file for agent from -Failed to read config file -Failed to parse config file -While evaluating configuration -failed to run pprof profiler -failed to run the health check server -failed to start a controller-runtime component -failed to wait for controller-runtime component to stop -running data gatherer %s of type %s as Local, data-path override present -failed to instantiate %q data gatherer -failed to read local data file -failed to unmarshal local data file -failed to output to local file -Exiting due to fatal error uploading -halting datagathering in strict mode due to error -Cannot marshal readings -Failed to read config file -Failed to parse config file -Failed to validate data gatherers +failed to complete initial sync of %q data gatherer %q: %v +error messages will not show in the pod's events because the POD_NAME environment variable is empty +retrying in %v after error: %s +datagatherer informer for %q has failed and is backing off due to error: %s this is a happy log that should show as INFO`, "\n") expect := strings.TrimPrefix(` -level=ERROR msg="Failed to load config file for agent from" source=agent -level=ERROR msg="Failed to read config file" source=agent -level=ERROR msg="Failed to parse config file" source=agent -level=ERROR msg="While evaluating configuration" source=agent -level=ERROR msg="failed to run pprof profiler" source=agent -level=ERROR msg="failed to run the health check server" source=agent -level=ERROR msg="failed to start a controller-runtime component" source=agent -level=ERROR msg="failed to wait for controller-runtime component to stop" source=agent -level=ERROR msg="running data gatherer %!s(MISSING) of type %!s(MISSING) as Local, data-path override present" source=agent -level=ERROR msg="failed to instantiate %!q(MISSING) data gatherer" source=agent -level=ERROR msg="failed to read local data file" source=agent -level=ERROR msg="failed to unmarshal local data file" source=agent -level=ERROR msg="failed to output to local file" source=agent -level=ERROR msg="Exiting due to fatal error uploading" source=agent -level=ERROR msg="halting datagathering in strict mode due to error" source=agent -level=ERROR msg="Cannot marshal readings" source=agent -level=ERROR msg="Failed to read config file" source=agent -level=ERROR msg="Failed to parse config file" source=agent -level=ERROR msg="Failed to validate data gatherers" source=agent +level=ERROR msg="failed to complete initial sync of %!q(MISSING) data gatherer %!q(MISSING): %!v(MISSING)" source=agent +level=ERROR msg="error messages will not show in the pod's events because the POD_NAME environment variable is empty" source=agent +level=ERROR msg="retrying in %!v(MISSING) after error: %!s(MISSING)" source=agent +level=ERROR msg="datagatherer informer for %!q(MISSING) has failed and is backing off due to error: %!s(MISSING)" source=agent level=INFO msg="this is a happy log that should show as INFO" source=agent `, "\n")