Explore: Update time range before running queries (#17349)
This makes sure that refresh/update/run query are parsing a relative time range to get proper epoch time range before running queries. Fixes #17322
This commit is contained in:
@@ -230,6 +230,7 @@ export interface LoadExploreDataSourcesPayload {
|
|||||||
|
|
||||||
export interface RunQueriesPayload {
|
export interface RunQueriesPayload {
|
||||||
exploreId: ExploreId;
|
exploreId: ExploreId;
|
||||||
|
range: TimeRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResetQueryErrorPayload {
|
export interface ResetQueryErrorPayload {
|
||||||
|
|||||||
@@ -521,6 +521,7 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false, replaceU
|
|||||||
datasourceError,
|
datasourceError,
|
||||||
containerWidth,
|
containerWidth,
|
||||||
mode,
|
mode,
|
||||||
|
range,
|
||||||
} = getState().explore[exploreId];
|
} = getState().explore[exploreId];
|
||||||
|
|
||||||
if (datasourceError) {
|
if (datasourceError) {
|
||||||
@@ -538,7 +539,10 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false, replaceU
|
|||||||
// but we're using the datasource interval limit for now
|
// but we're using the datasource interval limit for now
|
||||||
const interval = datasourceInstance.interval;
|
const interval = datasourceInstance.interval;
|
||||||
|
|
||||||
dispatch(runQueriesAction({ exploreId }));
|
const timeZone = getTimeZone(getState().user);
|
||||||
|
const updatedRange = getTimeRange(timeZone, range.raw);
|
||||||
|
|
||||||
|
dispatch(runQueriesAction({ exploreId, range: updatedRange }));
|
||||||
// Keep table queries first since they need to return quickly
|
// Keep table queries first since they need to return quickly
|
||||||
if ((ignoreUIState || showingTable) && mode === ExploreMode.Metrics) {
|
if ((ignoreUIState || showingTable) && mode === ExploreMode.Metrics) {
|
||||||
dispatch(
|
dispatch(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
exploreReducer,
|
exploreReducer,
|
||||||
makeInitialUpdateState,
|
makeInitialUpdateState,
|
||||||
initialExploreState,
|
initialExploreState,
|
||||||
|
DEFAULT_RANGE,
|
||||||
} from './reducers';
|
} from './reducers';
|
||||||
import {
|
import {
|
||||||
ExploreId,
|
ExploreId,
|
||||||
@@ -31,7 +32,7 @@ import { ActionOf } from 'app/core/redux/actionCreatorFactory';
|
|||||||
import { updateLocation } from 'app/core/actions/location';
|
import { updateLocation } from 'app/core/actions/location';
|
||||||
import { serializeStateToUrlParam } from 'app/core/utils/explore';
|
import { serializeStateToUrlParam } from 'app/core/utils/explore';
|
||||||
import TableModel from 'app/core/table_model';
|
import TableModel from 'app/core/table_model';
|
||||||
import { DataSourceApi, DataQuery, LogsModel, LogsDedupStrategy } from '@grafana/ui';
|
import { DataSourceApi, DataQuery, LogsModel, LogsDedupStrategy, dateTime } from '@grafana/ui';
|
||||||
|
|
||||||
describe('Explore item reducer', () => {
|
describe('Explore item reducer', () => {
|
||||||
describe('scanning', () => {
|
describe('scanning', () => {
|
||||||
@@ -193,6 +194,7 @@ describe('Explore item reducer', () => {
|
|||||||
it('then it should set correct state', () => {
|
it('then it should set correct state', () => {
|
||||||
const initalState: Partial<ExploreItemState> = {
|
const initalState: Partial<ExploreItemState> = {
|
||||||
showingStartPage: true,
|
showingStartPage: true,
|
||||||
|
range: null,
|
||||||
};
|
};
|
||||||
const expectedState = {
|
const expectedState = {
|
||||||
queryIntervals: {
|
queryIntervals: {
|
||||||
@@ -200,11 +202,16 @@ describe('Explore item reducer', () => {
|
|||||||
intervalMs: 1000,
|
intervalMs: 1000,
|
||||||
},
|
},
|
||||||
showingStartPage: false,
|
showingStartPage: false,
|
||||||
|
range: {
|
||||||
|
from: dateTime(),
|
||||||
|
to: dateTime(),
|
||||||
|
raw: DEFAULT_RANGE,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
reducerTester()
|
reducerTester()
|
||||||
.givenReducer(itemReducer, initalState)
|
.givenReducer(itemReducer, initalState)
|
||||||
.whenActionIsDispatched(runQueriesAction({ exploreId: ExploreId.left }))
|
.whenActionIsDispatched(runQueriesAction({ exploreId: ExploreId.left, range: expectedState.range }))
|
||||||
.thenStateShouldEqual(expectedState);
|
.thenStateShouldEqual(expectedState);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -599,8 +599,9 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
|
|||||||
})
|
})
|
||||||
.addMapper({
|
.addMapper({
|
||||||
filter: runQueriesAction,
|
filter: runQueriesAction,
|
||||||
mapper: (state): ExploreItemState => {
|
mapper: (state, action): ExploreItemState => {
|
||||||
const { range, datasourceInstance, containerWidth } = state;
|
const { range } = action.payload;
|
||||||
|
const { datasourceInstance, containerWidth } = state;
|
||||||
let interval = '1s';
|
let interval = '1s';
|
||||||
if (datasourceInstance && datasourceInstance.interval) {
|
if (datasourceInstance && datasourceInstance.interval) {
|
||||||
interval = datasourceInstance.interval;
|
interval = datasourceInstance.interval;
|
||||||
@@ -608,6 +609,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
|
|||||||
const queryIntervals = getIntervals(range, interval, containerWidth);
|
const queryIntervals = getIntervals(range, interval, containerWidth);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
range,
|
||||||
queryIntervals,
|
queryIntervals,
|
||||||
showingStartPage: false,
|
showingStartPage: false,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user