mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Use PanelQueryState to handle querying (#18694)
* WIP: inital POC * Wip: Moving forward * Wip * Refactor: Makes loading indicator work for Prometheus * Refactor: Reverts prom observable queries because they did not work for multiple targets * Refactor: Transforms all epics into thunks * Fix: Fixes scanning * Fix: Fixes so that Instant and TimeSeries Prom query loads in parallel * Fix: Fixes negation logic error * Propagate errors in stream events, and close streams
This commit is contained in:
committed by
Torkel Ödegaard
parent
f942fecc52
commit
5ca643f2ba
@@ -1,6 +1,5 @@
|
||||
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
|
||||
import thunk from 'redux-thunk';
|
||||
import { combineEpics, createEpicMiddleware } from 'redux-observable';
|
||||
import { createLogger } from 'redux-logger';
|
||||
import sharedReducers from 'app/core/reducers';
|
||||
import alertingReducers from 'app/features/alerting/state/reducers';
|
||||
@@ -15,41 +14,8 @@ import usersReducers from 'app/features/users/state/reducers';
|
||||
import userReducers from 'app/features/profile/state/reducers';
|
||||
import organizationReducers from 'app/features/org/state/reducers';
|
||||
import { setStore } from './store';
|
||||
import { limitMessageRateEpic } from 'app/features/explore/state/epics/limitMessageRateEpic';
|
||||
import { stateSaveEpic } from 'app/features/explore/state/epics/stateSaveEpic';
|
||||
import { processQueryResultsEpic } from 'app/features/explore/state/epics/processQueryResultsEpic';
|
||||
import { processQueryErrorsEpic } from 'app/features/explore/state/epics/processQueryErrorsEpic';
|
||||
import { runQueriesEpic } from 'app/features/explore/state/epics/runQueriesEpic';
|
||||
import { runQueriesBatchEpic } from 'app/features/explore/state/epics/runQueriesBatchEpic';
|
||||
import {
|
||||
DataSourceApi,
|
||||
DataQueryResponse,
|
||||
DataQuery,
|
||||
DataSourceJsonData,
|
||||
DataQueryRequest,
|
||||
DataStreamObserver,
|
||||
} from '@grafana/ui';
|
||||
|
||||
import {
|
||||
TimeZone,
|
||||
RawTimeRange,
|
||||
TimeRange,
|
||||
DateTimeInput,
|
||||
FormatInput,
|
||||
DateTime,
|
||||
AbsoluteTimeRange,
|
||||
dateTimeForTimeZone,
|
||||
} from '@grafana/data';
|
||||
import { Observable } from 'rxjs';
|
||||
import { getQueryResponse } from 'app/core/utils/explore';
|
||||
import { StoreState } from 'app/types/store';
|
||||
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
||||
import { timeEpic } from 'app/features/explore/state/epics/timeEpic';
|
||||
import { TimeSrv, getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { UserState } from 'app/types/user';
|
||||
import { getTimeRange } from 'app/core/utils/explore';
|
||||
import { getTimeZone } from 'app/features/profile/state/selectors';
|
||||
import { getShiftedTimeRange } from 'app/core/utils/timePicker';
|
||||
|
||||
const rootReducers = {
|
||||
...sharedReducers,
|
||||
@@ -70,40 +36,6 @@ export function addRootReducer(reducers: any) {
|
||||
Object.assign(rootReducers, ...reducers);
|
||||
}
|
||||
|
||||
export const rootEpic: any = combineEpics(
|
||||
limitMessageRateEpic,
|
||||
stateSaveEpic,
|
||||
runQueriesEpic,
|
||||
runQueriesBatchEpic,
|
||||
processQueryResultsEpic,
|
||||
processQueryErrorsEpic,
|
||||
timeEpic
|
||||
);
|
||||
|
||||
export interface EpicDependencies {
|
||||
getQueryResponse: (
|
||||
datasourceInstance: DataSourceApi<DataQuery, DataSourceJsonData>,
|
||||
options: DataQueryRequest<DataQuery>,
|
||||
observer?: DataStreamObserver
|
||||
) => Observable<DataQueryResponse>;
|
||||
getTimeSrv: () => TimeSrv;
|
||||
getTimeRange: (timeZone: TimeZone, rawRange: RawTimeRange) => TimeRange;
|
||||
getTimeZone: (state: UserState) => TimeZone;
|
||||
getShiftedTimeRange: (direction: number, origRange: TimeRange, timeZone: TimeZone) => AbsoluteTimeRange;
|
||||
dateTimeForTimeZone: (timezone?: TimeZone, input?: DateTimeInput, formatInput?: FormatInput) => DateTime;
|
||||
}
|
||||
|
||||
const dependencies: EpicDependencies = {
|
||||
getQueryResponse,
|
||||
getTimeSrv,
|
||||
getTimeRange,
|
||||
getTimeZone,
|
||||
getShiftedTimeRange,
|
||||
dateTimeForTimeZone,
|
||||
};
|
||||
|
||||
const epicMiddleware = createEpicMiddleware({ dependencies });
|
||||
|
||||
export function configureStore() {
|
||||
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||
const rootReducer = combineReducers(rootReducers);
|
||||
@@ -114,11 +46,10 @@ export function configureStore() {
|
||||
});
|
||||
const storeEnhancers =
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? applyMiddleware(toggleLogActionsMiddleware, thunk, epicMiddleware, logger)
|
||||
: applyMiddleware(thunk, epicMiddleware);
|
||||
? applyMiddleware(toggleLogActionsMiddleware, thunk, logger)
|
||||
: applyMiddleware(thunk);
|
||||
|
||||
const store = createStore(rootReducer, {}, composeEnhancers(storeEnhancers));
|
||||
setStore(store);
|
||||
epicMiddleware.run(rootEpic);
|
||||
return store;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user