mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Loki: Bring back processed bytes as meta info (#34092)
* Loki: Bring back processed bytes as meta info * style: Lint
This commit is contained in:
parent
e21b90681f
commit
6796a89e9d
@ -698,6 +698,8 @@ describe('logSeriesToLogsModel', () => {
|
||||
meta: {
|
||||
searchWords: ['test'],
|
||||
limit: 1000,
|
||||
stats: [{ displayName: 'Summary: total bytes processed', value: 97048, unit: 'decbytes' }],
|
||||
custom: { lokiQueryStatKey: 'Summary: total bytes processed' },
|
||||
preferredVisualisationType: 'logs',
|
||||
},
|
||||
},
|
||||
@ -705,7 +707,10 @@ describe('logSeriesToLogsModel', () => {
|
||||
|
||||
const metaData = {
|
||||
hasUniqueLabels: false,
|
||||
meta: [{ label: LIMIT_LABEL, value: 1000, kind: 0 }],
|
||||
meta: [
|
||||
{ label: LIMIT_LABEL, value: 1000, kind: 0 },
|
||||
{ label: 'Total bytes processed', value: '97.0 kB', kind: 1 },
|
||||
],
|
||||
rows: [],
|
||||
};
|
||||
|
||||
@ -739,6 +744,8 @@ describe('logSeriesToLogsModel', () => {
|
||||
meta: {
|
||||
searchWords: ['test'],
|
||||
limit: 1000,
|
||||
stats: [{ displayName: 'Summary: total bytes processed', value: 97048, unit: 'decbytes' }],
|
||||
custom: { lokiQueryStatKey: 'Summary: total bytes processed' },
|
||||
preferredVisualisationType: 'logs',
|
||||
},
|
||||
}),
|
||||
@ -749,6 +756,8 @@ describe('logSeriesToLogsModel', () => {
|
||||
meta: {
|
||||
searchWords: ['test'],
|
||||
limit: 1000,
|
||||
stats: [{ displayName: 'Summary: total bytes processed', value: 97048, unit: 'decbytes' }],
|
||||
custom: { lokiQueryStatKey: 'Summary: total bytes processed' },
|
||||
preferredVisualisationType: 'logs',
|
||||
},
|
||||
}),
|
||||
@ -758,6 +767,7 @@ describe('logSeriesToLogsModel', () => {
|
||||
expect(logsModel.meta).toMatchObject([
|
||||
{ kind: 2, label: 'Common labels', value: { foo: 'bar', level: 'dbug' } },
|
||||
{ kind: 0, label: LIMIT_LABEL, value: 2000 },
|
||||
{ kind: 1, label: 'Total bytes processed', value: '194 kB' },
|
||||
]);
|
||||
expect(logsModel.rows).toHaveLength(3);
|
||||
expect(logsModel.rows).toMatchObject([
|
||||
|
@ -33,6 +33,7 @@ import {
|
||||
DataQuery,
|
||||
} from '@grafana/data';
|
||||
import { getThemeColor } from 'app/core/utils/colors';
|
||||
import { SIPrefix } from '@grafana/data/src/valueFormats/symbolFormatters';
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const LIMIT_LABEL = 'Line limit';
|
||||
@ -443,10 +444,16 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
kind: LogsMetaKind.Number,
|
||||
});
|
||||
}
|
||||
|
||||
let totalBytes = 0;
|
||||
const queriesVisited: { [refId: string]: boolean } = {};
|
||||
// To add just 1 error message
|
||||
let errorMetaAdded = false;
|
||||
|
||||
for (const series of logSeries) {
|
||||
const totalBytesKey = series.meta?.custom?.lokiQueryStatKey;
|
||||
const { refId } = series; // Stats are per query, keeping track by refId
|
||||
|
||||
if (!errorMetaAdded && series.meta?.custom?.error) {
|
||||
meta.push({
|
||||
label: '',
|
||||
@ -455,7 +462,28 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
|
||||
});
|
||||
errorMetaAdded = true;
|
||||
}
|
||||
|
||||
if (refId && !queriesVisited[refId]) {
|
||||
if (totalBytesKey && series.meta?.stats) {
|
||||
const byteStat = series.meta.stats.find((stat) => stat.displayName === totalBytesKey);
|
||||
if (byteStat) {
|
||||
totalBytes += byteStat.value;
|
||||
}
|
||||
}
|
||||
|
||||
queriesVisited[refId] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (totalBytes > 0) {
|
||||
const { text, suffix } = SIPrefix('B')(totalBytes);
|
||||
meta.push({
|
||||
label: 'Total bytes processed',
|
||||
value: `${text} ${suffix}`,
|
||||
kind: LogsMetaKind.String,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
hasUniqueLabels,
|
||||
meta,
|
||||
|
Loading…
Reference in New Issue
Block a user