Skip to content

Commit

Permalink
fix double line response to show only numbers from the response (#46)
Browse files Browse the repository at this point in the history
* fix double line response to show only numbers from the response

* add CHANGELOG.md
  • Loading branch information
dmitryk-dk authored Jul 22, 2024
1 parent 3cbd5e9 commit c1064f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## tip

* BUGFIX: fix bug with parsing response when time field is empty but message and labels are present.
It happens when the user tries to show only stats number. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/45).

## v0.2.4

* BUGFIX: fix bug with parsing response when one of the field contains ANSI escape sequences. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/24).
Expand Down
5 changes: 0 additions & 5 deletions pkg/plugin/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ func parseStreamResponse(reader io.Reader) backend.DataResponse {
return newResponseError(err, backend.StatusInternal)
}
labelsField.Append(d)

// Grafana expects lineField to be always non-empty.
if timeFd.Len() == 0 {
lineField.Append(string(d))
}
}

// Grafana expects lineFields to be always non-empty.
Expand Down
31 changes: 31 additions & 0 deletions pkg/plugin/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,37 @@ func Test_parseStreamResponse(t *testing.T) {
frame.Meta = &data.FrameMeta{}
rsp.Frames = append(rsp.Frames, frame)

return rsp
},
},
{
name: "response has labels and message, time field is empty",
response: `{"count":"507","_msg":"507"}`,
want: func() backend.DataResponse {
labelsField := data.NewFieldFromFieldType(data.FieldTypeJSON, 0)
labelsField.Name = gLabelsField

timeFd := data.NewFieldFromFieldType(data.FieldTypeTime, 0)
timeFd.Name = gTimeField

lineField := data.NewFieldFromFieldType(data.FieldTypeString, 0)
lineField.Name = gLineField

lineField.Append("507")

labels := data.Labels{
"count": "507",
}

b, _ := labelsToJSON(labels)
labelsField.Append(b)

frame := data.NewFrame("", timeFd, lineField, labelsField)

rsp := backend.DataResponse{}
frame.Meta = &data.FrameMeta{}
rsp.Frames = append(rsp.Frames, frame)

return rsp
},
},
Expand Down

0 comments on commit c1064f9

Please sign in to comment.