From a044bb2d34e5de507d44abae4a03ab6f2d29c548 Mon Sep 17 00:00:00 2001 From: George Tsilias Date: Thu, 24 Nov 2022 18:58:31 +0200 Subject: [PATCH 1/4] promtail: Handle nil error on target Details() call --- clients/pkg/promtail/targets/docker/target.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clients/pkg/promtail/targets/docker/target.go b/clients/pkg/promtail/targets/docker/target.go index 71837e8b7dd2..92d50b24a6c3 100644 --- a/clients/pkg/promtail/targets/docker/target.go +++ b/clients/pkg/promtail/targets/docker/target.go @@ -251,9 +251,13 @@ func (t *Target) Labels() model.LabelSet { // Details returns target-specific details. func (t *Target) Details() interface{} { + var errMsg string + if t.err != nil { + errMsg = fmt.Sprintf("%v", t.err.Error()) + } return map[string]string{ "id": t.containerName, - "error": t.err.Error(), + "error": errMsg, "position": t.positions.GetString(positions.CursorKey(t.containerName)), "running": strconv.FormatBool(t.running.Load()), } From fbe2340f726d1bd37c0d43a7905987efe45aa5cd Mon Sep 17 00:00:00 2001 From: George Tsilias Date: Thu, 24 Nov 2022 19:30:42 +0200 Subject: [PATCH 2/4] promtail: Handle nil error on cloudflare target Details() call --- clients/pkg/promtail/targets/cloudflare/target.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clients/pkg/promtail/targets/cloudflare/target.go b/clients/pkg/promtail/targets/cloudflare/target.go index 2cb4cea97493..02190c929412 100644 --- a/clients/pkg/promtail/targets/cloudflare/target.go +++ b/clients/pkg/promtail/targets/cloudflare/target.go @@ -3,6 +3,7 @@ package cloudflare import ( "context" "errors" + "fmt" "regexp" "strings" "sync" @@ -224,9 +225,13 @@ func (t *Target) Ready() bool { func (t *Target) Details() interface{} { fields, _ := Fields(FieldsType(t.config.FieldsType)) + var errMsg string + if t.err != nil { + errMsg = fmt.Sprintf("%v", t.err.Error()) + } return map[string]string{ "zone_id": t.config.ZoneID, - "error": t.err.Error(), + "error": errMsg, "position": t.positions.GetString(positions.CursorKey(t.config.ZoneID)), "last_timestamp": t.to.String(), "fields": strings.Join(fields, ","), From b5fcc471743ea76090dacae885d51a4b6550b89f Mon Sep 17 00:00:00 2001 From: George Tsilias Date: Thu, 24 Nov 2022 19:37:57 +0200 Subject: [PATCH 3/4] Don't wrap non-nil err with Sprintf --- clients/pkg/promtail/targets/cloudflare/target.go | 3 +-- clients/pkg/promtail/targets/docker/target.go | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/clients/pkg/promtail/targets/cloudflare/target.go b/clients/pkg/promtail/targets/cloudflare/target.go index 02190c929412..d1bc2cd9af4f 100644 --- a/clients/pkg/promtail/targets/cloudflare/target.go +++ b/clients/pkg/promtail/targets/cloudflare/target.go @@ -3,7 +3,6 @@ package cloudflare import ( "context" "errors" - "fmt" "regexp" "strings" "sync" @@ -227,7 +226,7 @@ func (t *Target) Details() interface{} { fields, _ := Fields(FieldsType(t.config.FieldsType)) var errMsg string if t.err != nil { - errMsg = fmt.Sprintf("%v", t.err.Error()) + errMsg = t.err.Error() } return map[string]string{ "zone_id": t.config.ZoneID, diff --git a/clients/pkg/promtail/targets/docker/target.go b/clients/pkg/promtail/targets/docker/target.go index 92d50b24a6c3..329827e5b61c 100644 --- a/clients/pkg/promtail/targets/docker/target.go +++ b/clients/pkg/promtail/targets/docker/target.go @@ -253,7 +253,7 @@ func (t *Target) Labels() model.LabelSet { func (t *Target) Details() interface{} { var errMsg string if t.err != nil { - errMsg = fmt.Sprintf("%v", t.err.Error()) + errMsg = t.err.Error() } return map[string]string{ "id": t.containerName, From 264c4348a57f8712a1770874b77367fd660ce205 Mon Sep 17 00:00:00 2001 From: George Tsilias Date: Wed, 30 Nov 2022 09:28:27 +0200 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82489eff6754..4ea046b20315 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ ##### Enhancements ##### Fixes +* [7771](https://github.com/grafana/loki/pull/7771) **GeorgeTsilias**: Handle nil error on target Details() call. ##### Changes * [7587](https://github.com/grafana/loki/pull/7587) **mar4uk**: Add go build tag `promtail_journal_enabled` to include/exclude Promtail journald code from binary.