diff --git a/pkg/tsdb/loki/frame.go b/pkg/tsdb/loki/frame.go index aa574270c1c..4be11e1813e 100644 --- a/pkg/tsdb/loki/frame.go +++ b/pkg/tsdb/loki/frame.go @@ -128,7 +128,7 @@ func adjustLogsFrame(frame *data.Frame, query *lokiQuery) error { // so we send a separate timestamp-as-string field too. it is provided by the // loki-json-parser-code - idField, err := makeIdField(stringTimeField, lineField, labelsField, frame.RefID) + idField, err := makeIdField(stringTimeField, lineField, labelsField, query.RefID) if err != nil { return err } diff --git a/pkg/tsdb/loki/frame_test.go b/pkg/tsdb/loki/frame_test.go index 430db3b1330..e1f57f85a1d 100644 --- a/pkg/tsdb/loki/frame_test.go +++ b/pkg/tsdb/loki/frame_test.go @@ -66,11 +66,10 @@ func TestAdjustFrame(t *testing.T) { }), ) - frame.RefID = "A" - query := &lokiQuery{ Expr: `{type="important"}`, QueryType: QueryTypeRange, + RefID: "A", } err := adjustFrame(frame, query) diff --git a/pkg/tsdb/loki/framing_test.go b/pkg/tsdb/loki/framing_test.go index cd057d375d5..78ffa720de0 100644 --- a/pkg/tsdb/loki/framing_test.go +++ b/pkg/tsdb/loki/framing_test.go @@ -19,9 +19,9 @@ import ( // but i wanted to test for all of them, to be sure. func TestSuccessResponse(t *testing.T) { - matrixQuery := lokiQuery{Expr: "up(ALERTS)", Step: time.Second * 42, QueryType: QueryTypeRange, Direction: DirectionBackward} - vectorQuery := lokiQuery{Expr: "query1", QueryType: QueryTypeInstant, Direction: DirectionBackward} - streamsQuery := lokiQuery{Expr: "query1", QueryType: QueryTypeRange, Direction: DirectionBackward} + matrixQuery := lokiQuery{Expr: "up(ALERTS)", Step: time.Second * 42, QueryType: QueryTypeRange, Direction: DirectionBackward, RefID: "mq"} + vectorQuery := lokiQuery{Expr: "query1", QueryType: QueryTypeInstant, Direction: DirectionBackward, RefID: "vq"} + streamsQuery := lokiQuery{Expr: "query1", QueryType: QueryTypeRange, Direction: DirectionBackward, RefID: "sq"} tt := []struct { name string diff --git a/pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc b/pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc index 04dc9c4e46d..940f1eb4c4f 100644 --- a/pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc +++ b/pkg/tsdb/loki/testdata/streams_parse_errors.golden.jsonc @@ -8,16 +8,16 @@ // } // Name: // Dimensions: 5 Fields by 4 Rows -// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+ -// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: id | -// | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []string | -// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+ -// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:51 +0000 UTC | "hello1 | 1655448591000000000 | 1655448591000000000_44cbf4ec_ | -// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:54 +0000 UTC | "hello4 | 1655448594000000000 | 1655448594000000000_408b3f5b_ | -// | {"place":"moon","text":"hello3"} | 2022-06-17 06:49:52 +0000 UTC | text=hello2 | 1655448592000000000 | 1655448592000000000_d1b2086_ | -// | {"place":"moon","text":"hello4"} | 2022-06-17 06:49:53 +0000 UTC | text=hello3 | 1655448593000000000 | 1655448593000000000_45714922_ | -// +------------------------------------------------+-------------------------------+----------------+---------------------+-------------------------------+ +// +------------------------------------------------+-------------------------------+----------------+---------------------+---------------------------------+ +// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: id | +// | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []string | +// +------------------------------------------------+-------------------------------+----------------+---------------------+---------------------------------+ +// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:51 +0000 UTC | "hello1 | 1655448591000000000 | 1655448591000000000_44cbf4ec_sq | +// | {"__error__":"LogfmtParserErr","place":"moon"} | 2022-06-17 06:49:54 +0000 UTC | "hello4 | 1655448594000000000 | 1655448594000000000_408b3f5b_sq | +// | {"place":"moon","text":"hello3"} | 2022-06-17 06:49:52 +0000 UTC | text=hello2 | 1655448592000000000 | 1655448592000000000_d1b2086_sq | +// | {"place":"moon","text":"hello4"} | 2022-06-17 06:49:53 +0000 UTC | text=hello3 | 1655448593000000000 | 1655448593000000000_45714922_sq | +// +------------------------------------------------+-------------------------------+----------------+---------------------+---------------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -108,10 +108,10 @@ "1655448593000000000" ], [ - "1655448591000000000_44cbf4ec_", - "1655448594000000000_408b3f5b_", - "1655448592000000000_d1b2086_", - "1655448593000000000_45714922_" + "1655448591000000000_44cbf4ec_sq", + "1655448594000000000_408b3f5b_sq", + "1655448592000000000_d1b2086_sq", + "1655448593000000000_45714922_sq" ] ] } diff --git a/pkg/tsdb/loki/testdata/streams_simple.golden.jsonc b/pkg/tsdb/loki/testdata/streams_simple.golden.jsonc index df20de17d03..036ad3f4b94 100644 --- a/pkg/tsdb/loki/testdata/streams_simple.golden.jsonc +++ b/pkg/tsdb/loki/testdata/streams_simple.golden.jsonc @@ -116,18 +116,18 @@ // } // Name: // Dimensions: 5 Fields by 6 Rows -// +---------------------------------------+-----------------------------------------+------------------+---------------------+---------------------------------+ -// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: id | -// | Labels: | Labels: | Labels: | Labels: | Labels: | -// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []string | -// +---------------------------------------+-----------------------------------------+------------------+---------------------+---------------------------------+ -// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | 1645030244810757120_1d8c2178_ | -// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | 1645030247027735040_87a7aed2_ | -// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | 1645030246277587968_318d05c9_ | -// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | 1645030246277587968_318d05c9_1_ | -// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744 | 1645030245539423744_fd17f65c_ | -// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992 | 1645030244091700992_62ae07f3_ | -// +---------------------------------------+-----------------------------------------+------------------+---------------------+---------------------------------+ +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------------+ +// | Name: labels | Name: Time | Name: Line | Name: tsNs | Name: id | +// | Labels: | Labels: | Labels: | Labels: | Labels: | +// | Type: []json.RawMessage | Type: []time.Time | Type: []string | Type: []string | Type: []string | +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------------+ +// | {"code":"one\",","location":"moon🌙"} | 2022-02-16 16:50:44.81075712 +0000 UTC | log line error 1 | 1645030244810757120 | 1645030244810757120_1d8c2178_sq | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:47.02773504 +0000 UTC | log line info 1 | 1645030247027735040 | 1645030247027735040_87a7aed2_sq | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | 1645030246277587968_318d05c9_sq | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:46.277587968 +0000 UTC | log line info 2 | 1645030246277587968 | 1645030246277587968_318d05c9_1_sq | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:45.539423744 +0000 UTC | log line info 3 | 1645030245539423744 | 1645030245539423744_fd17f65c_sq | +// | {"code":"\",two","location":"moon🌙"} | 2022-02-16 16:50:44.091700992 +0000 UTC | log line info 4 | 1645030244091700992 | 1645030244091700992_62ae07f3_sq | +// +---------------------------------------+-----------------------------------------+------------------+---------------------+-----------------------------------+ // // // 🌟 This was machine generated. Do not edit. 🌟 @@ -340,12 +340,12 @@ "1645030244091700992" ], [ - "1645030244810757120_1d8c2178_", - "1645030247027735040_87a7aed2_", - "1645030246277587968_318d05c9_", - "1645030246277587968_318d05c9_1_", - "1645030245539423744_fd17f65c_", - "1645030244091700992_62ae07f3_" + "1645030244810757120_1d8c2178_sq", + "1645030247027735040_87a7aed2_sq", + "1645030246277587968_318d05c9_sq", + "1645030246277587968_318d05c9_1_sq", + "1645030245539423744_fd17f65c_sq", + "1645030244091700992_62ae07f3_sq" ] ] }