|
7 | 7 | import getProjectQuery from '$queries/get_project'; |
8 | 8 | import getDryRunPhaseResultsQuery from '$queries/get_dry_run_phase_results'; |
9 | 9 | import getDryRunQuery from '$queries/get_selected_project'; |
| 10 | + import getCarbontrackerDataQuery from '$queries/get_carbontracker_metrics'; |
10 | 11 | import { requestGraphQLClient } from '$lib/graphqlUtils'; |
11 | 12 | import { goto } from '$app/navigation'; |
12 | 13 | import Plot from './plot.svelte'; |
|
127 | 128 | } |
128 | 129 | }; |
129 | 130 |
|
| 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 | +
|
130 | 159 | const getData = async (): Promise<{ |
131 | 160 | workflow: any; |
132 | 161 | dryrun: any; |
|
180 | 209 | cumulativeNetworkData = result.cumulativeNetworkData; |
181 | 210 | currentNetworkData = result.currentNetworkData; |
182 | 211 | 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 | +
|
183 | 235 | const responses = { |
184 | 236 | workflow: workflowResponse.project, |
185 | 237 | dryrun: dryrunResponse, |
186 | 238 | metrics: metricsResponse, |
187 | | - allstepnames: allStepNames |
| 239 | + allstepnames: allStepNames, |
| 240 | + selectedDryRunName: $selectedDryRunName, |
| 241 | + carbontracker_data |
188 | 242 | }; |
| 243 | + console.log('responses:', responses); |
189 | 244 | return responses; |
190 | 245 | }; |
191 | 246 |
|
|
496 | 551 | <th>Started</th> |
497 | 552 | <th>Finished</th> |
498 | 553 | <th>Duration</th> |
| 554 | + <th>CO2 [<span class="lowercase">g</span>]</th> |
| 555 | + <th>Energy [<span class="lowercase">k</span>Wh]</th> |
499 | 556 | <th>Status</th> |
500 | 557 | <th>Output</th> |
501 | 558 | </tr> |
|
505 | 562 | <!-- eslint-disable-next-line @typescript-eslint/explicit-function-return-type --> |
506 | 563 | <tr on:click={() => stepOnClick(step.displayName)}> |
507 | 564 | <td style="width:15%">{step.displayName}</td> |
508 | | - <td style="width:20%"> |
| 565 | + <td style="width:15%"> |
509 | 566 | {step.startedAt ?? '-'} |
510 | 567 | </td> |
511 | | - <td style="width:20%"> |
| 568 | + <td style="width:15%"> |
512 | 569 | {step.finishedAt ?? '-'} |
513 | 570 | </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> |
516 | 587 | <td style="width:15%"> |
517 | 588 | {#if step.outputArtifacts?.length > 1} |
518 | 589 | {#each step.outputArtifacts as artifact} |
|
0 commit comments