Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with doubled labels in the response #74

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Thanks to @yincongcyincong for [the pull request](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/69).

* BUGFIX: correctly pass time range filter when querying variable values. Before, time filter wasn't applied for `/field_values` and `/field_names` API calls. See [this](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/71) and [this](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/72) issues.
* BUGFIX: fix the issue of collecting labels in different log lines. Removed duplicated labels from previous log lines. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/60).
dmitryk-dk marked this conversation as resolved.
Show resolved Hide resolved

## v0.4.0

Expand Down
1 change: 1 addition & 0 deletions pkg/plugin/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func parseStreamResponse(reader io.Reader) backend.DataResponse {
return newResponseError(err, backend.StatusInternal)
}
labelsField.Append(d)
labels = data.Labels{}
dmitryk-dk marked this conversation as resolved.
Show resolved Hide resolved
}

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

return rsp
},
},
{
name: "new test",
response: `{"_time": "2024-09-10T12:24:38.124811Z","_stream_id": "00000000000000002e3bd2bdc376279a6418761ca20c417c","_stream": "{path=\"/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log\",stream=\"stderr\"}","_msg": "1","path": "/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log","stream": "stderr","time": "2024-09-10T12:24:38.124811792Z"}
{"_time": "2024-09-10T12:36:10.664553169Z","_stream_id": "0000000000000000356bfe9e3c71128c750d94c15df6b908","_stream": "{stream=\"stream1\"}","_msg": "2","date": "0","stream": "stream1","log.level": "info"}
{"_time": "2024-09-10T13:06:56.45147Z","_stream_id": "00000000000000002e3bd2bdc376279a6418761ca20c417c","_stream": "{path=\"/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log\",stream=\"stderr\"}","_msg": "3","path": "/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log","stream": "stderr","time": "2024-09-10T13:06:56.451470093Z"}`,
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

timeFd.Append(time.Date(2024, 9, 10, 12, 24, 38, 124000000, time.UTC))
timeFd.Append(time.Date(2024, 9, 10, 12, 36, 10, 664000000, time.UTC))
timeFd.Append(time.Date(2024, 9, 10, 13, 06, 56, 451000000, time.UTC))

lineField.Append("1")

labels := data.Labels{
"_stream_id": "00000000000000002e3bd2bdc376279a6418761ca20c417c",
"path": "/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log",
"stream": "stderr",
"time": "2024-09-10T12:24:38.124811792Z",
}

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

lineField.Append("2")

labels = data.Labels{
"_stream_id": "0000000000000000356bfe9e3c71128c750d94c15df6b908",
"date": "0",
"stream": "stream1",
"log.level": "info",
}

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

lineField.Append("3")

labels = data.Labels{
"_stream_id": "00000000000000002e3bd2bdc376279a6418761ca20c417c",
"path": "/var/lib/docker/containers/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89/c01cbe414773fa6b3e4e0976fb27c3583b1a5cd4b7007662477df66987f97f89-json.log",
"stream": "stderr",
"time": "2024-09-10T13:06:56.451470093Z",
}

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 All @@ -369,6 +433,7 @@ func Test_parseStreamResponse(t *testing.T) {
if len(resp.Frames) != 1 {
t.Fatalf("expected for response to always contain 1 Frame; got %d", len(resp.Frames))
}

got := resp.Frames[0]
want := w.Frames[0]
expFieldsLen := got.Fields[0].Len()
Expand Down
Loading