2019-07-02 09:06:21 +01:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-01-25 17:05:27 +01:00
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2021-10-01 13:38:16 +02:00
|
|
|
import {
|
|
|
|
|
AbsoluteTimeRange,
|
|
|
|
|
Field,
|
|
|
|
|
hasLogsContextSupport,
|
2023-01-27 15:12:01 +01:00
|
|
|
hasLogsContextUiSupport,
|
2021-10-01 13:38:16 +02:00
|
|
|
LoadingState,
|
|
|
|
|
LogRowModel,
|
|
|
|
|
RawTimeRange,
|
2022-11-03 09:55:02 +00:00
|
|
|
EventBus,
|
2022-11-02 11:22:09 +01:00
|
|
|
SplitOpen,
|
2022-11-10 15:33:17 +01:00
|
|
|
DataFrame,
|
2023-01-20 14:20:49 +01:00
|
|
|
SupplementaryQueryType,
|
2023-03-14 09:51:44 +00:00
|
|
|
DataQueryResponse,
|
2023-04-20 14:21:14 +02:00
|
|
|
LogRowContextOptions,
|
|
|
|
|
DataSourceWithLogsContextSupport,
|
|
|
|
|
DataSourceApi,
|
2021-10-01 13:38:16 +02:00
|
|
|
} from '@grafana/data';
|
2023-04-20 14:21:14 +02:00
|
|
|
import { DataQuery } from '@grafana/schema';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { Collapse } from '@grafana/ui';
|
2019-01-13 23:10:23 +01:00
|
|
|
import { StoreState } from 'app/types';
|
2023-01-20 14:20:49 +01:00
|
|
|
import { ExploreId, ExploreItemState } from 'app/types/explore';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2023-05-23 07:42:38 -06:00
|
|
|
import { getTimeZone } from '../../profile/state/selectors';
|
|
|
|
|
import {
|
|
|
|
|
addResultsToCache,
|
|
|
|
|
clearCache,
|
|
|
|
|
loadSupplementaryQueryData,
|
|
|
|
|
setSupplementaryQueryEnabled,
|
|
|
|
|
} from '../state/query';
|
|
|
|
|
import { updateTimeRange } from '../state/time';
|
|
|
|
|
import { LiveTailControls } from '../useLiveTailControls';
|
|
|
|
|
import { getFieldLinksForExplore } from '../utils/links';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2019-05-20 13:28:23 +02:00
|
|
|
import { LiveLogsWithTheme } from './LiveLogs';
|
2019-08-26 08:11:07 +02:00
|
|
|
import { Logs } from './Logs';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { LogsCrossFadeTransition } from './utils/LogsCrossFadeTransition';
|
2019-01-13 23:10:23 +01:00
|
|
|
|
2021-05-24 13:56:48 +02:00
|
|
|
interface LogsContainerProps extends PropsFromRedux {
|
2021-06-18 14:21:54 +02:00
|
|
|
width: number;
|
2019-01-13 23:10:23 +01:00
|
|
|
exploreId: ExploreId;
|
2021-01-25 17:05:27 +01:00
|
|
|
scanRange?: RawTimeRange;
|
|
|
|
|
syncedTimes: boolean;
|
2021-09-10 18:18:22 +02:00
|
|
|
loadingState: LoadingState;
|
2023-01-11 19:20:11 +01:00
|
|
|
onClickFilterLabel: (key: string, value: string) => void;
|
|
|
|
|
onClickFilterOutLabel: (key: string, value: string) => void;
|
2019-01-13 23:10:23 +01:00
|
|
|
onStartScanning: () => void;
|
|
|
|
|
onStopScanning: () => void;
|
2022-11-03 09:55:02 +00:00
|
|
|
eventBus: EventBus;
|
2022-11-02 11:22:09 +01:00
|
|
|
splitOpenFn: SplitOpen;
|
2023-06-16 14:07:51 +02:00
|
|
|
scrollElement?: HTMLDivElement;
|
2019-01-13 23:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-29 11:34:48 +01:00
|
|
|
class LogsContainer extends PureComponent<LogsContainerProps> {
|
2019-06-25 14:44:19 +02:00
|
|
|
onChangeTime = (absoluteRange: AbsoluteTimeRange) => {
|
|
|
|
|
const { exploreId, updateTimeRange } = this.props;
|
|
|
|
|
updateTimeRange({ exploreId, absoluteRange });
|
2019-05-10 12:10:32 +02:00
|
|
|
};
|
|
|
|
|
|
2023-04-20 14:21:14 +02:00
|
|
|
private getQuery(
|
|
|
|
|
logsQueries: DataQuery[] | undefined,
|
|
|
|
|
row: LogRowModel,
|
|
|
|
|
datasourceInstance: DataSourceApi<DataQuery> & DataSourceWithLogsContextSupport<DataQuery>
|
|
|
|
|
) {
|
|
|
|
|
// we need to find the query, and we need to be very sure that it's a query
|
|
|
|
|
// from this datasource
|
|
|
|
|
return (logsQueries ?? []).find(
|
|
|
|
|
(q) => q.refId === row.dataFrame.refId && q.datasource != null && q.datasource.type === datasourceInstance.type
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getLogRowContext = async (row: LogRowModel, options?: LogRowContextOptions): Promise<DataQueryResponse | []> => {
|
2022-07-15 16:02:43 +02:00
|
|
|
const { datasourceInstance, logsQueries } = this.props;
|
2019-05-20 08:44:37 +02:00
|
|
|
|
2021-10-01 13:38:16 +02:00
|
|
|
if (hasLogsContextSupport(datasourceInstance)) {
|
2023-04-20 14:21:14 +02:00
|
|
|
const query = this.getQuery(logsQueries, row, datasourceInstance);
|
2022-07-15 16:02:43 +02:00
|
|
|
return datasourceInstance.getLogRowContext(row, options, query);
|
2019-05-20 08:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [];
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-20 14:21:14 +02:00
|
|
|
getLogRowContextQuery = async (row: LogRowModel, options?: LogRowContextOptions): Promise<DataQuery | null> => {
|
|
|
|
|
const { datasourceInstance, logsQueries } = this.props;
|
|
|
|
|
|
|
|
|
|
if (hasLogsContextSupport(datasourceInstance) && datasourceInstance.getLogRowContextQuery) {
|
|
|
|
|
const query = this.getQuery(logsQueries, row, datasourceInstance);
|
|
|
|
|
return datasourceInstance.getLogRowContextQuery(row, options, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-27 15:12:01 +01:00
|
|
|
getLogRowContextUi = (row: LogRowModel, runContextQuery?: () => void): React.ReactNode => {
|
2023-04-18 15:59:22 +02:00
|
|
|
const { datasourceInstance, logsQueries } = this.props;
|
2023-01-27 15:12:01 +01:00
|
|
|
|
|
|
|
|
if (hasLogsContextUiSupport(datasourceInstance) && datasourceInstance.getLogRowContextUi) {
|
2023-04-20 14:21:14 +02:00
|
|
|
const query = this.getQuery(logsQueries, row, datasourceInstance);
|
2023-04-18 15:59:22 +02:00
|
|
|
return datasourceInstance.getLogRowContextUi(row, runContextQuery, query);
|
2023-01-27 15:12:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <></>;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-15 12:16:52 +01:00
|
|
|
showContextToggle = (row?: LogRowModel): boolean => {
|
2020-12-10 04:19:14 -07:00
|
|
|
const { datasourceInstance } = this.props;
|
|
|
|
|
|
2021-10-01 13:38:16 +02:00
|
|
|
if (hasLogsContextSupport(datasourceInstance)) {
|
2020-12-15 12:16:52 +01:00
|
|
|
return datasourceInstance.showContextToggle(row);
|
2020-12-10 04:19:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2022-11-10 15:33:17 +01:00
|
|
|
getFieldLinks = (field: Field, rowIndex: number, dataFrame: DataFrame) => {
|
2022-11-02 11:22:09 +01:00
|
|
|
const { splitOpenFn, range } = this.props;
|
2022-11-10 15:33:17 +01:00
|
|
|
return getFieldLinksForExplore({ field, rowIndex, splitOpenFn, range, dataFrame });
|
2020-03-25 12:25:39 +01:00
|
|
|
};
|
|
|
|
|
|
2019-01-13 23:10:23 +01:00
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
loading,
|
2021-09-10 18:18:22 +02:00
|
|
|
loadingState,
|
2019-11-01 16:38:34 +01:00
|
|
|
logRows,
|
|
|
|
|
logsMeta,
|
|
|
|
|
logsSeries,
|
2021-05-12 12:54:15 +02:00
|
|
|
logsQueries,
|
2023-01-09 18:33:48 +01:00
|
|
|
loadSupplementaryQueryData,
|
|
|
|
|
setSupplementaryQueryEnabled,
|
2019-11-01 10:01:00 +01:00
|
|
|
onClickFilterLabel,
|
|
|
|
|
onClickFilterOutLabel,
|
2019-01-13 23:10:23 +01:00
|
|
|
onStartScanning,
|
|
|
|
|
onStopScanning,
|
2019-06-25 14:44:19 +02:00
|
|
|
absoluteRange,
|
2019-04-29 18:28:41 +02:00
|
|
|
timeZone,
|
2020-05-29 15:39:13 +02:00
|
|
|
visibleRange,
|
2019-01-13 23:10:23 +01:00
|
|
|
scanning,
|
2019-06-28 12:07:55 +02:00
|
|
|
range,
|
2021-06-18 14:21:54 +02:00
|
|
|
width,
|
2022-11-02 11:22:09 +01:00
|
|
|
splitOpenFn,
|
2019-05-20 13:28:23 +02:00
|
|
|
isLive,
|
2019-09-24 10:18:34 +02:00
|
|
|
exploreId,
|
2021-05-24 13:56:48 +02:00
|
|
|
addResultsToCache,
|
|
|
|
|
clearCache,
|
2023-01-09 18:33:48 +01:00
|
|
|
logsVolume,
|
2023-06-16 14:07:51 +02:00
|
|
|
scrollElement,
|
2019-01-13 23:10:23 +01:00
|
|
|
} = this.props;
|
2019-01-28 12:57:09 +01:00
|
|
|
|
2021-01-25 17:05:27 +01:00
|
|
|
if (!logRows) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-13 23:10:23 +01:00
|
|
|
return (
|
2019-09-20 13:00:11 +02:00
|
|
|
<>
|
|
|
|
|
<LogsCrossFadeTransition visible={isLive}>
|
|
|
|
|
<Collapse label="Logs" loading={false} isOpen>
|
2019-09-24 10:18:34 +02:00
|
|
|
<LiveTailControls exploreId={exploreId}>
|
2021-01-20 07:59:48 +01:00
|
|
|
{(controls) => (
|
2019-09-24 10:18:34 +02:00
|
|
|
<LiveLogsWithTheme
|
2019-11-01 16:38:34 +01:00
|
|
|
logRows={logRows}
|
2019-09-24 10:18:34 +02:00
|
|
|
timeZone={timeZone}
|
|
|
|
|
stopLive={controls.stop}
|
|
|
|
|
isPaused={this.props.isPaused}
|
|
|
|
|
onPause={controls.pause}
|
|
|
|
|
onResume={controls.resume}
|
2023-04-20 05:21:28 -03:00
|
|
|
onClear={controls.clear}
|
|
|
|
|
clearedAtIndex={this.props.clearedAtIndex}
|
2019-09-24 10:18:34 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</LiveTailControls>
|
2019-09-20 13:00:11 +02:00
|
|
|
</Collapse>
|
|
|
|
|
</LogsCrossFadeTransition>
|
|
|
|
|
<LogsCrossFadeTransition visible={!isLive}>
|
2022-09-26 14:28:12 +02:00
|
|
|
<Logs
|
|
|
|
|
exploreId={exploreId}
|
|
|
|
|
datasourceType={this.props.datasourceInstance?.type}
|
|
|
|
|
logRows={logRows}
|
|
|
|
|
logsMeta={logsMeta}
|
|
|
|
|
logsSeries={logsSeries}
|
2023-01-09 18:33:48 +01:00
|
|
|
logsVolumeEnabled={logsVolume.enabled}
|
|
|
|
|
onSetLogsVolumeEnabled={(enabled) =>
|
|
|
|
|
setSupplementaryQueryEnabled(exploreId, enabled, SupplementaryQueryType.LogsVolume)
|
|
|
|
|
}
|
|
|
|
|
logsVolumeData={logsVolume.data}
|
2022-09-26 14:28:12 +02:00
|
|
|
logsQueries={logsQueries}
|
|
|
|
|
width={width}
|
2022-11-02 11:22:09 +01:00
|
|
|
splitOpen={splitOpenFn}
|
2022-09-26 14:28:12 +02:00
|
|
|
loading={loading}
|
|
|
|
|
loadingState={loadingState}
|
2023-01-09 18:33:48 +01:00
|
|
|
loadLogsVolumeData={() => loadSupplementaryQueryData(exploreId, SupplementaryQueryType.LogsVolume)}
|
2022-09-26 14:28:12 +02:00
|
|
|
onChangeTime={this.onChangeTime}
|
|
|
|
|
onClickFilterLabel={onClickFilterLabel}
|
|
|
|
|
onClickFilterOutLabel={onClickFilterOutLabel}
|
|
|
|
|
onStartScanning={onStartScanning}
|
|
|
|
|
onStopScanning={onStopScanning}
|
|
|
|
|
absoluteRange={absoluteRange}
|
|
|
|
|
visibleRange={visibleRange}
|
|
|
|
|
timeZone={timeZone}
|
|
|
|
|
scanning={scanning}
|
|
|
|
|
scanRange={range.raw}
|
|
|
|
|
showContextToggle={this.showContextToggle}
|
|
|
|
|
getRowContext={this.getLogRowContext}
|
2023-04-20 14:21:14 +02:00
|
|
|
getRowContextQuery={this.getLogRowContextQuery}
|
2023-01-27 15:12:01 +01:00
|
|
|
getLogRowContextUi={this.getLogRowContextUi}
|
2022-09-26 14:28:12 +02:00
|
|
|
getFieldLinks={this.getFieldLinks}
|
|
|
|
|
addResultsToCache={() => addResultsToCache(exploreId)}
|
|
|
|
|
clearCache={() => clearCache(exploreId)}
|
2022-11-03 09:55:02 +00:00
|
|
|
eventBus={this.props.eventBus}
|
2023-06-16 14:07:51 +02:00
|
|
|
panelState={this.props.panelState}
|
|
|
|
|
scrollElement={scrollElement}
|
2022-09-26 14:28:12 +02:00
|
|
|
/>
|
2019-09-20 13:00:11 +02:00
|
|
|
</LogsCrossFadeTransition>
|
|
|
|
|
</>
|
2019-01-13 23:10:23 +01:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 16:45:11 +01:00
|
|
|
function mapStateToProps(state: StoreState, { exploreId }: { exploreId: ExploreId }) {
|
2019-01-13 23:10:23 +01:00
|
|
|
const explore = state.explore;
|
2023-05-03 16:45:11 +01:00
|
|
|
const item: ExploreItemState = explore.panes[exploreId]!;
|
2021-10-20 13:58:04 +02:00
|
|
|
const {
|
|
|
|
|
logsResult,
|
|
|
|
|
loading,
|
|
|
|
|
scanning,
|
|
|
|
|
datasourceInstance,
|
|
|
|
|
isLive,
|
|
|
|
|
isPaused,
|
2023-04-20 05:21:28 -03:00
|
|
|
clearedAtIndex,
|
2021-10-20 13:58:04 +02:00
|
|
|
range,
|
|
|
|
|
absoluteRange,
|
2023-01-09 18:33:48 +01:00
|
|
|
supplementaryQueries,
|
2021-10-20 13:58:04 +02:00
|
|
|
} = item;
|
2023-06-16 14:07:51 +02:00
|
|
|
const panelState = item.panelsState;
|
2019-04-29 18:28:41 +02:00
|
|
|
const timeZone = getTimeZone(state.user);
|
2023-01-09 18:33:48 +01:00
|
|
|
const logsVolume = supplementaryQueries[SupplementaryQueryType.LogsVolume];
|
2019-02-11 11:59:48 +01:00
|
|
|
|
2019-01-13 23:10:23 +01:00
|
|
|
return {
|
|
|
|
|
loading,
|
2021-01-25 17:05:27 +01:00
|
|
|
logRows: logsResult?.rows,
|
|
|
|
|
logsMeta: logsResult?.meta,
|
|
|
|
|
logsSeries: logsResult?.series,
|
2021-05-12 12:54:15 +02:00
|
|
|
logsQueries: logsResult?.queries,
|
2021-01-25 17:05:27 +01:00
|
|
|
visibleRange: logsResult?.visibleRange,
|
2019-01-13 23:10:23 +01:00
|
|
|
scanning,
|
2019-04-29 18:28:41 +02:00
|
|
|
timeZone,
|
2019-05-20 08:44:37 +02:00
|
|
|
datasourceInstance,
|
2019-05-20 13:28:23 +02:00
|
|
|
isLive,
|
2019-09-03 11:23:39 +02:00
|
|
|
isPaused,
|
2023-04-20 05:21:28 -03:00
|
|
|
clearedAtIndex,
|
2019-06-28 12:07:55 +02:00
|
|
|
range,
|
2019-06-25 14:44:19 +02:00
|
|
|
absoluteRange,
|
2023-01-09 18:33:48 +01:00
|
|
|
logsVolume,
|
2023-06-16 14:07:51 +02:00
|
|
|
panelState,
|
2019-01-13 23:10:23 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-06-25 14:44:19 +02:00
|
|
|
updateTimeRange,
|
2021-05-24 13:56:48 +02:00
|
|
|
addResultsToCache,
|
|
|
|
|
clearCache,
|
2023-01-09 18:33:48 +01:00
|
|
|
loadSupplementaryQueryData,
|
|
|
|
|
setSupplementaryQueryEnabled,
|
2019-01-13 23:10:23 +01:00
|
|
|
};
|
|
|
|
|
|
2021-01-25 17:05:27 +01:00
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
type PropsFromRedux = ConnectedProps<typeof connector>;
|
|
|
|
|
|
2021-08-31 12:55:05 +02:00
|
|
|
export default connector(LogsContainer);
|