forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui: split txn and stmt fingerprints requests and storage
Previously, both the stmt and txns fingerprints pages were using the same api response from the /statements. This was because we need the stmts response to build txns pages. Howevever having to fetch both types of stats can slow down the request. Now that we can specify the fetch_mode as part of the request, we can split the 2 into their own api calls and redux fields. Epic: none Part of: cockroachdb#97875 Release note: None
- Loading branch information
Showing
20 changed files
with
361 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
pkg/ui/workspaces/cluster-ui/src/store/transactionStats/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
export * from "./txnStats.reducer"; | ||
export * from "./txnStats.sagas"; |
73 changes: 73 additions & 0 deletions
73
pkg/ui/workspaces/cluster-ui/src/store/transactionStats/txnStats.reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; | ||
import { DOMAIN_NAME } from "../utils"; | ||
import { StatementsRequest } from "src/api/statementsApi"; | ||
import { TimeScale } from "../../timeScaleDropdown"; | ||
import moment from "moment"; | ||
import { StatementsResponse } from "../sqlStats"; | ||
|
||
export type TxnStatsData = cockroach.server.serverpb.IStatementsResponse; | ||
|
||
export type TxnStatsState = { | ||
data: TxnStatsData; | ||
inFlight: boolean; | ||
lastError: Error; | ||
valid: boolean; | ||
lastUpdated: moment.Moment | null; | ||
}; | ||
|
||
const initialState: TxnStatsState = { | ||
data: null, | ||
inFlight: false, | ||
lastError: null, | ||
valid: false, | ||
lastUpdated: null, | ||
}; | ||
|
||
export type UpdateTimeScalePayload = { | ||
ts: TimeScale; | ||
}; | ||
|
||
// This is actually statements only, despite the SQLStatsState name. | ||
// We can rename this in the future. Leaving it now to reduce backport surface area. | ||
const txnStatsSlice = createSlice({ | ||
name: `${DOMAIN_NAME}/txnStats`, | ||
initialState, | ||
reducers: { | ||
received: (state, action: PayloadAction<StatementsResponse>) => { | ||
state.inFlight = false; | ||
state.data = action.payload; | ||
state.valid = true; | ||
state.lastError = null; | ||
state.lastUpdated = moment.utc(); | ||
}, | ||
failed: (state, action: PayloadAction<Error>) => { | ||
state.inFlight = false; | ||
state.valid = false; | ||
state.lastError = action.payload; | ||
state.lastUpdated = moment.utc(); | ||
}, | ||
invalidated: state => { | ||
state.inFlight = false; | ||
state.valid = false; | ||
}, | ||
refresh: (state, _: PayloadAction<StatementsRequest>) => { | ||
state.inFlight = true; | ||
}, | ||
request: (state, _: PayloadAction<StatementsRequest>) => { | ||
state.inFlight = true; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { reducer, actions } = txnStatsSlice; |
100 changes: 100 additions & 0 deletions
100
pkg/ui/workspaces/cluster-ui/src/store/transactionStats/txnStats.sagas.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { expectSaga } from "redux-saga-test-plan"; | ||
import { | ||
EffectProviders, | ||
StaticProvider, | ||
throwError, | ||
} from "redux-saga-test-plan/providers"; | ||
import * as matchers from "redux-saga-test-plan/matchers"; | ||
import { cockroach } from "@cockroachlabs/crdb-protobuf-client"; | ||
|
||
import { getFlushedTxnStatsApi } from "src/api/statementsApi"; | ||
import { refreshTxnStatsSaga, requestTxnStatsSaga } from "./txnStats.sagas"; | ||
import { actions, reducer, TxnStatsState } from "./txnStats.reducer"; | ||
import Long from "long"; | ||
import moment from "moment"; | ||
|
||
const lastUpdated = moment(); | ||
|
||
describe("txnStats sagas", () => { | ||
let spy: jest.SpyInstance; | ||
beforeAll(() => { | ||
spy = jest.spyOn(moment, "utc").mockImplementation(() => lastUpdated); | ||
}); | ||
|
||
afterAll(() => { | ||
spy.mockRestore(); | ||
}); | ||
|
||
const payload = new cockroach.server.serverpb.StatementsRequest({ | ||
start: Long.fromNumber(1596816675), | ||
end: Long.fromNumber(1596820675), | ||
combined: true, | ||
}); | ||
const txnStatsResponse = new cockroach.server.serverpb.StatementsResponse({ | ||
transactions: [ | ||
{ | ||
stats_data: { transaction_fingerprint_id: new Long(1) }, | ||
}, | ||
{ | ||
stats_data: { transaction_fingerprint_id: new Long(2) }, | ||
}, | ||
], | ||
last_reset: null, | ||
}); | ||
|
||
const txnStatsAPIProvider: (EffectProviders | StaticProvider)[] = [ | ||
[matchers.call.fn(getFlushedTxnStatsApi), txnStatsResponse], | ||
]; | ||
|
||
describe("refreshTxnStatsSaga", () => { | ||
it("dispatches request txnStats action", () => { | ||
return expectSaga(refreshTxnStatsSaga, actions.request(payload)) | ||
.provide(txnStatsAPIProvider) | ||
.put(actions.request(payload)) | ||
.run(); | ||
}); | ||
}); | ||
|
||
describe("requestTxnStatsSaga", () => { | ||
it("successfully requests statements list", () => { | ||
return expectSaga(requestTxnStatsSaga, actions.request(payload)) | ||
.provide(txnStatsAPIProvider) | ||
.put(actions.received(txnStatsResponse)) | ||
.withReducer(reducer) | ||
.hasFinalState<TxnStatsState>({ | ||
inFlight: false, | ||
data: txnStatsResponse, | ||
lastError: null, | ||
valid: true, | ||
lastUpdated, | ||
}) | ||
.run(); | ||
}); | ||
|
||
it("returns error on failed request", () => { | ||
const error = new Error("Failed request"); | ||
return expectSaga(requestTxnStatsSaga, actions.request(payload)) | ||
.provide([[matchers.call.fn(getFlushedTxnStatsApi), throwError(error)]]) | ||
.put(actions.failed(error)) | ||
.withReducer(reducer) | ||
.hasFinalState<TxnStatsState>({ | ||
inFlight: false, | ||
data: null, | ||
lastError: error, | ||
valid: false, | ||
lastUpdated, | ||
}) | ||
.run(); | ||
}); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
pkg/ui/workspaces/cluster-ui/src/store/transactionStats/txnStats.sagas.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { PayloadAction } from "@reduxjs/toolkit"; | ||
import { all, call, put, takeLatest } from "redux-saga/effects"; | ||
import { | ||
getFlushedTxnStatsApi, | ||
StatementsRequest, | ||
} from "src/api/statementsApi"; | ||
import { actions as txnStatsActions } from "./txnStats.reducer"; | ||
|
||
export function* refreshTxnStatsSaga( | ||
action: PayloadAction<StatementsRequest>, | ||
): Generator<unknown> { | ||
yield put(txnStatsActions.request(action.payload)); | ||
} | ||
|
||
export function* requestTxnStatsSaga( | ||
action: PayloadAction<StatementsRequest>, | ||
): any { | ||
try { | ||
const result = yield call(getFlushedTxnStatsApi, action.payload); | ||
yield put(txnStatsActions.received(result)); | ||
} catch (e) { | ||
yield put(txnStatsActions.failed(e)); | ||
} | ||
} | ||
|
||
export function* txnStatsSaga(): any { | ||
yield all([ | ||
takeLatest(txnStatsActions.refresh, refreshTxnStatsSaga), | ||
takeLatest(txnStatsActions.request, requestTxnStatsSaga), | ||
]); | ||
} |
17 changes: 17 additions & 0 deletions
17
pkg/ui/workspaces/cluster-ui/src/store/transactionStats/txnStats.selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import { createSelector } from "reselect"; | ||
import { adminUISelector } from "../utils/selectors"; | ||
|
||
export const txnStatsSelector = createSelector( | ||
adminUISelector, | ||
adminUiState => adminUiState?.transactions, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.