feat(docker): add endpoint filtering and setup assistant

This commit is contained in:
ajnart committed 2026-08-18 17:47:31 +02:00
1 parent 315245e048
commit f9e62a4932
13 files changed
+426 -190

No files matched your search

+14 -5
View File
@@ -196,7 +196,7 @@ const mockContainers: {
];
export const dockerContainersRequestHandler = createWidgetRequestHandler({
async requestAsync() {
async requestAsync({ endpointIds }: { endpointIds?: string[] }) {
if (isDemoMode()) {
return {
containers: mockContainers.map((container) => ({
@@ -219,7 +219,7 @@ export const dockerContainersRequestHandler = createWidgetRequestHandler({
] satisfies DockerEndpointStatus[],
};
}
return await getContainersWithStatsAsync();
return await getContainersWithStatsAsync(dockerWidgetEndpointTimeoutMs, endpointIds);
},
});
@@ -331,9 +331,18 @@ export const getDockerEndpointsAsync = (): DockerEndpointStatus[] => {
];
};
export async function getContainersWithStatsAsync(timeoutMs = dockerWidgetEndpointTimeoutMs) {
const dockerInstances = DockerSingleton.getInstances();
const initializationFailures = DockerSingleton.getInitializationFailures();
export async function getContainersWithStatsAsync(
timeoutMs = dockerWidgetEndpointTimeoutMs,
endpointIds: string[] = [],
) {
const selectedEndpointIds = new Set(endpointIds);
const includesAllEndpoints = selectedEndpointIds.size === 0;
const dockerInstances = DockerSingleton.getInstances().filter(
({ endpointId }) => includesAllEndpoints || selectedEndpointIds.has(endpointId),
);
const initializationFailures = DockerSingleton.getInitializationFailures().filter(
({ descriptor }) => includesAllEndpoints || selectedEndpointIds.has(descriptor.id),
);
const results = await Promise.allSettled(
dockerInstances.map(async ({ instance, host, endpointId, endpointName }) => {
const instanceContainers = await withDockerTimeoutAsync(
@@ -127,6 +127,31 @@ describe("calculateMemoryUsage", () => {
});
describe("getContainersWithStatsAsync", () => {
test("queries only selected Docker endpoints and leaves an empty selection as all", async () => {
const firstListContainers = vi.fn(async () => []);
const secondListContainers = vi.fn(async () => []);
vi.spyOn(DockerSingleton, "getInstances").mockReturnValue([
createDockerInstance("first", firstListContainers),
createDockerInstance("second", secondListContainers),
] as never);
vi.spyOn(DockerSingleton, "getInitializationFailures").mockReturnValue([]);
try {
const selectedResult = await getContainersWithStatsAsync(50, ["second"]);
expect(firstListContainers).not.toHaveBeenCalled();
expect(secondListContainers).toHaveBeenCalledOnce();
expect(selectedResult.endpoints.map(({ id }) => id)).toEqual(["second"]);
await getContainersWithStatsAsync(50, []);
expect(firstListContainers).toHaveBeenCalledOnce();
expect(secondListContainers).toHaveBeenCalledTimes(2);
} finally {
vi.restoreAllMocks();
}
});
test("marks a timed-out endpoint unavailable without blocking healthy endpoints", async () => {
vi.useFakeTimers();
try {