Skip to content

Commit

Permalink
Merge pull request #573 from vitessio/refactor-compare
Browse files Browse the repository at this point in the history
Refactor Compare Page
  • Loading branch information
frouioui authored Jul 22, 2024
2 parents 801ad69 + 94725dd commit 286517b
Show file tree
Hide file tree
Showing 10 changed files with 686 additions and 134 deletions.
24 changes: 15 additions & 9 deletions go/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,16 @@ type RecentExecutions struct {
}

type ExecutionMetadatas struct {
Workloads []string `json:"workloads"`
Sources []string `json:"sources"`
Statuses []string `json:"statuses"`
Workloads []string `json:"workloads"`
Sources []string `json:"sources"`
Statuses []string `json:"statuses"`
}

type RecentExecutionsResponse struct {
Executions []RecentExecutions `json:"executions"`
ExecutionMetadatas
}


type ExecutionQueueResponse struct {
Executions []ExecutionQueue `json:"executions"`
ExecutionMetadatas
Expand Down Expand Up @@ -153,7 +152,13 @@ type VitessGitRef struct {
FinishedAt *time.Time `json:"finished_at"`
}

type VitessGitRefReleases struct {
Tags []*git.Release `json:"tags"`
Branches []*git.Release `json:"branches"`
}

func (s *Server) getLatestVitessGitRef(c *gin.Context) {
var response VitessGitRefReleases
allReleases, err := git.GetLatestVitessReleaseCommitHash(s.getVitessPath())
if err != nil {
c.JSON(http.StatusInternalServerError, &ErrorAPI{Error: err.Error()})
Expand All @@ -166,21 +171,22 @@ func (s *Server) getLatestVitessGitRef(c *gin.Context) {
slog.Error(err)
return
}
mainRelease := []*git.Release{{
mainRelease := &git.Release{
Name: "main",
CommitHash: lastrunDailySHA,
}}
allReleases = append(mainRelease, allReleases...)
}
response.Branches = append(response.Branches, mainRelease)
// get all the latest release branches as well
allReleaseBranches, err := git.GetLatestVitessReleaseBranchCommitHash(s.getVitessPath())
if err != nil {
c.JSON(http.StatusInternalServerError, &ErrorAPI{Error: err.Error()})
slog.Error(err)
return
}
allReleases = append(allReleases, allReleaseBranches...)
response.Branches = append(response.Branches, allReleaseBranches...)
response.Tags = allReleases

c.JSON(http.StatusOK, allReleases)
c.JSON(http.StatusOK, response)
}

type CompareMacrobench struct {
Expand Down
12 changes: 7 additions & 5 deletions go/tools/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ import (

type (
Release struct {
Name string
CommitHash string
Version Version
RCnumber int
Name string `json:"name"`
CommitHash string `json:"commit_hash"`
Version Version `json:"version"`
RCnumber int `json:"rc_number"`
}

Version struct {
Major, Minor, Patch int
Major int `json:"major"`
Minor int `json:"minor"`
Patch int `json:"patch"`
}
)

Expand Down
219 changes: 219 additions & 0 deletions website/src/common/MacroBenchmarkTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { Badge } from "@/components/ui/badge";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { MacroDataValue, Range } from "@/types";
import {
fixed,
formatByte,
formatGitRef,
secondToMicrosecond,
} from "@/utils/Utils";
import { Link } from "react-router-dom";

type MacroBenchmarkTableDataRow = {
title: string;
old: MacroDataValue;
new: MacroDataValue;
p: number;
delta: number;
insignificant: boolean;
};

export type MacroBenchmarkTableData = {
qpsTotal: MacroBenchmarkTableDataRow;
qpsReads: MacroBenchmarkTableDataRow;
qpsWrites: MacroBenchmarkTableDataRow;
qpsOther: MacroBenchmarkTableDataRow;
tps: MacroBenchmarkTableDataRow;
latency: MacroBenchmarkTableDataRow;
errors: MacroBenchmarkTableDataRow;
totalComponentsCpuTime: MacroBenchmarkTableDataRow;
vtgateCpuTime: MacroBenchmarkTableDataRow;
vttabletCpuTime: MacroBenchmarkTableDataRow;
totalComponentsMemStatsAllocBytes: MacroBenchmarkTableDataRow;
vtgateMemStatsAllocBytes: MacroBenchmarkTableDataRow;
vttabletMemStatsAllocBytes: MacroBenchmarkTableDataRow;
};

export type MacroBenchmarkTableProps = {
data: MacroBenchmarkTableData;
oldGitRef: string;
newGitRef: string;
};

const getDeltaBadgeVariant = (key: string, delta: number, p: number) => {
if (delta === 0) {
return "warning";
}
if (
key.includes("CpuTime") ||
key.includes("Mem") ||
key.includes("latency")
) {
if (delta < 0) {
return "success";
}
}
if (key.includes("qps") || key.includes("tps")) {
if (delta > 0) {
return "success";
}
}
return "destructive";
};

const formatCellValue = (key: string, value: number) => {
if (key.includes("CpuTime")) {
return secondToMicrosecond(value);
} else if (key.includes("MemStatsAllocBytes")) {
return formatByte(Number(fixed(value, 2)));
}
return fixed(value, 2);
};

export function getRange(range: Range) {
if (range.infinite == true) {
return "∞";
}
if (range.unknown == true) {
return "?";
}
return "±" + fixed(range.value, 1) + "%";
}

// Type-safe function to access properties
const getValue = <T, K extends keyof T>(obj: T, key: K): T[K] => obj[key];

export default function MacroBenchmarkTable({
data,
newGitRef,
oldGitRef,
}: MacroBenchmarkTableProps) {
if (!data) {
return null;
}
const dataKeys = Object.keys(data) as Array<keyof MacroBenchmarkTableData>;

// Use keyof MacroBenchmarkTableData to enforce key types
const classNameMap: { [key in keyof MacroBenchmarkTableData]: string } = {
qpsTotal: "border-b border-foreground dark:border-none",
qpsReads: "bg-muted/80",
qpsWrites: "bg-muted/80",
qpsOther: "bg-muted/80 border-b border-foreground dark:border-none",
tps: "bg-background",
latency: "bg-background",
errors: "bg-background",
totalComponentsCpuTime: "border-b border-foreground dark:border-none",
vtgateCpuTime: "bg-muted/80 ",
vttabletCpuTime: "bg-muted/80 border-b border-foreground dark:border-none",
totalComponentsMemStatsAllocBytes:
"border-b border-foreground dark:border-none",
vtgateMemStatsAllocBytes: "bg-muted/80",
vttabletMemStatsAllocBytes:
"bg-muted/80 border-b border-foreground dark:border-none",
};

return (
<Table>
<TableHeader>
<TableRow className="hover:bg-background border-b">
<TableHead className="w-[200px]"></TableHead>
<TableHead className="text-center text-primary font-semibold">
<Link
to={`https://github.com/vitessio/vitess/commit/${oldGitRef}`}
target="__blank"
>
{formatGitRef(oldGitRef) || "N/A"}
</Link>
</TableHead>
<TableHead className="text-center text-primary font-semibold">
<Link
to={`https://github.com/vitessio/vitess/commit/${newGitRef}`}
target="__blank"
>
{formatGitRef(newGitRef) || "N/A"}
</Link>{" "}
</TableHead>
<TableHead className="lg:w-[150px] text-center font-semibold">P</TableHead>
<TableHead className="lg:w-[150px] text-center font-semibold">Delta</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{dataKeys.map((key, index) => {
const row = getValue(data, key);
return (
<TableRow key={index} className={classNameMap[key]}>
<TableCell className="w-[200px] font-medium text-right border-r border-border">
{row.title}
</TableCell>
<TableCell className="text-center text-front">
{formatCellValue(key, Number(row.old.center))} (
{getRange(row.old.range)})
</TableCell>
<TableCell className="text-center text-front border-r border-border">
{formatCellValue(key, Number(row.new.center))} (
{getRange(row.new.range)})
</TableCell>
<TableCell className="lg:w-[150px] text-center text-front">
<TooltipProvider delayDuration={200}>
<Tooltip>
<TooltipTrigger asChild>
<div>
<Badge
variant={row.p > 0.05 ? "destructive" : "success"}
>
{fixed(row.p, 3)}
</Badge>
</div>
</TooltipTrigger>
<TooltipContent>
<p>
{row.insignificant ? "Insignificant" : "Significant"}
</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>
</TableCell>
<TableCell className="lg:w-[150px] text-center text-front">
{row.insignificant && <>{fixed(row.delta, 3)}%</>}
{!row.insignificant && (
<Badge variant={getDeltaBadgeVariant(key, row.delta, row.p)}>
{fixed(row.delta, 3)}%
</Badge>
)}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
);
}
5 changes: 2 additions & 3 deletions website/src/common/Macrobench.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import React from "react";
import PropTypes from 'prop-types';
import { Link } from "react-router-dom";
import { formatByte, fixed, secondToMicrosecond } from "../utils/Utils";
import {twMerge} from "tailwind-merge";
import { twMerge } from "tailwind-merge";
import { fixed, formatByte, secondToMicrosecond } from "../utils/Utils";

export default function Macrobench({ data, gitRef, commits }) {
return (
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/ui/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const TableRow = React.forwardRef<
<tr
ref={ref}
className={cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
"border-b border-border transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
Expand Down
Loading

0 comments on commit 286517b

Please sign in to comment.