From b1d462df05401a3bd5184459bf0787a31ae4a969 Mon Sep 17 00:00:00 2001 From: Kyle Wong <37189875+kyle-a-wong@users.noreply.github.com> Date: Fri, 17 Jan 2025 11:25:25 -0500 Subject: [PATCH] ui: fix statement diag reports when min exec latency is null A bug in db console was resulting in statement diagnostics reports to not work as intended. As a result, activating diagnostics didn't result in the intended state change which showed a user that a diagnostics report is running or downloadble. This was happening in edge cases where reports "minExecutionLatency" response field was null, but the db console expected it to be populated. Now, db console should handle this edge case. This commit also adds nanosecond granularity to the returned StatementDiagnosticsResponse.min_execution_latency field. Previously only the seconds portion of the statement's min_execution_latency was converted into the returned objects duration, but often times this latency will be sub 1 second, resulting in "O" to be returned. Fixes: #139340 Epic: none Release note (bug fix): Fixes a bug where sometimes activating diagnostics for sql activity appears unresponsive, with no state or status update upon activating. Now, the status should always reflect that diagnosticsa are active or that a statement bundle is downloadable. --- .../src/api/statementDiagnosticsApi.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/ui/workspaces/cluster-ui/src/api/statementDiagnosticsApi.ts b/pkg/ui/workspaces/cluster-ui/src/api/statementDiagnosticsApi.ts index a7fb4122645b..548e936bcaa0 100644 --- a/pkg/ui/workspaces/cluster-ui/src/api/statementDiagnosticsApi.ts +++ b/pkg/ui/workspaces/cluster-ui/src/api/statementDiagnosticsApi.ts @@ -33,17 +33,24 @@ export async function getStatementDiagnosticsReports(): Promise { + const minExecutionLatency = report.min_execution_latency + ? moment + .duration(report.min_execution_latency?.seconds.toNumber(), "seconds") + .add( + moment.duration( + report.min_execution_latency.nanos / 1e9, + "seconds", + ), + ) + : null; return { id: report.id.toString(), statement_fingerprint: report.statement_fingerprint, completed: report.completed, statement_diagnostics_id: report.statement_diagnostics_id.toString(), - requested_at: moment.unix(report.requested_at.seconds.toNumber()), - min_execution_latency: moment.duration( - report.min_execution_latency.seconds.toNumber(), - "seconds", - ), - expires_at: moment.unix(report.expires_at.seconds.toNumber()), + requested_at: moment.unix(report.requested_at?.seconds.toNumber()), + min_execution_latency: minExecutionLatency, + expires_at: moment.unix(report.expires_at?.seconds.toNumber()), }; }); }