Skip to content

Commit

Permalink
ui: show events even with max size limit reached
Browse files Browse the repository at this point in the history
Show events that were returned when we reach the max
size limit of the sql-api.

Part Of cockroachdb#96184

Release note: None
  • Loading branch information
maryliag committed Feb 24, 2023
1 parent d4d9507 commit eb52f63
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
18 changes: 10 additions & 8 deletions pkg/ui/workspaces/cluster-ui/src/api/eventsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SqlExecutionRequest,
sqlResultsAreEmpty,
SqlStatement,
SqlApiResponse,
formatApiResult,
} from "./sqlApi";
import { withTimeout } from "./util";
import moment from "moment";
Expand Down Expand Up @@ -89,20 +91,20 @@ export function buildEventsSQLRequest(
export function getNonRedactedEvents(
req: NonRedactedEventsRequest = {},
timeout?: moment.Duration,
): Promise<EventsResponse> {
): Promise<SqlApiResponse<EventsResponse>> {
const eventsRequest: SqlExecutionRequest = buildEventsSQLRequest(req);
return withTimeout(
executeInternalSql<EventColumns>(eventsRequest),
timeout,
).then(result => {
// If request succeeded but query failed, throw error (caught by saga/cacheDataReducer).
if (result.error) {
throw result.error;
}

if (sqlResultsAreEmpty(result)) {
return [];
return formatApiResult([], result.error, "retrieving events information");
}
return result.execution.txn_results[0].rows;

return formatApiResult(
result.execution.txn_results[0].rows,
result.error,
"retrieving events information",
);
});
}
4 changes: 3 additions & 1 deletion pkg/ui/workspaces/db-console/src/redux/apiReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ export const refreshRawTrace = rawTraceReducerObj.refresh;

export interface APIReducersState {
cluster: CachedDataReducerState<api.ClusterResponseMessage>;
events: CachedDataReducerState<clusterUiApi.EventsResponse>;
events: CachedDataReducerState<
clusterUiApi.SqlApiResponse<clusterUiApi.EventsResponse>
>;
health: HealthState;
nodes: CachedDataReducerState<INodeStatus[]>;
raft: CachedDataReducerState<api.RaftDebugResponseMessage>;
Expand Down
6 changes: 5 additions & 1 deletion pkg/ui/workspaces/db-console/src/redux/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AdminUIState } from "src/redux/state";
* eventsSelector selects the list of events from the store.
*/
export function eventsSelector(state: AdminUIState) {
return state.cachedData.events.data;
return state.cachedData.events?.data?.results;
}

/**
Expand All @@ -27,3 +27,7 @@ export function eventsValidSelector(state: AdminUIState) {
export function eventsLastErrorSelector(state: AdminUIState) {
return state.cachedData.events.lastError;
}

export const eventsMaxApiReached = (state: AdminUIState): boolean => {
return !!state.cachedData.events?.data?.maxSizeReached;
};
4 changes: 2 additions & 2 deletions pkg/ui/workspaces/db-console/src/util/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe("rest api", function () {

return clusterUiApi.getNonRedactedEvents().then(result => {
expect(fetchMock.calls(clusterUiApi.SQL_API_PATH).length).toBe(1);
expect(result.length).toBe(1);
expect(result.results.length).toBe(1);
});
});

Expand Down Expand Up @@ -364,7 +364,7 @@ describe("rest api", function () {

return clusterUiApi.getNonRedactedEvents(req).then(result => {
expect(fetchMock.calls(clusterUiApi.SQL_API_PATH).length).toBe(1);
expect(result.length).toBe(1);
expect(result.results.length).toBe(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
eventsLastErrorSelector,
eventsSelector,
eventsValidSelector,
eventsMaxApiReached,
} from "src/redux/events";
import { LocalSetting } from "src/redux/localsettings";
import { AdminUIState } from "src/redux/state";
Expand All @@ -31,6 +32,7 @@ import {
util,
api as clusterUiApi,
} from "@cockroachlabs/cluster-ui";
import { InlineAlert } from "@cockroachlabs/ui-components";
import "./events.styl";

// Number of events to show in the sidebar.
Expand Down Expand Up @@ -134,6 +136,7 @@ export interface EventPageProps {
sortSetting: SortSetting;
setSort: typeof eventsSortSetting.set;
lastError: Error;
maxSizeApiReached: boolean;
}

export class EventPageUnconnected extends React.Component<EventPageProps, {}> {
Expand All @@ -148,30 +151,43 @@ export class EventPageUnconnected extends React.Component<EventPageProps, {}> {
}

renderContent() {
const { events, sortSetting } = this.props;
const { events, sortSetting, maxSizeApiReached } = this.props;
const simplifiedEvents = _.map(events, getEventInfo);

return (
<div className="l-columns__left events-table">
<EventSortedTable
data={simplifiedEvents}
sortSetting={sortSetting}
onChangeSortSetting={setting => this.props.setSort(setting)}
columns={[
{
title: "Event",
name: "event",
cell: e => e.content,
},
{
title: "Timestamp",
name: "timestamp",
cell: e => e.fromNowString,
sort: e => e.sortableTimestamp,
},
]}
/>
</div>
<>
<div className="l-columns__left events-table">
<EventSortedTable
data={simplifiedEvents}
sortSetting={sortSetting}
onChangeSortSetting={setting => this.props.setSort(setting)}
columns={[
{
title: "Event",
name: "event",
cell: e => e.content,
},
{
title: "Timestamp",
name: "timestamp",
cell: e => e.fromNowString,
sort: e => e.sortableTimestamp,
},
]}
/>
</div>
{maxSizeApiReached && (
<InlineAlert
intent="info"
title={
<>
Not all events are displayed because the maximum number of
events was reached in the console.&nbsp;
</>
}
/>
)}
</>
);
}

Expand All @@ -183,7 +199,7 @@ export class EventPageUnconnected extends React.Component<EventPageProps, {}> {
<section className="section section--heading">
<h1 className="base-heading">Events</h1>
</section>
<section className="section l-columns">
<section className="section">
<Loading
loading={!events}
page={"events"}
Expand Down Expand Up @@ -220,6 +236,7 @@ const eventPageConnected = withRouter(
eventsValid: eventsValidSelector(state),
sortSetting: eventsSortSetting.selector(state),
lastError: eventsLastErrorSelector(state),
maxSizeApiReached: eventsMaxApiReached(state),
};
},
{
Expand Down

0 comments on commit eb52f63

Please sign in to comment.