LogsPanel: Speed up labels processing by 50x (#103296)

pull/103307/head
Leon Sorokin 2 months ago committed by GitHub
parent 47ec51fda7
commit c5264e3bfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      .betterer.results
  2. 28
      public/app/features/logs/logsFrame.ts

@ -3805,6 +3805,9 @@ exports[`better eslint`] = {
"public/app/features/logs/components/LogLabelStats.tsx:5381": [
[0, 0, 0, "No untranslated strings. Wrap text with <Trans />", "0"]
],
"public/app/features/logs/logsFrame.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"public/app/features/logs/utils.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],

@ -35,14 +35,32 @@ const DATAPLANE_SEVERITY_NAME = 'severity';
const DATAPLANE_ID_NAME = 'id';
const DATAPLANE_LABELS_NAME = 'labels';
// NOTE: this is a hot fn, we need to avoid allocating new objects here
export function logFrameLabelsToLabels(logFrameLabels: LogFrameLabels): Labels {
const result: Labels = {};
let needsSerialization = false;
Object.entries(logFrameLabels).forEach(([k, v]) => {
result[k] = typeof v === 'string' ? v : JSON.stringify(v);
});
for (const k in logFrameLabels) {
const v = logFrameLabels[k];
return result;
if (typeof v !== 'string') {
needsSerialization = true;
break;
}
}
if (needsSerialization) {
let labels: Labels = {};
for (const k in logFrameLabels) {
const v = logFrameLabels[k];
labels[k] = typeof v === 'string' ? v : JSON.stringify(v);
}
return labels;
}
// @ts-ignore
return logFrameLabels as Labels;
}
export function parseDataplaneLogsFrame(frame: DataFrame): LogsFrame | null {

Loading…
Cancel
Save