Skip to content

Commit

Permalink
Improve the time of the UI distribution graph (trinodb#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytwp authored and mosabua committed Jul 22, 2024
1 parent fdb1aa0 commit f8eb116
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import jakarta.ws.rs.core.SecurityContext;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
Expand All @@ -59,7 +62,7 @@
public class GatewayWebAppResource
{
private static final LocalDateTime START_TIME = LocalDateTime.now();
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
private final GatewayBackendManager gatewayBackendManager;
private final QueryHistoryManager queryHistoryManager;
private final BackendStateManager backendStateManager;
Expand Down Expand Up @@ -159,7 +162,9 @@ public Response getDistribution(QueryDistributionRequest query)
distributionResponse.setTotalQueryCount(totalQueryCount);
distributionResponse.setAverageQueryCountSecond(totalQueryCount / (latestHour * 60d * 60d));
distributionResponse.setAverageQueryCountMinute(totalQueryCount / (latestHour * 60d));
distributionResponse.setStartTime(START_TIME.format(formatter));
ZonedDateTime zonedLocalTime = START_TIME.atZone(ZoneId.systemDefault());
ZonedDateTime utcTime = zonedLocalTime.withZoneSameInstant(ZoneOffset.UTC);
distributionResponse.setStartTime(utcTime.format(formatter));
return Response.ok(Result.ok(distributionResponse)).build();
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IconHelpCircle } from "@douyinfe/semi-icons";
import { useNavigate } from "react-router-dom";
import { hasPagePermission, routersMapper } from "../router";
import { useAccessStore } from "../store";
import { formatZonedDateTime } from "../utils/time";

export function Dashboard() {
const access = useAccessStore();
Expand All @@ -26,7 +27,7 @@ export function Dashboard() {
const data = [
{
key: Locale.Dashboard.StartTime,
value: distributionDetail?.startTime
value: distributionDetail && formatZonedDateTime(distributionDetail.startTime)
},
{
key: Locale.Dashboard.Backends,
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Card, Form, Table, Tag, Typography } from "@douyinfe/semi-ui";
import Column from "@douyinfe/semi-ui/lib/es/table/Column";
import { queryHistoryApi } from "../api/webapp/history";
import { HistoryData, HistoryDetail } from "../types/history";
import { formatYYYYMMddHHMMSS } from "../utils/time";
import { formatTimestamp } from "../utils/time";
import { backendsApi } from "../api/webapp/cluster";
import { Role, useAccessStore } from "../store";
import { BackendData } from "../types/cluster";
Expand Down Expand Up @@ -66,7 +66,7 @@ export function History() {

const timeRender = (text: number) => {
return (
<Text>{formatYYYYMMddHHMMSS(text)}</Text>
<Text>{formatTimestamp(text)}</Text>
);
}

Expand Down
13 changes: 11 additions & 2 deletions webapp/src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const format = (
.format(formatString);
};

export const formatYYYYMMddHHMMSS = (timestamp: number): string => {
const date = new Date(timestamp);
const formatDateComponents = (date: Date): string => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
Expand All @@ -39,3 +38,13 @@ export const formatYYYYMMddHHMMSS = (timestamp: number): string => {
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}

export const formatTimestamp = (timestamp: number): string => {
const date = new Date(timestamp);
return formatDateComponents(date);
}

export const formatZonedDateTime = (zonedDateTime: string): string => {
const date = new Date(zonedDateTime);
return formatDateComponents(date);
}

0 comments on commit f8eb116

Please sign in to comment.