grafana/public/app/features/explore/__mocks__/makeLogs.ts
Abdul 3a013cbe48
Explore: Clear live logs (#64237)
* feat: add clear logs to explorer's live logs

* refactor live logs pause/resume updating logic

* add tests for clearing live logs

* rm unused imports

* move `onClear` live logs logic to redux

* move clear logs tests to `query.test`

* use utils `sortLogsRows` and Button's icon props

* rename `filterLogRows` and add `clearedAt` as an arg

* mv clearedAt type closer to live tailing items and add jsdoc

* mv `filterLogRowsByTime` to `/utils` and use it at `LiveLogs` component

* make `Exit live` button consistent with other actions

* use `sortLogRows` and fix timestamp by id on `makeLogs`

* change clear live logs from based on timestamp to index on logRows

* assign `null` to `clearedAtIndex` on first batch of logs live

* move `isFirstStreaming` implementation to `clearLogs` reducer

* fix `clearLogs` tests

* Update public/app/features/explore/state/query.ts

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
2023-04-20 10:21:28 +02:00

33 lines
986 B
TypeScript

import { MutableDataFrame, LogLevel, LogRowModel, LogsSortOrder } from '@grafana/data';
import { sortLogRows } from 'app/features/logs/utils';
export const makeLogs = (numberOfLogsToCreate: number, overrides?: Partial<LogRowModel>): LogRowModel[] => {
const array: LogRowModel[] = [];
for (let i = 0; i < numberOfLogsToCreate; i++) {
const uuid = (i + 1).toString();
const entry = `log message ${uuid}`;
const timeInMs = overrides?.timeEpochMs || new Date().getTime();
array.push({
uid: uuid,
entryFieldIndex: 0,
rowIndex: 0,
dataFrame: new MutableDataFrame(),
logLevel: LogLevel.debug,
entry,
hasAnsi: false,
hasUnescapedContent: false,
labels: {},
raw: entry,
timeFromNow: '',
timeEpochMs: timeInMs + i,
timeEpochNs: (timeInMs * 1000000 + i).toString(),
timeLocal: '',
timeUtc: '',
...overrides,
});
}
return sortLogRows(array, LogsSortOrder.Ascending);
};