Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] [Logs UI] Support zoom by brushing in the log rate chart… #45916

Merged
merged 2 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ export const AnalysisResultsContent = ({
[setSelectedTimeRange, handleQueryTimeRangeChange]
);

const handleChartTimeRangeChange = useCallback(
({ startTime, endTime }: TimeRange) => {
handleSelectedTimeRangeChange({
end: new Date(endTime).toISOString(),
isInvalid: false,
start: new Date(startTime).toISOString(),
});
},
[handleSelectedTimeRangeChange]
);

const handleAutoRefreshChange = useCallback(
({ isPaused, refreshInterval: interval }: { isPaused: boolean; refreshInterval: number }) => {
setAutoRefresh({
Expand Down Expand Up @@ -183,6 +194,7 @@ export const AnalysisResultsContent = ({
<LogRateResults
isLoading={isLoading}
results={logEntryRate}
setTimeRange={handleChartTimeRangeChange}
timeRange={queryTimeRange}
/>
</EuiPageContentBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@ const lineSeriesColour = 'rgb(49, 133, 252)';

interface Props {
data: GetLogEntryRateSuccessResponsePayload['data'] | null;
setTimeRange: (timeRange: TimeRange) => void;
timeRange: TimeRange;
}

export const ChartView = ({ data, timeRange }: Props) => {
const showModelBoundsLabel = i18n.translate(
'xpack.infra.logs.analysis.logRateSectionModelBoundsCheckboxLabel',
{ defaultMessage: 'Show model bounds' }
);

export const ChartView = ({ data, setTimeRange, timeRange }: Props) => {
const { areaSeries, lineSeries, anomalySeries } = useLogEntryRateGraphData({ data });

const dateFormatter = useMemo(
Expand All @@ -55,15 +51,26 @@ export const ChartView = ({ data, timeRange }: Props) => {

const [dateFormat] = useKibanaUiSetting('dateFormat');

const tooltipProps = {
headerFormatter: useCallback(
(tooltipData: TooltipValue) =>
const tooltipProps = useMemo(
() => ({
headerFormatter: (tooltipData: TooltipValue) =>
moment(tooltipData.value).format(dateFormat || 'Y-MM-DD HH:mm:ss.SSS'),
[dateFormat]
),
};
}),
[dateFormat]
);

const [isShowingModelBounds, setIsShowingModelBounds] = useState<boolean>(true);

const handleBrushEnd = useCallback(
(startTime: number, endTime: number) => {
setTimeRange({
endTime,
startTime,
});
},
[setTimeRange]
);

return (
<>
<EuiFlexGroup justifyContent="flexEnd">
Expand Down Expand Up @@ -172,6 +179,7 @@ export const ChartView = ({ data, timeRange }: Props) => {
customSeriesColors={!isDarkMode() ? getColorsMap('red', anomalySpecId) : undefined}
/>
<Settings
onBrushEnd={handleBrushEnd}
tooltip={tooltipProps}
theme={getChartTheme()}
xDomain={{ min: timeRange.startTime, max: timeRange.endTime }}
Expand All @@ -181,3 +189,8 @@ export const ChartView = ({ data, timeRange }: Props) => {
</>
);
};

const showModelBoundsLabel = i18n.translate(
'xpack.infra.logs.analysis.logRateSectionModelBoundsCheckboxLabel',
{ defaultMessage: 'Show model bounds' }
);
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
export const LogRateResults = ({
isLoading,
results,
setTimeRange,
timeRange,
}: {
isLoading: boolean;
results: GetLogEntryRateSuccessResponsePayload['data'] | null;
setTimeRange: (timeRange: TimeRange) => void;
timeRange: TimeRange;
}) => {
const title = i18n.translate('xpack.infra.logs.analysis.logRateSectionTitle', {
Expand Down Expand Up @@ -83,7 +85,7 @@ export const LogRateResults = ({
</EuiFlexGroup>
<EuiSpacer size="l" />
{viewMode === 'chart' ? (
<ChartView data={results} timeRange={timeRange} />
<ChartView data={results} setTimeRange={setTimeRange} timeRange={timeRange} />
) : (
<TableView data={results} />
)}
Expand Down