-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathjobDetails.tsx
310 lines (288 loc) · 9.42 KB
/
jobDetails.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// Copyright 2022 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 React, { useContext } from "react";
import { cockroach } from "@cockroachlabs/crdb-protobuf-client";
import { ArrowLeft } from "@cockroachlabs/icons";
import { Col, Row, Tabs } from "antd";
import "antd/lib/col/style";
import "antd/lib/row/style";
import "antd/lib/tabs/style";
import Long from "long";
import Helmet from "react-helmet";
import { RouteComponentProps } from "react-router-dom";
import { JobRequest, JobResponse } from "src/api/jobsApi";
import { Button } from "src/button";
import { Loading } from "src/loading";
import { SqlBox, SqlBoxSize } from "src/sql";
import { SummaryCard, SummaryCardItem } from "src/summaryCard";
import {
TimestampToMoment,
idAttr,
getMatchParamByName,
DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ,
} from "src/util";
import { HighwaterTimestamp } from "src/jobs/util/highwaterTimestamp";
import { JobStatusCell } from "src/jobs/util/jobStatusCell";
import { isTerminalState } from "../util/jobOptions";
import { commonStyles } from "src/common";
import summaryCardStyles from "src/summaryCard/summaryCard.module.scss";
import jobStyles from "src/jobs/jobs.module.scss";
import classNames from "classnames/bind";
import { Timestamp } from "../../timestamp";
import {
ListJobProfilerExecutionDetailsRequest,
ListJobProfilerExecutionDetailsResponse,
RequestState,
} from "../../api";
import moment from "moment-timezone";
import { CockroachCloudContext } from "src/contexts";
import { JobProfilerView } from "./jobProfilerView";
const { TabPane } = Tabs;
const cardCx = classNames.bind(summaryCardStyles);
const jobCx = classNames.bind(jobStyles);
enum TabKeysEnum {
OVERVIEW = "Overview",
PROFILER = "Advanced Debugging",
}
export interface JobDetailsStateProps {
jobRequest: RequestState<JobResponse>;
jobProfilerResponse: RequestState<ListJobProfilerExecutionDetailsResponse>;
}
export interface JobDetailsDispatchProps {
refreshJob: (req: JobRequest) => void;
refreshExecutionDetails: (
req: ListJobProfilerExecutionDetailsRequest,
) => void;
}
export interface JobDetailsState {
currentTab?: string;
}
export type JobDetailsProps = JobDetailsStateProps &
JobDetailsDispatchProps &
RouteComponentProps<unknown>;
export class JobDetails extends React.Component<
JobDetailsProps,
JobDetailsState
> {
refreshDataInterval: NodeJS.Timeout;
constructor(props: JobDetailsProps) {
super(props);
const searchParams = new URLSearchParams(props.history.location.search);
this.state = {
currentTab: searchParams.get("tab") || "overview",
};
}
private refresh(): void {
if (isTerminalState(this.props.jobRequest.data?.status)) {
clearInterval(this.refreshDataInterval);
return;
}
this.props.refreshJob(
new cockroach.server.serverpb.JobRequest({
job_id: Long.fromString(getMatchParamByName(this.props.match, idAttr)),
}),
);
}
componentDidMount(): void {
if (!this.props.jobRequest.data) {
this.refresh();
}
// Refresh every 10s.
this.refreshDataInterval = setInterval(() => this.refresh(), 10 * 1000);
}
componentWillUnmount(): void {
if (this.refreshDataInterval) {
clearInterval(this.refreshDataInterval);
}
}
prevPage = (): void => this.props.history.goBack();
renderProfilerTabContent = (
job: cockroach.server.serverpb.JobResponse,
): React.ReactElement => {
const id = job?.id;
return (
<JobProfilerView
jobID={id}
executionDetailsResponse={this.props.jobProfilerResponse}
refreshExecutionDetails={this.props.refreshExecutionDetails}
/>
);
};
renderOverviewTabContent = (
hasNextRun: boolean,
nextRun: moment.Moment,
job: JobResponse,
): React.ReactElement => {
if (!job) {
return null;
}
return (
<Row gutter={24}>
<Col className="gutter-row" span={24}>
<SummaryCard className={cardCx("summary-card")}>
<SummaryCardItem
label="Status"
value={
<JobStatusCell job={job} lineWidth={1.5} hideDuration={true} />
}
/>
{hasNextRun && (
<>
<SummaryCardItem
label="Next Planned Execution Time"
value={
<Timestamp
time={nextRun}
format={DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ}
/>
}
/>
</>
)}
<SummaryCardItem
label="Creation Time"
value={
<Timestamp
time={TimestampToMoment(job.created)}
format={DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ}
/>
}
/>
{job.modified && (
<SummaryCardItem
label="Last Modified Time"
value={
<Timestamp
time={TimestampToMoment(job.modified)}
format={DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ}
/>
}
/>
)}
{job.finished && (
<SummaryCardItem
label="Completed Time"
value={
<Timestamp
time={TimestampToMoment(job.finished)}
format={DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ}
/>
}
/>
)}
<SummaryCardItem
label="Last Execution Time"
value={
<Timestamp
time={TimestampToMoment(job.last_run)}
format={DATE_WITH_SECONDS_AND_MILLISECONDS_FORMAT_24_TZ}
/>
}
/>
<SummaryCardItem
label="Execution Count"
value={String(job.num_runs)}
/>
<SummaryCardItem label="User Name" value={job.username} />
{job.highwater_timestamp && (
<SummaryCardItem
label="High-water Timestamp"
value={
<HighwaterTimestamp
timestamp={job.highwater_timestamp}
decimalString={job.highwater_decimal}
/>
}
/>
)}
</SummaryCard>
</Col>
</Row>
);
};
onTabChange = (tabId: string): void => {
const { history } = this.props;
const searchParams = new URLSearchParams(history.location.search);
searchParams.set("tab", tabId);
history.replace({
...history.location,
search: searchParams.toString(),
});
this.setState({
currentTab: tabId,
});
};
render(): React.ReactElement {
const isLoading =
this.props.jobRequest.inFlight && !this.props.jobRequest.data;
const error = this.props.jobRequest.error;
const job = this.props.jobRequest.data;
const nextRun = TimestampToMoment(job?.next_run);
const hasNextRun = nextRun?.isAfter();
const { currentTab } = this.state;
return (
<div className={jobCx("job-details")}>
<Helmet title={"Details | Job"} />
<div className={jobCx("section page--header")}>
<Button
onClick={this.prevPage}
type="unstyled-link"
size="small"
icon={<ArrowLeft fontSize={"10px"} />}
iconPosition="left"
className={commonStyles("small-margin")}
>
Jobs
</Button>
<h3 className={jobCx("page--header__title")}>{`Job ID: ${String(
getMatchParamByName(this.props.match, idAttr),
)}`}</h3>
</div>
<section className={jobCx("section section--container")}>
<Loading
loading={isLoading}
page={"job details"}
error={error}
render={() => (
<>
<section className={cardCx("summary-card")}>
<Row gutter={24}>
<Col className="gutter-row" span={24}>
<SqlBox
value={job?.description ?? "Job not found."}
size={SqlBoxSize.custom}
format={true}
/>
</Col>
</Row>
</section>
<Tabs
className={commonStyles("cockroach--tabs")}
defaultActiveKey={TabKeysEnum.OVERVIEW}
onChange={this.onTabChange}
activeKey={currentTab}
>
<TabPane tab={TabKeysEnum.OVERVIEW} key="overview">
{this.renderOverviewTabContent(hasNextRun, nextRun, job)}
</TabPane>
{!useContext(CockroachCloudContext) && (
<TabPane tab={TabKeysEnum.PROFILER} key="advancedDebugging">
{this.renderProfilerTabContent(job)}
</TabPane>
)}
</Tabs>
</>
)}
/>
</section>
</div>
);
}
}