-
Notifications
You must be signed in to change notification settings - Fork 8
Reduce contracts and deployments loading time #4233
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
Draft
samaradel
wants to merge
18
commits into
development
Choose a base branch
from
dev_load_deployments_performance
base: development
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.
Draft
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1f525e8
- Load all deployments in parallel
samaradel 3e900a9
Optimize contracts fetching
samaradel 23301da
Merge branch 'development' into dev_load_deployments_performance
samaradel 236bbbb
Remove unused vars
samaradel 2cb4f99
Use promise.allSettled instead
samaradel 0482f2c
Replace promise.all accross all deployments files
samaradel 3484c4c
- Run the three independent calls using Promise.allSettled
samaradel 500da01
Fully parallel cluster detail loading
samaradel f90894e
- Handle the failure of VM deployments
samaradel 26d9a93
- Run batches in parallel
samaradel 2d1bb02
- Remove dead code
samaradel 91d0faf
Fix batch process calling
samaradel 13747a8
Use cached getGridClient instead of updateGrid to avoid recreating mo…
samaradel c62179c
Merge branch 'development' into dev_load_deployments_performance
samaradel 3d9814c
Fix conflicts
samaradel 469b79b
Fix load network duplicates
samaradel 784df78
Merge branch 'development' into dev_load_deployments_performance
samaradel 3796e69
Fix conflicts
samaradel 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ | |
<span> | ||
This might happen because the node is down or it's not reachable | ||
<span v-if="showEncryption"> | ||
or the deployment{{ count - items.length > 1 ? "s are" : " is" }} encrypted by another key | ||
</span>. | ||
or the deployment{{ count - items.length > 1 ? "s are" : " is" }} encrypted by another key </span>. | ||
</span> | ||
<v-tooltip location="top" text="Show failed deployments"> | ||
<template #activator="{ props: tooltipProps }"> | ||
|
@@ -166,9 +165,9 @@ import { onMounted, ref } from "vue"; | |
import { getNodeHealthColor, NodeHealth } from "@/utils/get_nodes"; | ||
|
||
import { useProfileManager } from "../stores"; | ||
import { getGrid, updateGrid } from "../utils/grid"; | ||
import { getGrid } from "../utils/grid"; | ||
import { markAsFromAnotherClient } from "../utils/helpers"; | ||
import { type K8S, type LoadedDeployments, loadK8s, mergeLoadedDeployments } from "../utils/load_deployment"; | ||
import { loadK8s, mergeLoadedDeployments, getGridClient } from "../utils/load_deployment"; | ||
const profileManager = useProfileManager(); | ||
const showDialog = ref(false); | ||
const showEncryption = ref(false); | ||
|
@@ -188,35 +187,108 @@ const loading = ref(false); | |
|
||
onMounted(loadDeployments); | ||
async function loadDeployments() { | ||
const start = performance.now(); | ||
items.value = []; | ||
loading.value = true; | ||
const grid = await getGrid(profileManager.profile!, props.projectName); | ||
const chunk1 = await loadK8s(grid!); | ||
const chunk2 = await loadK8s(updateGrid(grid!, { projectName: props.projectName.toLowerCase() })); | ||
let chunk3: LoadedDeployments<K8S> = { count: 0, items: [], failedDeployments: [] }; | ||
|
||
if (showAllDeployments.value) { | ||
chunk3 = await loadK8s(updateGrid(grid!, { projectName: "" })); | ||
chunk3.items = chunk3.items.map(i => { | ||
return !i.projectName || i.projectName === "Kubernetes" ? markAsFromAnotherClient(i) : i; | ||
try { | ||
const grid = await getGrid(profileManager.profile!, props.projectName); | ||
if (!grid) { | ||
loading.value = false; | ||
0oM4R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.error("Failed to initialize grid connection"); | ||
return; | ||
} | ||
const shouldLoadAllDeployments = showAllDeployments.value; | ||
const results = await Promise.allSettled([ | ||
loadK8s(grid), | ||
loadK8s(await getGridClient(grid.clientOptions, props.projectName.toLowerCase())), | ||
shouldLoadAllDeployments | ||
? loadK8s(await getGridClient(grid.clientOptions, "")) | ||
: Promise.resolve({ count: 0, items: [], failedDeployments: [] }), | ||
]); | ||
const chunk1 = | ||
results[0].status === "fulfilled" | ||
? results[0].value | ||
: (() => { | ||
console.error("Failed to load K8s deployments from default project:", results[0].reason); | ||
return { count: 0, items: [], failedDeployments: [] }; | ||
})(); | ||
const chunk2 = | ||
results[1].status === "fulfilled" | ||
? results[1].value | ||
: (() => { | ||
console.error(`Failed to load K8s deployments from project "${props.projectName}":`, results[1].reason); | ||
return { count: 0, items: [], failedDeployments: [] }; | ||
})(); | ||
const chunk3 = | ||
results[2].status === "fulfilled" | ||
? results[2].value | ||
: (() => { | ||
console.error("Failed to load K8s deployments from all projects:", results[2].reason); | ||
return { count: 0, items: [], failedDeployments: [] }; | ||
})(); | ||
if (chunk3.items) { | ||
chunk3.items = chunk3.items.map(i => { | ||
return !i.projectName || i.projectName === "Kubernetes" ? markAsFromAnotherClient(i) : i; | ||
}); | ||
} | ||
const clusters = mergeLoadedDeployments(chunk1, chunk2, chunk3); | ||
failedDeployments.value = clusters.failedDeployments; | ||
count.value = clusters.count; | ||
items.value = clusters.items.map(item => { | ||
const master = item.masters[0]; | ||
const publicIP = master.publicIP?.ip; | ||
return { | ||
...item, | ||
name: item.deploymentName, | ||
ipv4: publicIP ? publicIP.split("/")?.[0] || publicIP : "-", | ||
ipv6: master.publicIP?.ip6?.replace(/\/64$/, "") || "-", | ||
planetary: master.planetary || "-", | ||
workersLength: item.workers.length, | ||
billing: undefined, | ||
wireguard: undefined, | ||
detailsLoading: false, | ||
}; | ||
}); | ||
|
||
await Promise.allSettled(items.value.map(item => fetchClusterDetails(item))); | ||
} catch (error) { | ||
console.error("Error loading deployments:", error); | ||
items.value = []; | ||
count.value = 0; | ||
failedDeployments.value = []; | ||
} finally { | ||
loading.value = false; | ||
const end = performance.now(); | ||
console.log(`Time taken: ${(end - start) / 1000} seconds`); | ||
} | ||
} | ||
|
||
async function fetchClusterDetails(item: any) { | ||
if (item.detailsLoading || (item.billing !== undefined && item.wireguard !== undefined)) return; | ||
0oM4R marked this conversation as resolved.
Show resolved
Hide resolved
|
||
item.detailsLoading = true; | ||
try { | ||
const grid = await getGrid(profileManager.profile!, item.projectName || props.projectName); | ||
if (!grid) { | ||
item.detailsLoading = false; | ||
return; | ||
} | ||
|
||
const clusters = mergeLoadedDeployments(chunk1, chunk2, chunk3); | ||
failedDeployments.value = clusters.failedDeployments; | ||
|
||
count.value = clusters.count; | ||
items.value = clusters.items.map((item: any) => { | ||
item.name = item.deploymentName; | ||
item.ipv4 = item.masters[0].publicIP?.ip?.split("/")?.[0] || item.masters[0].publicIP?.ip || "-"; | ||
item.ipv6 = item.masters[0].publicIP?.ip6.replace(/\/64$/, "") || "-"; | ||
item.planetary = item.masters[0].planetary || "-"; | ||
item.workersLength = item.workers.length; | ||
item.billing = item.masters[0].billing; | ||
item.created = item.masters[0].created; | ||
return item; | ||
}); | ||
loading.value = false; | ||
const [consumption, wireguardConfig] = await Promise.allSettled([ | ||
grid.contracts.getConsumption({ id: item.masters[0].contractId }), | ||
grid.networks.getWireGuardConfigs({ | ||
name: item.masters[0].interfaces[0].network, | ||
ipRange: item.masters[0].interfaces[0].ip, | ||
}), | ||
]); | ||
|
||
item.billing = | ||
consumption.status === "fulfilled" && consumption.value ? consumption.value.amountBilled : "No Data Available"; | ||
|
||
item.wireguard = | ||
wireguardConfig.status === "fulfilled" && wireguardConfig.value?.[0] ? wireguardConfig.value[0] : undefined; | ||
} finally { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a catch block; to at least log the errors There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
item.detailsLoading = false; | ||
} | ||
} | ||
|
||
defineExpose({ loadDeployments }); | ||
|
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.