From df05c79d912203cb5ac364d22e5078bc4ad8d9cb Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Mon, 29 Jan 2024 11:24:05 +0100 Subject: [PATCH] Infinite scrolling: Add X-Query-Tag header (#81089) --- .../dataquery/x/LokiDataQuery_types.gen.ts | 1 + pkg/tsdb/loki/api.go | 2 ++ pkg/tsdb/loki/api_test.go | 25 +++++++++++++++++++ .../kinds/dataquery/types_dataquery_gen.go | 7 +++--- pkg/tsdb/loki/types.go | 9 ++++--- public/app/features/explore/state/query.ts | 2 ++ .../app/plugins/datasource/loki/dataquery.cue | 2 +- .../plugins/datasource/loki/dataquery.gen.ts | 1 + 8 files changed, 41 insertions(+), 8 deletions(-) diff --git a/packages/grafana-schema/src/raw/composable/loki/dataquery/x/LokiDataQuery_types.gen.ts b/packages/grafana-schema/src/raw/composable/loki/dataquery/x/LokiDataQuery_types.gen.ts index 328006a0467..a89814adb3b 100644 --- a/packages/grafana-schema/src/raw/composable/loki/dataquery/x/LokiDataQuery_types.gen.ts +++ b/packages/grafana-schema/src/raw/composable/loki/dataquery/x/LokiDataQuery_types.gen.ts @@ -26,6 +26,7 @@ export enum LokiQueryType { export enum SupportingQueryType { DataSample = 'dataSample', + InfiniteScroll = 'infiniteScroll', LogsSample = 'logsSample', LogsVolume = 'logsVolume', } diff --git a/pkg/tsdb/loki/api.go b/pkg/tsdb/loki/api.go index 6e6568ae79e..b7564897184 100644 --- a/pkg/tsdb/loki/api.go +++ b/pkg/tsdb/loki/api.go @@ -332,6 +332,8 @@ func getSupportingQueryHeaderValue(req *http.Request, supportingQueryType Suppor value = "logsample" case SupportingQueryDataSample: value = "datasample" + case SupportingQueryInfiniteScroll: + value = "infinitescroll" default: //ignore } diff --git a/pkg/tsdb/loki/api_test.go b/pkg/tsdb/loki/api_test.go index cbe964dbbe9..c510fd78d01 100644 --- a/pkg/tsdb/loki/api_test.go +++ b/pkg/tsdb/loki/api_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/grafana/grafana/pkg/tsdb/loki/kinds/dataquery" "github.com/stretchr/testify/require" ) @@ -82,6 +83,30 @@ func TestApiLogVolume(t *testing.T) { }) } +func TestInfiniteScroll(t *testing.T) { + response := []byte(` + { + "status": "success", + "data": { + "resultType" : "matrix", + "result": [] + } + } + `) + + t.Run("infinite scrolling queries should set infinite scroll http header", func(t *testing.T) { + called := false + api := makeMockedAPI(200, "application/json", response, func(req *http.Request) { + called = true + require.Equal(t, "Source=infinitescroll", req.Header.Get("X-Query-Tags")) + }, false) + + _, err := api.DataQuery(context.Background(), lokiQuery{Expr: "", SupportingQueryType: dataquery.SupportingQueryTypeInfiniteScroll, QueryType: QueryTypeRange}, ResponseOpts{}) + require.NoError(t, err) + require.True(t, called) + }) +} + func TestApiUrlHandling(t *testing.T) { response := []byte(` { diff --git a/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go b/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go index c79be5cae6f..db33add2813 100644 --- a/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go +++ b/pkg/tsdb/loki/kinds/dataquery/types_dataquery_gen.go @@ -30,9 +30,10 @@ const ( // Defines values for SupportingQueryType. const ( - SupportingQueryTypeDataSample SupportingQueryType = "dataSample" - SupportingQueryTypeLogsSample SupportingQueryType = "logsSample" - SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume" + SupportingQueryTypeDataSample SupportingQueryType = "dataSample" + SupportingQueryTypeInfiniteScroll SupportingQueryType = "infiniteScroll" + SupportingQueryTypeLogsSample SupportingQueryType = "logsSample" + SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume" ) // These are the common properties available to all queries in all datasources. diff --git a/pkg/tsdb/loki/types.go b/pkg/tsdb/loki/types.go index 06f8b1836b5..5ac5ee514c3 100644 --- a/pkg/tsdb/loki/types.go +++ b/pkg/tsdb/loki/types.go @@ -16,10 +16,11 @@ const ( ) const ( - SupportingQueryLogsVolume = dataquery.SupportingQueryTypeLogsVolume - SupportingQueryLogsSample = dataquery.SupportingQueryTypeLogsSample - SupportingQueryDataSample = dataquery.SupportingQueryTypeDataSample - SupportingQueryNone SupportingQueryType = "none" + SupportingQueryLogsVolume = dataquery.SupportingQueryTypeLogsVolume + SupportingQueryLogsSample = dataquery.SupportingQueryTypeLogsSample + SupportingQueryDataSample = dataquery.SupportingQueryTypeDataSample + SupportingQueryInfiniteScroll = dataquery.SupportingQueryTypeInfiniteScroll + SupportingQueryNone SupportingQueryType = "none" ) const ( diff --git a/public/app/features/explore/state/query.ts b/public/app/features/explore/state/query.ts index 47f58b0ebbc..b2b123fa22b 100644 --- a/public/app/features/explore/state/query.ts +++ b/public/app/features/explore/state/query.ts @@ -41,6 +41,7 @@ import { getShiftedTimeRange } from 'app/core/utils/timePicker'; import { getCorrelationsBySourceUIDs } from 'app/features/correlations/utils'; import { infiniteScrollRefId } from 'app/features/logs/logsModel'; import { getFiscalYearStartMonth, getTimeZone } from 'app/features/profile/state/selectors'; +import { SupportingQueryType } from 'app/plugins/datasource/loki/types'; import { MIXED_DATASOURCE_NAME } from 'app/plugins/datasource/mixed/MixedDataSource'; import { createAsyncThunk, @@ -732,6 +733,7 @@ export const runLoadMoreLogsQueries = createAsyncThunk