Logs: Use millisecond precision for open context in split view (#67385)

Log: Use millisecond precision for open context in split view
This commit is contained in:
Ivana Huckova 2023-04-27 14:09:20 +02:00 committed by GitHub
parent d01ea9902c
commit 3a8bb226bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,8 @@ import {
LogsDedupStrategy,
LogsSortOrder,
SelectableValue,
rangeUtil,
dateTime,
TimeRange,
} from '@grafana/data';
import { config, reportInteraction } from '@grafana/runtime';
import { DataQuery, TimeZone } from '@grafana/schema';
@ -23,6 +24,7 @@ import { splitOpen } from 'app/features/explore/state/main';
import { SETTINGS_KEYS } from 'app/features/explore/utils/logs';
import { useDispatch } from 'app/types';
import { sortLogRows } from '../../utils';
import { LogRows } from '../LogRows';
import { LoadMoreOptions, LogContextButtons } from './LogContextButtons';
@ -154,16 +156,26 @@ export const LogRowContextModal: React.FunctionComponent<LogRowContextModalProps
const getFullTimeRange = useCallback(() => {
const { before, after } = context;
const allRows = [...before, row, ...after].sort((a, b) => a.timeEpochMs - b.timeEpochMs);
const first = allRows[0];
const last = allRows[allRows.length - 1];
return rangeUtil.convertRawToRange(
{
from: first.timeUtc,
to: last.timeUtc,
const allRows = sortLogRows([...before, row, ...after], LogsSortOrder.Ascending);
const fromMs = allRows[0].timeEpochMs;
let toMs = allRows[allRows.length - 1].timeEpochMs;
// In case we have a lot of logs and from and to have same millisecond
// we add 1 millisecond to toMs to make sure we have a range
if (fromMs === toMs) {
toMs += 1;
}
const from = dateTime(fromMs);
const to = dateTime(toMs);
const range: TimeRange = {
from,
to,
raw: {
from,
to,
},
'utc'
);
};
return range;
}, [context, row]);
const onChangeLimitOption = (option: SelectableValue<number>) => {