mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
Infinite scrolling: Add X-Query-Tag header (#81089)
This commit is contained in:
parent
a83e01918a
commit
df05c79d91
@ -26,6 +26,7 @@ export enum LokiQueryType {
|
||||
|
||||
export enum SupportingQueryType {
|
||||
DataSample = 'dataSample',
|
||||
InfiniteScroll = 'infiniteScroll',
|
||||
LogsSample = 'logsSample',
|
||||
LogsVolume = 'logsVolume',
|
||||
}
|
||||
|
@ -332,6 +332,8 @@ func getSupportingQueryHeaderValue(req *http.Request, supportingQueryType Suppor
|
||||
value = "logsample"
|
||||
case SupportingQueryDataSample:
|
||||
value = "datasample"
|
||||
case SupportingQueryInfiniteScroll:
|
||||
value = "infinitescroll"
|
||||
default: //ignore
|
||||
}
|
||||
|
||||
|
@ -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(`
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ const (
|
||||
// Defines values for SupportingQueryType.
|
||||
const (
|
||||
SupportingQueryTypeDataSample SupportingQueryType = "dataSample"
|
||||
SupportingQueryTypeInfiniteScroll SupportingQueryType = "infiniteScroll"
|
||||
SupportingQueryTypeLogsSample SupportingQueryType = "logsSample"
|
||||
SupportingQueryTypeLogsVolume SupportingQueryType = "logsVolume"
|
||||
)
|
||||
|
@ -19,6 +19,7 @@ const (
|
||||
SupportingQueryLogsVolume = dataquery.SupportingQueryTypeLogsVolume
|
||||
SupportingQueryLogsSample = dataquery.SupportingQueryTypeLogsSample
|
||||
SupportingQueryDataSample = dataquery.SupportingQueryTypeDataSample
|
||||
SupportingQueryInfiniteScroll = dataquery.SupportingQueryTypeInfiniteScroll
|
||||
SupportingQueryNone SupportingQueryType = "none"
|
||||
)
|
||||
|
||||
|
@ -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<void, RunLoadMoreLogsQuer
|
||||
...query,
|
||||
datasource: query.datasource || datasourceInstance?.getRef(),
|
||||
refId: `${infiniteScrollRefId}${query.refId}`,
|
||||
supportingQueryType: SupportingQueryType.InfiniteScroll,
|
||||
}));
|
||||
|
||||
if (!hasNonEmptyQuery(logQueries) || !datasourceInstance) {
|
||||
|
@ -47,7 +47,7 @@ composableKinds: DataQuery: {
|
||||
|
||||
#LokiQueryType: "range" | "instant" | "stream" @cuetsy(kind="enum")
|
||||
|
||||
#SupportingQueryType: "logsVolume" | "logsSample" | "dataSample" @cuetsy(kind="enum")
|
||||
#SupportingQueryType: "logsVolume" | "logsSample" | "dataSample" | "infiniteScroll" @cuetsy(kind="enum")
|
||||
|
||||
#LokiQueryDirection: "forward" | "backward" @cuetsy(kind="enum")
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ export enum LokiQueryType {
|
||||
|
||||
export enum SupportingQueryType {
|
||||
DataSample = 'dataSample',
|
||||
InfiniteScroll = 'infiniteScroll',
|
||||
LogsSample = 'logsSample',
|
||||
LogsVolume = 'logsVolume',
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user