Skip to content

Commit

Permalink
ui/cluster-ui: filter out closed sessions from active exec pages
Browse files Browse the repository at this point in the history
Previously, it was possible for the active transactions page
to show txns from closed sessions. The sessions API was
recently updated to return closed sessions, and it is
possible for the active_txn field in a closed session to be
populated. This commit filters  out the closed sessions when
retrieving active transactions.

Release note (bug fix): active transactions page no longer
shows transactions from closed sessions
  • Loading branch information
xinhaoz committed Jul 6, 2022
1 parent 9c5472e commit c3c1541
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
SessionsResponse,
ActiveTransaction,
ActiveStatement,
SessionStatusType,
} from "./types";
import * as protos from "@cockroachlabs/crdb-protobuf-client";
import moment from "moment";
Expand Down Expand Up @@ -185,6 +186,14 @@ describe("test activeStatementUtils", () => {
client_address: "clientAddress2",
active_queries: activeQueries,
},
{
id: new Uint8Array(),
username: "foo",
status: SessionStatusType.CLOSED,
application_name: "application2",
client_address: "clientAddress2",
active_queries: activeQueries,
},
],
errors: [],
internal_app_name_prefix: "",
Expand Down Expand Up @@ -270,6 +279,15 @@ describe("test activeStatementUtils", () => {
active_queries: [makeActiveQuery()],
active_txn: txns[1],
},
{
id: new Uint8Array(),
username: "foo",
status: SessionStatusType.CLOSED,
application_name: "closed_application",
client_address: "clientAddress2",
active_queries: [makeActiveQuery()],
active_txn: txns[1],
},
],
errors: [],
internal_app_name_prefix: "",
Expand All @@ -281,6 +299,9 @@ describe("test activeStatementUtils", () => {
LAST_UPDATED,
);

// Should filter out the txn from closed session.
expect(activeTransactions.length).toBe(2);

expect(activeTransactions.length).toBe(txns.length);

activeTransactions.forEach((txn: ActiveTransaction, i) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ActiveStatementPhase,
ExecutionStatus,
ActiveTransactionFilters,
SessionStatusType,
} from "./types";
import { ActiveStatement, ActiveStatementFilters } from "./types";

Expand Down Expand Up @@ -54,6 +55,7 @@ export function getActiveStatementsFromSessions(
const time = lastUpdated || moment.utc();

sessionsResponse.sessions.forEach(session => {
if (session.status === SessionStatusType.CLOSED) return;
session.active_queries.forEach(query => {
activeQueries.push({
executionID: query.id,
Expand Down Expand Up @@ -140,7 +142,10 @@ export function getActiveTransactionsFromSessions(
});

return sessionsResponse.sessions
.filter(session => session.active_txn)
.filter(
session =>
session.status !== SessionStatusType.CLOSED && session.active_txn,
)
.map(session => {
const activeTxn = session.active_txn;

Expand Down
3 changes: 3 additions & 0 deletions pkg/ui/workspaces/cluster-ui/src/activeExecutions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export type SessionsResponse =
export type ActiveStatementResponse =
protos.cockroach.server.serverpb.ActiveQuery;
export type ExecutionStatus = "Waiting" | "Executing" | "Preparing";

export const ActiveStatementPhase =
protos.cockroach.server.serverpb.ActiveQuery.Phase;
export const SessionStatusType =
protos.cockroach.server.serverpb.Session.Status;

export type ActiveStatement = {
executionID: string;
Expand Down

0 comments on commit c3c1541

Please sign in to comment.