Skip to content

Commit

Permalink
Merge pull request #101803 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-23.1.0-101489

release-23.1.0: ui: add timescale to diag details page
  • Loading branch information
maryliag authored Apr 19, 2023
2 parents 65ee4b5 + dd664d0 commit dc5c429
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
import React from "react";
import classNames from "classnames/bind";
import styles from "./searchCriteria.module.scss";
import { PageConfig, PageConfigItem } from "src/pageConfig";
import { Button } from "src/button";
import { commonStyles, selectCustomStyles } from "src/common";
import {
Button,
commonStyles,
PageConfig,
PageConfigItem,
selectCustomStyles,
TimeScale,
timeScale1hMinOptions,
TimeScaleDropdown,
} from "src";
} from "src/timeScaleDropdown";
import { applyBtn } from "../queryFilter/filterClasses";
import Select from "react-select";
import { limitOptions } from "../util/sqlActivityConstants";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

import { isUndefined } from "lodash";
import { TimeScale, toDateRange } from "src/timeScaleDropdown";
import { DiagnosticStatuses } from "src/statementsDiagnostics";
import { StatementDiagnosticsReport } from "../../api";
import moment from "moment-timezone";
Expand All @@ -19,60 +19,17 @@ export function getDiagnosticsStatus(
if (diagnosticsRequest.completed) {
return "READY";
}

return "WAITING";
}

export function sortByRequestedAtField(
a: StatementDiagnosticsReport,
b: StatementDiagnosticsReport,
): number {
const activatedOnA = moment(a.requested_at)?.unix();
const activatedOnB = moment(b.requested_at)?.unix();
if (isUndefined(activatedOnA) && isUndefined(activatedOnB)) {
return 0;
}
if (activatedOnA < activatedOnB) {
return -1;
}
if (activatedOnA > activatedOnB) {
return 1;
}
return 0;
}

export function sortByCompletedField(
a: StatementDiagnosticsReport,
b: StatementDiagnosticsReport,
): number {
const completedA = a.completed ? 1 : -1;
const completedB = b.completed ? 1 : -1;
if (completedA < completedB) {
return -1;
}
if (completedA > completedB) {
return 1;
}
return 0;
}

export function sortByStatementFingerprintField(
a: StatementDiagnosticsReport,
b: StatementDiagnosticsReport,
): number {
const statementFingerprintA = a.statement_fingerprint;
const statementFingerprintB = b.statement_fingerprint;
if (
isUndefined(statementFingerprintA) &&
isUndefined(statementFingerprintB)
) {
return 0;
}
if (statementFingerprintA < statementFingerprintB) {
return -1;
}
if (statementFingerprintA > statementFingerprintB) {
return 1;
}
return 0;
export function filterByTimeScale(
diagnostics: StatementDiagnosticsReport[],
ts: TimeScale,
): StatementDiagnosticsReport[] {
const [start, end] = toDateRange(ts);
return diagnostics.filter(
diag =>
start.isSameOrBefore(moment(diag.requested_at)) &&
end.isSameOrAfter(moment(diag.requested_at)),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
display: flex;
flex-direction: column;

&__title {
&__header {
display: flex;
flex-direction: row;
justify-content: space-between;
Expand Down Expand Up @@ -79,3 +79,19 @@
margin-right: $spacing-x-small;
}
}

.column-size-medium {
width: 230px;
}

.column-size-small {
width: 140px;
}

.sorted-table {
width: 100%;
}

.margin-bottom {
margin-bottom: $spacing-smaller;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,31 @@ import { MemoryRouter } from "react-router-dom";
import { Button } from "@cockroachlabs/ui-components";

import { DiagnosticsView } from "./diagnosticsView";
import { Table } from "src/table";
import { TestStoreProvider } from "src/test-utils";
import { StatementDiagnosticsReport } from "../../api";
import moment from "moment-timezone";
import { SortedTable } from "src/sortedtable";

const activateDiagnosticsRef = { current: { showModalFor: jest.fn() } };
const ts = {
windowSize: moment.duration(20, "day"),
sampleSize: moment.duration(5, "minutes"),
fixedWindowEnd: moment.utc("2023.01.5"),
key: "Custom",
};
const mockSetTimeScale = jest.fn();

function generateDiagnosticsRequest(
extendObject: Partial<StatementDiagnosticsReport> = {},
): StatementDiagnosticsReport {
const requestedAt = moment.now();
const requestedAt = moment("2023-01-01 00:00:00");
const report: StatementDiagnosticsReport = {
id: "124354678574635",
statement_fingerprint: "SELECT * FROM table",
completed: true,
requested_at: moment(requestedAt),
min_execution_latency: moment.duration(10),
expires_at: moment(requestedAt + 10),
expires_at: moment("2023-01-01 00:00:10"),
};
Object.assign(report, extendObject);
return report;
Expand All @@ -52,6 +59,8 @@ describe("DiagnosticsView", () => {
hasData={false}
diagnosticsReports={[]}
dismissAlertMessage={() => {}}
currentScale={ts}
onChangeTimeScale={mockSetTimeScale}
/>
</MemoryRouter>,
);
Expand Down Expand Up @@ -81,13 +90,15 @@ describe("DiagnosticsView", () => {
hasData={true}
diagnosticsReports={diagnosticsRequests}
dismissAlertMessage={() => {}}
currentScale={ts}
onChangeTimeScale={mockSetTimeScale}
/>
</TestStoreProvider>,
);
});

it("renders Table component when diagnostics data is provided", () => {
assert.isTrue(wrapper.find(Table).exists());
assert.isTrue(wrapper.find(SortedTable).exists());
});

it("opens the statement diagnostics modal when Activate button is clicked", () => {
Expand All @@ -113,6 +124,8 @@ describe("DiagnosticsView", () => {
hasData={true}
diagnosticsReports={diagnosticsRequests}
dismissAlertMessage={() => {}}
currentScale={ts}
onChangeTimeScale={mockSetTimeScale}
/>
</TestStoreProvider>,
);
Expand All @@ -135,6 +148,8 @@ describe("DiagnosticsView", () => {
hasData={true}
diagnosticsReports={diagnosticsRequests}
dismissAlertMessage={() => {}}
currentScale={ts}
onChangeTimeScale={mockSetTimeScale}
/>
</TestStoreProvider>,
);
Expand Down
Loading

0 comments on commit dc5c429

Please sign in to comment.