feat(charting): unify configurable time windows
This commit is contained in:
@@ -69,6 +69,44 @@ describe("service registry", () => {
|
||||
expect(speed?.defaultConfig.unit).toBe("bytes_per_sec");
|
||||
});
|
||||
|
||||
it("shares expanded chart windows and an all-retained option", () => {
|
||||
const propertiesOf = (kind: string) => {
|
||||
const binding = SERVICE_REGISTRY[
|
||||
kind === "speed" ? "qbittorrent" : "prometheus"
|
||||
].widgets.find((widget) => widget.kind === kind);
|
||||
const schema = binding?.configSchema as
|
||||
| { properties?: Record<string, { enum?: string[] }> }
|
||||
| undefined;
|
||||
return schema?.properties ?? {};
|
||||
};
|
||||
|
||||
expect(propertiesOf("chart").window?.enum).toEqual([
|
||||
"5m",
|
||||
"15m",
|
||||
"30m",
|
||||
"1h",
|
||||
"3h",
|
||||
"6h",
|
||||
"12h",
|
||||
"24h",
|
||||
"2d",
|
||||
"7d",
|
||||
"14d",
|
||||
"30d",
|
||||
]);
|
||||
expect(propertiesOf("speed").window_seconds?.enum).toEqual([
|
||||
"300",
|
||||
"900",
|
||||
"1800",
|
||||
"3600",
|
||||
"10800",
|
||||
"21600",
|
||||
"43200",
|
||||
"86400",
|
||||
"all",
|
||||
]);
|
||||
});
|
||||
|
||||
it("resolves a prometheus metric widget via the services list", () => {
|
||||
const widget: WidgetInstance = {
|
||||
id: "w1",
|
||||
|
||||
@@ -17,6 +17,10 @@ import { RequestStatWidget } from "../widgets/RequestStatWidget";
|
||||
import { RequestsOverviewWidget } from "../widgets/RequestsOverviewWidget";
|
||||
import { SshTaskWidget } from "../widgets/SshTaskWidget";
|
||||
import { StaticWidget } from "../widgets/StaticWidget";
|
||||
import {
|
||||
numericChartRangesThrough,
|
||||
PROMETHEUS_WINDOW_VALUES,
|
||||
} from "../components/chartRanges";
|
||||
import type {
|
||||
ServiceInstance,
|
||||
ServiceTypeInfo,
|
||||
@@ -64,6 +68,10 @@ const UNIT_VALUES = [
|
||||
"seconds",
|
||||
];
|
||||
const SCALE_VALUES = ["auto", "k", "m", "g", "t"];
|
||||
const SPEED_WINDOW_VALUES = [
|
||||
...numericChartRangesThrough(86_400).map(String),
|
||||
"all",
|
||||
];
|
||||
const AXIS_FORMAT_PROPERTIES = {
|
||||
unit: {
|
||||
type: "string",
|
||||
@@ -186,7 +194,8 @@ export const SERVICE_REGISTRY: Record<string, ServiceBinding> = {
|
||||
},
|
||||
window: {
|
||||
type: "string",
|
||||
description: "Time window preset (1h, 6h, 24h, 7d)",
|
||||
enum: PROMETHEUS_WINDOW_VALUES,
|
||||
description: "Maximum history fetched for the chart",
|
||||
},
|
||||
...AXIS_FORMAT_PROPERTIES,
|
||||
},
|
||||
@@ -233,7 +242,8 @@ export const SERVICE_REGISTRY: Record<string, ServiceBinding> = {
|
||||
},
|
||||
window: {
|
||||
type: "string",
|
||||
description: "Time window preset (1h, 6h, 24h, 7d)",
|
||||
enum: PROMETHEUS_WINDOW_VALUES,
|
||||
description: "Time window used to calculate the average",
|
||||
},
|
||||
unit: { type: "string" },
|
||||
},
|
||||
@@ -282,7 +292,9 @@ export const SERVICE_REGISTRY: Record<string, ServiceBinding> = {
|
||||
properties: {
|
||||
window_seconds: {
|
||||
type: "integer",
|
||||
description: "Maximum data window available to the chart",
|
||||
enum: SPEED_WINDOW_VALUES,
|
||||
description:
|
||||
"Maximum history fetched for the chart, or all retained samples",
|
||||
},
|
||||
...AXIS_FORMAT_PROPERTIES,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user