-
Notifications
You must be signed in to change notification settings - Fork 85
feat(provider): implement streamer walking skeleton with end-to-end write path #3153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stalniy
wants to merge
9
commits into
main
Choose a base branch
from
feat/pinventory-skeleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
49d68d2
feat(provider): implement streamer walking skeleton with end-to-end w…
stalniy c707371
feat(provider): apply review feedback to streamer walking skeleton
stalniy d0f7f45
feat(provider): add bigint-safe JSONB serialization for inventory pay…
stalniy 38dddb2
feat(provider): only promote JSONB integers to bigint on precision loss
stalniy 595cb93
fix(provider): stop streams for providers that leave discovery results
stalniy a3185d2
refactor(provider): inline reduceAttributes into the writer
stalniy 523dc01
refactor(provider): split writer into upsertInventory and upsertAttri…
stalniy 48227bf
refactor(provider): add readonly to constructor-assigned private fields
stalniy 2eb2d69
test(provider): add unit tests for StreamLifecycleManagerService
stalniy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
268 changes: 268 additions & 0 deletions
268
apps/provider-inventory/src/lib/compute-rollups/compute-rollups.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { computeRollups } from "./compute-rollups"; | ||
|
|
||
| describe(computeRollups.name, () => { | ||
| it("returns all zeros for an empty cluster", () => { | ||
| const result = computeRollups({ nodes: [], storage: [] }); | ||
|
|
||
| expect(result).toEqual({ | ||
| totalAvailableCpu: 0n, | ||
| totalAvailableMemory: 0n, | ||
| totalAvailableGpu: 0n, | ||
| totalAvailableEph: 0n, | ||
| totalAvailablePersistent: 0n, | ||
| maxNodeFreeCpu: 0n, | ||
| maxNodeFreeMemory: 0n, | ||
| maxNodeFreeGpu: 0n, | ||
| gpuModels: [], | ||
| storageClasses: [] | ||
| }); | ||
| }); | ||
|
|
||
| it("computes rollups for a single node", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 4000 }, | ||
| memory: { available: 8_000_000_000 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: 2 }], | ||
| ephStorage: { available: 100_000_000_000 }, | ||
| persistentStorage: [{ class: "beta2", available: 500_000_000_000 }] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableCpu).toBe(4000n); | ||
| expect(result.totalAvailableMemory).toBe(8_000_000_000n); | ||
| expect(result.totalAvailableGpu).toBe(2n); | ||
| expect(result.totalAvailableEph).toBe(100_000_000_000n); | ||
| expect(result.totalAvailablePersistent).toBe(500_000_000_000n); | ||
| expect(result.maxNodeFreeCpu).toBe(4000n); | ||
| expect(result.maxNodeFreeMemory).toBe(8_000_000_000n); | ||
| expect(result.maxNodeFreeGpu).toBe(2n); | ||
| expect(result.gpuModels).toEqual(["nvidia/a100"]); | ||
| expect(result.storageClasses).toEqual(["beta2"]); | ||
| }); | ||
|
|
||
| it("sums totals across multiple nodes and tracks max-per-node", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 2000 }, | ||
| memory: { available: 4_000_000_000 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: 1 }], | ||
| ephStorage: { available: 50_000_000_000 }, | ||
| persistentStorage: [] | ||
| }, | ||
| { | ||
| name: "node-2", | ||
| cpu: { available: 8000 }, | ||
| memory: { available: 16_000_000_000 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: 4 }], | ||
| ephStorage: { available: 200_000_000_000 }, | ||
| persistentStorage: [{ class: "beta2", available: 1_000_000_000_000 }] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableCpu).toBe(10_000n); | ||
| expect(result.totalAvailableMemory).toBe(20_000_000_000n); | ||
| expect(result.totalAvailableGpu).toBe(5n); | ||
| expect(result.totalAvailableEph).toBe(250_000_000_000n); | ||
| expect(result.totalAvailablePersistent).toBe(1_000_000_000_000n); | ||
| expect(result.maxNodeFreeCpu).toBe(8000n); | ||
| expect(result.maxNodeFreeMemory).toBe(16_000_000_000n); | ||
| expect(result.maxNodeFreeGpu).toBe(4n); | ||
| }); | ||
|
|
||
| it("deduplicates GPU models across nodes", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 1000 }, | ||
| memory: { available: 1000 }, | ||
| gpu: [ | ||
| { vendor: "nvidia", model: "a100", available: 1 }, | ||
| { vendor: "amd", model: "mi300x", available: 1 } | ||
| ], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [] | ||
| }, | ||
| { | ||
| name: "node-2", | ||
| cpu: { available: 1000 }, | ||
| memory: { available: 1000 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: 2 }], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.gpuModels).toEqual(["amd/mi300x", "nvidia/a100"]); | ||
| }); | ||
|
|
||
| it("handles ephemeral-only storage", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 1000 }, | ||
| memory: { available: 1000 }, | ||
| gpu: [], | ||
| ephStorage: { available: 500_000_000_000 }, | ||
| persistentStorage: [] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableEph).toBe(500_000_000_000n); | ||
| expect(result.totalAvailablePersistent).toBe(0n); | ||
| expect(result.storageClasses).toEqual([]); | ||
| }); | ||
|
|
||
| it("handles persistent-only storage with multiple classes", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 1000 }, | ||
| memory: { available: 1000 }, | ||
| gpu: [], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [ | ||
| { class: "beta2", available: 100_000_000_000 }, | ||
| { class: "beta3", available: 200_000_000_000 } | ||
| ] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailablePersistent).toBe(300_000_000_000n); | ||
| expect(result.storageClasses).toEqual(["beta2", "beta3"]); | ||
| }); | ||
|
|
||
| it("collects storage classes from both nodes and cluster-level storage", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 0 }, | ||
| memory: { available: 0 }, | ||
| gpu: [], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [{ class: "beta2", available: 100 }] | ||
| } | ||
| ], | ||
| storage: [{ class: "beta3", available: 500 }] | ||
| }); | ||
|
|
||
| expect(result.storageClasses).toEqual(["beta2", "beta3"]); | ||
| }); | ||
|
|
||
| it("handles nodes with no GPUs", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 4000 }, | ||
| memory: { available: 8_000_000_000 }, | ||
| gpu: [], | ||
| ephStorage: { available: 100_000_000_000 }, | ||
| persistentStorage: [] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableGpu).toBe(0n); | ||
| expect(result.maxNodeFreeGpu).toBe(0n); | ||
| expect(result.gpuModels).toEqual([]); | ||
| }); | ||
|
|
||
| it("clamps negative values to zero (overcommit)", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "overcommitted", | ||
| cpu: { available: -500 }, | ||
| memory: { available: -1_000_000 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: -1 }], | ||
| ephStorage: { available: -100 }, | ||
| persistentStorage: [{ class: "beta2", available: -200 }] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableCpu).toBe(0n); | ||
| expect(result.totalAvailableMemory).toBe(0n); | ||
| expect(result.totalAvailableGpu).toBe(0n); | ||
| expect(result.totalAvailableEph).toBe(0n); | ||
| expect(result.totalAvailablePersistent).toBe(0n); | ||
| expect(result.maxNodeFreeCpu).toBe(0n); | ||
| expect(result.maxNodeFreeMemory).toBe(0n); | ||
| expect(result.maxNodeFreeGpu).toBe(0n); | ||
| }); | ||
|
|
||
| it("handles all-zero capacity", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "idle", | ||
| cpu: { available: 0 }, | ||
| memory: { available: 0 }, | ||
| gpu: [], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.totalAvailableCpu).toBe(0n); | ||
| expect(result.totalAvailableMemory).toBe(0n); | ||
| expect(result.maxNodeFreeCpu).toBe(0n); | ||
| expect(result.maxNodeFreeMemory).toBe(0n); | ||
| }); | ||
|
|
||
| it("sums GPU count per node for max-node-free-gpu", () => { | ||
| const result = computeRollups({ | ||
| nodes: [ | ||
| { | ||
| name: "node-1", | ||
| cpu: { available: 0 }, | ||
| memory: { available: 0 }, | ||
| gpu: [ | ||
| { vendor: "nvidia", model: "a100", available: 2 }, | ||
| { vendor: "nvidia", model: "h100", available: 3 } | ||
| ], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [] | ||
| }, | ||
| { | ||
| name: "node-2", | ||
| cpu: { available: 0 }, | ||
| memory: { available: 0 }, | ||
| gpu: [{ vendor: "nvidia", model: "a100", available: 4 }], | ||
| ephStorage: { available: 0 }, | ||
| persistentStorage: [] | ||
| } | ||
| ], | ||
| storage: [] | ||
| }); | ||
|
|
||
| expect(result.maxNodeFreeGpu).toBe(5n); | ||
| expect(result.totalAvailableGpu).toBe(9n); | ||
| expect(result.gpuModels).toEqual(["nvidia/a100", "nvidia/h100"]); | ||
| }); | ||
| }); |
65 changes: 65 additions & 0 deletions
65
apps/provider-inventory/src/lib/compute-rollups/compute-rollups.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { Inventory, InventoryRollups } from "@src/types/inventory"; | ||
|
|
||
| export function computeRollups(inventory: Inventory): InventoryRollups { | ||
| let totalAvailableCpu = 0n; | ||
| let totalAvailableMemory = 0n; | ||
| let totalAvailableGpu = 0n; | ||
| let totalAvailableEph = 0n; | ||
| let totalAvailablePersistent = 0n; | ||
| let maxNodeFreeCpu = 0n; | ||
| let maxNodeFreeMemory = 0n; | ||
| let maxNodeFreeGpu = 0n; | ||
| const gpuModelSet = new Set<string>(); | ||
| const storageClassSet = new Set<string>(); | ||
|
|
||
| for (const node of inventory.nodes) { | ||
| const nodeCpu = clamp(node.cpu.available); | ||
| const nodeMemory = clamp(node.memory.available); | ||
| const nodeEph = clamp(node.ephStorage.available); | ||
|
|
||
| totalAvailableCpu += nodeCpu; | ||
| totalAvailableMemory += nodeMemory; | ||
| totalAvailableEph += nodeEph; | ||
|
|
||
| if (nodeCpu > maxNodeFreeCpu) maxNodeFreeCpu = nodeCpu; | ||
| if (nodeMemory > maxNodeFreeMemory) maxNodeFreeMemory = nodeMemory; | ||
|
|
||
| let nodeGpuTotal = 0n; | ||
| for (const gpu of node.gpu) { | ||
| const gpuCount = clamp(gpu.available); | ||
| nodeGpuTotal += gpuCount; | ||
| totalAvailableGpu += gpuCount; | ||
| if (gpu.vendor && gpu.model) { | ||
| gpuModelSet.add(`${gpu.vendor}/${gpu.model}`); | ||
| } | ||
| } | ||
| if (nodeGpuTotal > maxNodeFreeGpu) maxNodeFreeGpu = nodeGpuTotal; | ||
|
|
||
| for (const ps of node.persistentStorage) { | ||
| totalAvailablePersistent += clamp(ps.available); | ||
| if (ps.class) storageClassSet.add(ps.class); | ||
| } | ||
| } | ||
|
|
||
| for (const s of inventory.storage) { | ||
| if (s.class) storageClassSet.add(s.class); | ||
| } | ||
|
|
||
| return { | ||
| totalAvailableCpu, | ||
| totalAvailableMemory, | ||
| totalAvailableGpu, | ||
| totalAvailableEph, | ||
| totalAvailablePersistent, | ||
| maxNodeFreeCpu, | ||
| maxNodeFreeMemory, | ||
| maxNodeFreeGpu, | ||
| gpuModels: [...gpuModelSet].sort(), | ||
| storageClasses: [...storageClassSet].sort() | ||
| }; | ||
| } | ||
|
|
||
| function clamp(value: number): bigint { | ||
| if (!Number.isFinite(value) || value <= 0) return 0n; | ||
| return BigInt(value); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.