feat: add combineSeries for GPU combination aggregation

This commit is contained in:
c4ch3c4d3
2026-08-14 12:59:41 -06:00
parent 15627fc494
commit 74d0c10523
2 changed files with 41 additions and 1 deletions
+29 -1
View File
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";
import { type LlamaSwapConfig } from "../src/lib/util";
import { MetricsPoller } from "../src/lib/metrics-poller";
import { combineSeries, MetricsPoller } from "../src/lib/metrics-poller";
const FIXTURE = readFileSync(new URL("./fixtures/metrics.txt", import.meta.url), "utf8");
@@ -61,3 +61,31 @@ test("poller reports offline after a fetch failure and recovers", async () => {
assert.equal(poller.isOffline(), false);
assert.ok(poller.getValue("0", "util_percent") !== undefined);
});
test("combineSeries averages util and sums power", () => {
const util = combineSeries(
[
[10, 20, 30],
[20, 40, 60],
],
"util_percent",
);
assert.deepEqual(util, { value: 45, history: [15, 30, 45] });
const power = combineSeries(
[
[100, 200],
[150, 250],
],
"power",
);
assert.deepEqual(power, { value: 450, history: [250, 450] });
});
test("combineSeries takes the max temperature and skips gaps", () => {
const temp = combineSeries([[50, 70], [60]], "temperature");
assert.deepEqual(temp, { value: 70, history: [60, 70] });
const empty = combineSeries([[], []], "temperature");
assert.deepEqual(empty, { value: undefined, history: [] });
});