2019-01-13 16:10:23 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { hot } from 'react-hot-loader';
|
|
|
|
import { connect } from 'react-redux';
|
2019-05-20 01:44:37 -05:00
|
|
|
import {
|
|
|
|
RawTimeRange,
|
|
|
|
TimeRange,
|
|
|
|
LogLevel,
|
|
|
|
TimeZone,
|
|
|
|
AbsoluteTimeRange,
|
|
|
|
toUtc,
|
|
|
|
dateTime,
|
|
|
|
DataSourceApi,
|
2019-05-22 16:10:05 -05:00
|
|
|
LogsModel,
|
|
|
|
LogRowModel,
|
|
|
|
LogsDedupStrategy,
|
2019-06-03 07:54:32 -05:00
|
|
|
LoadingState,
|
2019-05-20 01:44:37 -05:00
|
|
|
} from '@grafana/ui';
|
2019-01-13 16:10:23 -06:00
|
|
|
|
|
|
|
import { ExploreId, ExploreItemState } from 'app/types/explore';
|
|
|
|
import { StoreState } from 'app/types';
|
|
|
|
|
2019-05-17 05:45:11 -05:00
|
|
|
import { changeDedupStrategy, changeTime } from './state/actions';
|
2019-01-13 16:10:23 -06:00
|
|
|
import Logs from './Logs';
|
|
|
|
import Panel from './Panel';
|
2019-05-20 06:28:23 -05:00
|
|
|
import { toggleLogLevelAction, changeRefreshIntervalAction } from 'app/features/explore/state/actionTypes';
|
2019-02-12 05:36:46 -06:00
|
|
|
import { deduplicatedLogsSelector, exploreItemUIStateSelector } from 'app/features/explore/state/selectors';
|
2019-04-29 11:28:41 -05:00
|
|
|
import { getTimeZone } from '../profile/state/selectors';
|
2019-05-20 06:28:23 -05:00
|
|
|
import { LiveLogsWithTheme } from './LiveLogs';
|
|
|
|
import { offOption } from '@grafana/ui/src/components/RefreshPicker/RefreshPicker';
|
2019-01-13 16:10:23 -06:00
|
|
|
|
|
|
|
interface LogsContainerProps {
|
2019-05-20 01:44:37 -05:00
|
|
|
datasourceInstance: DataSourceApi | null;
|
2019-01-13 16:10:23 -06:00
|
|
|
exploreId: ExploreId;
|
|
|
|
loading: boolean;
|
2019-05-22 16:10:05 -05:00
|
|
|
|
2019-01-13 16:10:23 -06:00
|
|
|
logsHighlighterExpressions?: string[];
|
|
|
|
logsResult?: LogsModel;
|
2019-02-11 09:57:49 -06:00
|
|
|
dedupedResult?: LogsModel;
|
2019-01-13 16:10:23 -06:00
|
|
|
onClickLabel: (key: string, value: string) => void;
|
|
|
|
onStartScanning: () => void;
|
|
|
|
onStopScanning: () => void;
|
2019-04-29 11:28:41 -05:00
|
|
|
range: TimeRange;
|
|
|
|
timeZone: TimeZone;
|
2019-01-13 16:10:23 -06:00
|
|
|
scanning?: boolean;
|
|
|
|
scanRange?: RawTimeRange;
|
2019-02-11 09:57:49 -06:00
|
|
|
toggleLogLevelAction: typeof toggleLogLevelAction;
|
2019-02-07 10:46:33 -06:00
|
|
|
changeDedupStrategy: typeof changeDedupStrategy;
|
|
|
|
dedupStrategy: LogsDedupStrategy;
|
2019-02-11 09:57:49 -06:00
|
|
|
hiddenLogLevels: Set<LogLevel>;
|
2019-02-11 04:17:23 -06:00
|
|
|
width: number;
|
2019-05-10 05:10:32 -05:00
|
|
|
changeTime: typeof changeTime;
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive: boolean;
|
|
|
|
stopLive: typeof changeRefreshIntervalAction;
|
2019-01-13 16:10:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export class LogsContainer extends PureComponent<LogsContainerProps> {
|
2019-05-10 05:10:32 -05:00
|
|
|
onChangeTime = (absRange: AbsoluteTimeRange) => {
|
|
|
|
const { exploreId, timeZone, changeTime } = this.props;
|
|
|
|
const range = {
|
|
|
|
from: timeZone.isUtc ? toUtc(absRange.from) : dateTime(absRange.from),
|
|
|
|
to: timeZone.isUtc ? toUtc(absRange.to) : dateTime(absRange.to),
|
|
|
|
};
|
|
|
|
|
|
|
|
changeTime(exploreId, range);
|
|
|
|
};
|
|
|
|
|
2019-05-20 06:28:23 -05:00
|
|
|
onStopLive = () => {
|
|
|
|
const { exploreId } = this.props;
|
|
|
|
this.props.stopLive({ exploreId, refreshInterval: offOption.value });
|
|
|
|
};
|
|
|
|
|
2019-02-07 10:46:33 -06:00
|
|
|
handleDedupStrategyChange = (dedupStrategy: LogsDedupStrategy) => {
|
|
|
|
this.props.changeDedupStrategy(this.props.exploreId, dedupStrategy);
|
|
|
|
};
|
|
|
|
|
2019-02-11 09:57:49 -06:00
|
|
|
hangleToggleLogLevel = (hiddenLogLevels: Set<LogLevel>) => {
|
|
|
|
const { exploreId } = this.props;
|
|
|
|
this.props.toggleLogLevelAction({
|
|
|
|
exploreId,
|
|
|
|
hiddenLogLevels,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2019-05-22 16:10:05 -05:00
|
|
|
getLogRowContext = async (row: LogRowModel, options?: any) => {
|
2019-05-20 01:44:37 -05:00
|
|
|
const { datasourceInstance } = this.props;
|
|
|
|
|
|
|
|
if (datasourceInstance) {
|
2019-05-22 16:10:05 -05:00
|
|
|
return datasourceInstance.getLogRowContext(row, options);
|
2019-05-20 01:44:37 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2019-01-13 16:10:23 -06:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
exploreId,
|
|
|
|
loading,
|
|
|
|
logsHighlighterExpressions,
|
|
|
|
logsResult,
|
2019-02-11 09:57:49 -06:00
|
|
|
dedupedResult,
|
2019-01-13 16:10:23 -06:00
|
|
|
onClickLabel,
|
|
|
|
onStartScanning,
|
|
|
|
onStopScanning,
|
|
|
|
range,
|
2019-04-29 11:28:41 -05:00
|
|
|
timeZone,
|
2019-01-13 16:10:23 -06:00
|
|
|
scanning,
|
|
|
|
scanRange,
|
2019-02-11 04:17:23 -06:00
|
|
|
width,
|
2019-02-11 09:57:49 -06:00
|
|
|
hiddenLogLevels,
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive,
|
2019-01-13 16:10:23 -06:00
|
|
|
} = this.props;
|
2019-01-28 05:57:09 -06:00
|
|
|
|
2019-05-20 06:28:23 -05:00
|
|
|
if (isLive) {
|
|
|
|
return (
|
|
|
|
<Panel label="Logs" loading={false} isOpen>
|
|
|
|
<LiveLogsWithTheme logsResult={logsResult} stopLive={this.onStopLive} />
|
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-13 16:10:23 -06:00
|
|
|
return (
|
2019-05-17 05:45:11 -05:00
|
|
|
<Panel label="Logs" loading={loading} isOpen>
|
2019-01-13 16:10:23 -06:00
|
|
|
<Logs
|
2019-02-07 10:46:33 -06:00
|
|
|
dedupStrategy={this.props.dedupStrategy || LogsDedupStrategy.none}
|
2019-01-13 16:10:23 -06:00
|
|
|
data={logsResult}
|
2019-02-11 09:57:49 -06:00
|
|
|
dedupedData={dedupedResult}
|
2019-01-13 16:10:23 -06:00
|
|
|
exploreId={exploreId}
|
|
|
|
highlighterExpressions={logsHighlighterExpressions}
|
|
|
|
loading={loading}
|
2019-05-10 05:10:32 -05:00
|
|
|
onChangeTime={this.onChangeTime}
|
2019-01-13 16:10:23 -06:00
|
|
|
onClickLabel={onClickLabel}
|
|
|
|
onStartScanning={onStartScanning}
|
|
|
|
onStopScanning={onStopScanning}
|
2019-02-07 10:46:33 -06:00
|
|
|
onDedupStrategyChange={this.handleDedupStrategyChange}
|
2019-02-11 09:57:49 -06:00
|
|
|
onToggleLogLevel={this.hangleToggleLogLevel}
|
2019-01-13 16:10:23 -06:00
|
|
|
range={range}
|
2019-04-29 11:28:41 -05:00
|
|
|
timeZone={timeZone}
|
2019-01-13 16:10:23 -06:00
|
|
|
scanning={scanning}
|
|
|
|
scanRange={scanRange}
|
2019-02-11 04:17:23 -06:00
|
|
|
width={width}
|
2019-02-11 09:57:49 -06:00
|
|
|
hiddenLogLevels={hiddenLogLevels}
|
2019-05-20 01:44:37 -05:00
|
|
|
getRowContext={this.getLogRowContext}
|
2019-01-13 16:10:23 -06:00
|
|
|
/>
|
|
|
|
</Panel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: StoreState, { exploreId }) {
|
|
|
|
const explore = state.explore;
|
|
|
|
const item: ExploreItemState = explore[exploreId];
|
2019-05-20 06:28:23 -05:00
|
|
|
const {
|
|
|
|
logsHighlighterExpressions,
|
|
|
|
logsResult,
|
2019-06-03 07:54:32 -05:00
|
|
|
loadingState,
|
2019-05-20 06:28:23 -05:00
|
|
|
scanning,
|
|
|
|
scanRange,
|
|
|
|
range,
|
|
|
|
datasourceInstance,
|
|
|
|
isLive,
|
|
|
|
} = item;
|
2019-06-03 07:54:32 -05:00
|
|
|
const loading = loadingState === LoadingState.Loading || loadingState === LoadingState.Streaming;
|
2019-05-17 05:45:11 -05:00
|
|
|
const { dedupStrategy } = exploreItemUIStateSelector(item);
|
2019-02-11 09:57:49 -06:00
|
|
|
const hiddenLogLevels = new Set(item.hiddenLogLevels);
|
|
|
|
const dedupedResult = deduplicatedLogsSelector(item);
|
2019-04-29 11:28:41 -05:00
|
|
|
const timeZone = getTimeZone(state.user);
|
2019-02-11 04:59:48 -06:00
|
|
|
|
2019-01-13 16:10:23 -06:00
|
|
|
return {
|
|
|
|
loading,
|
|
|
|
logsHighlighterExpressions,
|
|
|
|
logsResult,
|
|
|
|
scanning,
|
|
|
|
scanRange,
|
|
|
|
range,
|
2019-04-29 11:28:41 -05:00
|
|
|
timeZone,
|
2019-02-07 10:46:33 -06:00
|
|
|
dedupStrategy,
|
2019-02-11 09:57:49 -06:00
|
|
|
hiddenLogLevels,
|
|
|
|
dedupedResult,
|
2019-05-20 01:44:37 -05:00
|
|
|
datasourceInstance,
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive,
|
2019-01-13 16:10:23 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2019-02-07 10:46:33 -06:00
|
|
|
changeDedupStrategy,
|
2019-02-11 09:57:49 -06:00
|
|
|
toggleLogLevelAction,
|
2019-05-10 05:10:32 -05:00
|
|
|
changeTime,
|
2019-05-20 06:28:23 -05:00
|
|
|
stopLive: changeRefreshIntervalAction,
|
2019-01-13 16:10:23 -06:00
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(LogsContainer)
|
|
|
|
);
|