Skip to content
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

ui/cluster-ui: filter out closed sessions from active exec pages #83896

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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