1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix fill the gaps logic in normalize metrics (#1940)

* fix fill the gaps logic in normalize metrics

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2021-01-12 12:01:06 +02:00 committed by GitHub
parent b1ab31831f
commit 11595abc93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,11 +78,25 @@ export function normalizeMetrics(metrics: IMetrics, frames = 60): IMetrics {
result.forEach(res => { result.forEach(res => {
if (!res.values || !res.values.length) return; if (!res.values || !res.values.length) return;
let now = moment().startOf("minute").subtract(1, "minute").unix();
let timestamp = res.values[0][0];
while (timestamp <= now) {
timestamp = moment.unix(timestamp).add(1, "minute").unix();
if (!res.values.find((value) => value[0] === timestamp)) {
res.values.push([timestamp, "0"]);
}
}
while (res.values.length < frames) { while (res.values.length < frames) {
const timestamp = moment.unix(res.values[0][0]).subtract(1, "minute").unix(); const timestamp = moment.unix(res.values[0][0]).subtract(1, "minute").unix();
if (!res.values.find((value) => value[0] === timestamp)) {
res.values.unshift([timestamp, "0"]); res.values.unshift([timestamp, "0"]);
} }
now = timestamp;
}
}); });
} }
} }