grafana/public/app/features/logs/components/panel/processing.ts

67 lines
1.6 KiB
TypeScript
Raw Normal View History

Logs Panel: Base elements for the new visualization (#99084) * Create base components * Create measurement service * Add container for list * Use measurement to render virtualized log lines * Match rendered styles in 2d context for measuring * Improve virtualization initialization and handle resize * Introduce log line processing * Virtualization: fix measurement of lines with line endings * Virtualization: include scrollbar width in calculation * Remove logs * Virtualization: optimize text measurement * Add support for forceEscape * Log line: properly style wrapped/unwrapped lines * Virtualization: handle possible overflows * Improve overflow handling * LogList: remove scroll position ref * Remove logs * Remove log * Add top/bottom navigation buttons * Add timestamp to pre-processing * Add showtime support * Fix imports * Chore: simplify dedup * Show level * Refactor measurement and measure level and timestamp * Virtualization: skip unnecessary measurements * Improve measurements to minimize overflow chance * Introduce logline colors * Update palette * Remove pretiffying * Add comment * Remove unused variable * Add color for info level * Fix dependencies * Refactor overflow to account for smaller estimations * Debounce resizing * Fix imports * Further optimize height calculation * Remove outline * Unused import * Use less under/overflow method * Respond to height changes * Refactor size adjustment to account for layout changes * Add Logs Panel support * Add margin bottom to log lines * Remove unused option * LogList: container div should never be null Bad API design * Log List: make app not undefined and update containerElement usages * New Logs Panel: Create as new visualization (#99427) * Logs Panel: clean up old panel * Logs Panel New: create as new visualization * Plugin: mark as alpha * Logs panel new: hold container in a state variable * Logs panel: fix no data state * Create newLogsPanel feature flag * Logs: use new feature flag * Prettier * Add new panel to code owners * Logs Navigation: add translations * Address betterer issues * Fix import * Extract translations * Update virtualization.ts * Virtualization: add DOM fallback for text measurement * Run gen-cue * plugins_integration_test: add logs-new to expected plugins
2025-02-05 01:40:17 +08:00
import { dateTimeFormat, LogRowModel, LogsSortOrder } from '@grafana/data';
import { escapeUnescapedString, sortLogRows } from '../../utils';
import { measureTextWidth } from './virtualization';
export interface ProcessedLogModel extends LogRowModel {
body: string;
timestamp: string;
dimensions: LogDimensions;
}
export interface LogDimensions {
timestampWidth: number;
levelWidth: number;
}
interface PreProcessOptions {
escape: boolean;
order: LogsSortOrder;
timeZone: string;
wrap: boolean;
}
export const preProcessLogs = (
logs: LogRowModel[],
{ escape, order, timeZone, wrap }: PreProcessOptions
): ProcessedLogModel[] => {
const orderedLogs = sortLogRows(logs, order);
return orderedLogs.map((log) => preProcessLog(log, { wrap, escape, timeZone, expanded: false }));
};
interface PreProcessLogOptions {
escape: boolean;
expanded: boolean; // Not yet implemented
timeZone: string;
wrap: boolean;
}
const preProcessLog = (
log: LogRowModel,
{ escape, expanded, timeZone, wrap }: PreProcessLogOptions
): ProcessedLogModel => {
let body = log.entry;
const timestamp = dateTimeFormat(log.timeEpochMs, {
timeZone,
defaultWithMS: true,
});
if (escape && log.hasUnescapedContent) {
body = escapeUnescapedString(body);
}
// With wrapping disabled, we want to turn it into a single-line log entry unless the line is expanded
if (!wrap && !expanded) {
body = body.replace(/(\r\n|\n|\r)/g, '');
}
return {
...log,
body,
timestamp,
dimensions: {
timestampWidth: measureTextWidth(timestamp),
levelWidth: measureTextWidth(log.logLevel),
},
};
};