Skip to content

Commit ae86b04

Browse files
committed
fix: resolves #185
1 parent df76470 commit ae86b04

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

frontend/src/queries/get_dry_run_metrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const getDryRunMetricsQuery = gql`
1212
phase
1313
type
1414
... on DryRunNodePod {
15+
id
1516
displayName
1617
startedAt
1718
finishedAt

frontend/src/queries/get_dry_run_phase_results.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const getDryRunPhaseResultsQuery = gql`
88
phase
99
type
1010
... on DryRunNodePod {
11+
id
1112
displayName
1213
startedAt
1314
finishedAt

frontend/src/routes/projects/dryruns/[dry_run]/[resource]/+page.svelte

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import getProjectQuery from '$queries/get_project';
88
import getDryRunPhaseResultsQuery from '$queries/get_dry_run_phase_results';
99
import getDryRunQuery from '$queries/get_selected_project';
10+
import getCarbontrackerDataQuery from '$queries/get_carbontracker_metrics';
1011
import { requestGraphQLClient } from '$lib/graphqlUtils';
1112
import { goto } from '$app/navigation';
1213
import Plot from './plot.svelte';
@@ -127,6 +128,34 @@
127128
}
128129
};
129130
131+
async function getCarbontrackerDataResponse(input: any): Promise<any> {
132+
const inputData = {
133+
input: {
134+
data: {
135+
dryRun: {
136+
node: {
137+
metrics: {
138+
cpuUsageSecondsTotal: input,
139+
}
140+
}
141+
}
142+
}
143+
}
144+
};
145+
console.log('inputData:', inputData);
146+
try {
147+
const response = await requestGraphQLClient(getCarbontrackerDataQuery, inputData);
148+
return response;
149+
} catch (error) {
150+
const title = 'Internal error!';
151+
const body = `${(error as Error).message}`;
152+
// await displayAlert(title, body, 10_000);
153+
console.log(title, body);
154+
return undefined;
155+
}
156+
}
157+
158+
130159
const getData = async (): Promise<{
131160
workflow: any;
132161
dryrun: any;
@@ -180,12 +209,38 @@
180209
cumulativeNetworkData = result.cumulativeNetworkData;
181210
currentNetworkData = result.currentNetworkData;
182211
logs = result.logs;
212+
//console.log('dryRunId:', $selectedDryRunName);
213+
const carbontracker_data = [];
214+
for (const step of metricsResponse) {
215+
if (step.type === 'Pod') {
216+
const carbonResponse = await getCarbontrackerDataResponse(step.metrics.cpuUsageSecondsTotal);
217+
carbontracker_data.push({
218+
nodeId: step.id,
219+
stepName: step.displayName,
220+
carbonData: carbonResponse
221+
});
222+
223+
}
224+
}
225+
226+
// Merge carbontracker data with stepsList
227+
$stepsList = $stepsList.map(step => {
228+
const carbonData = carbontracker_data.find(carbon => carbon.nodeId === step.id);
229+
return {
230+
...step,
231+
carbontracker: carbonData ? carbonData.carbonData : null
232+
};
233+
});
234+
183235
const responses = {
184236
workflow: workflowResponse.project,
185237
dryrun: dryrunResponse,
186238
metrics: metricsResponse,
187-
allstepnames: allStepNames
239+
allstepnames: allStepNames,
240+
selectedDryRunName: $selectedDryRunName,
241+
carbontracker_data
188242
};
243+
console.log('responses:', responses);
189244
return responses;
190245
};
191246
@@ -496,6 +551,8 @@
496551
<th>Started</th>
497552
<th>Finished</th>
498553
<th>Duration</th>
554+
<th>CO2 [<span class="lowercase">g</span>]</th>
555+
<th>Energy [<span class="lowercase">k</span>Wh]</th>
499556
<th>Status</th>
500557
<th>Output</th>
501558
</tr>
@@ -505,14 +562,28 @@
505562
<!-- eslint-disable-next-line @typescript-eslint/explicit-function-return-type -->
506563
<tr on:click={() => stepOnClick(step.displayName)}>
507564
<td style="width:15%">{step.displayName}</td>
508-
<td style="width:20%">
565+
<td style="width:15%">
509566
{step.startedAt ?? '-'}
510567
</td>
511-
<td style="width:20%">
568+
<td style="width:15%">
512569
{step.finishedAt ?? '-'}
513570
</td>
514-
<td style="width:15%">{displayStepDuration(step)}</td>
515-
<td style="width:15%">{step.phase}</td>
571+
<td style="width:10%">{displayStepDuration(step)}</td>
572+
<td style="width:10%">
573+
{#if step.carbontracker?.fetchCarbontrackerData?.co2eq}
574+
{step.carbontracker.fetchCarbontrackerData.co2eq.toFixed(3)}
575+
{:else}
576+
-
577+
{/if}
578+
</td>
579+
<td style="width:10%">
580+
{#if step.carbontracker?.fetchCarbontrackerData?.energy}
581+
{step.carbontracker.fetchCarbontrackerData.energy.toFixed(6)}
582+
{:else}
583+
-
584+
{/if}
585+
</td>
586+
<td style="width:10%">{step.phase}</td>
516587
<td style="width:15%">
517588
{#if step.outputArtifacts?.length > 1}
518589
{#each step.outputArtifacts as artifact}

frontend/src/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export type DryRun = {
5050
export type DryRunMetrics = {
5151
phase: string;
5252
displayName: string;
53+
id: string;
5354
startedAt: string;
5455
finishedAt: string;
5556
duration: number;

0 commit comments

Comments
 (0)