Skip to content

Commit

Permalink
promtail: Handle nil error on target Details() call (#7771)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
This PR addresses issue [#6930](#6930).
Promtail should not panic when the Details() method is called for a target that has no errors.

**Which issue(s) this PR fixes**:
Fixes #6930
  • Loading branch information
GeorgeTsilias authored Nov 30, 2022
1 parent 30ddd77 commit d3615f7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* [7602](https://github.com/grafana/loki/pull/7602) **vmax**: Add decolorize stage to Promtail to easily parse colored logs.

##### Fixes
* [7771](https://github.com/grafana/loki/pull/7771) **GeorgeTsilias**: Handle nil error on target Details() call.

* [7461](https://github.com/grafana/loki/pull/7461) **MarNicGit**: Promtail: Fix collecting userdata field from Windows Event Log

Expand Down
6 changes: 5 additions & 1 deletion clients/pkg/promtail/targets/cloudflare/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,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 = 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, ","),
Expand Down
6 changes: 5 additions & 1 deletion clients/pkg/promtail/targets/docker/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 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()),
}
Expand Down

0 comments on commit d3615f7

Please sign in to comment.