Logs: Fix total bytes process calculation (#24691)

- log stats for Loki are per query
- this change tracks the query stats by refId, preventing the summing of
    the same stats across multiple series of the same response.
This commit is contained in:
David 2020-05-14 16:27:26 +02:00 committed by GitHub
parent 405145fdd3
commit 25e1238022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -384,13 +384,19 @@ export function logSeriesToLogsModel(logSeries: DataFrame[]): LogsModel | undefi
// Hack to print loki stats in Explore. Should be using proper stats display via drawer in Explore (rework in 7.1) // Hack to print loki stats in Explore. Should be using proper stats display via drawer in Explore (rework in 7.1)
let totalBytes = 0; let totalBytes = 0;
const queriesVisited: { [refId: string]: boolean } = {};
for (const series of logSeries) { for (const series of logSeries) {
const totalBytesKey = series.meta?.custom?.lokiQueryStatKey; const totalBytesKey = series.meta?.custom?.lokiQueryStatKey;
if (totalBytesKey && series.meta.stats) { // Stats are per query, keeping track by refId
const byteStat = series.meta.stats.find(stat => stat.displayName === totalBytesKey); const { refId } = series;
if (byteStat) { if (refId && !queriesVisited[refId]) {
totalBytes += byteStat.value; 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) { if (totalBytes > 0) {