Skip to content

Commit

Permalink
fix: tcp test button (#1078)
Browse files Browse the repository at this point in the history
* fix: tcp

* fix: ts error
  • Loading branch information
mxkaske authored Nov 2, 2024
1 parent a973cae commit 0f88a9b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 23 deletions.
2 changes: 2 additions & 0 deletions apps/web/src/app/api/checker/test/tcp/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const tcpPayload = z.object({
});

export const TCPResponse = z.object({
type: z.literal("tcp").default("tcp"),
requestId: z.number().optional(),
workspaceId: z.number().optional(),
monitorId: z.number().optional(),
Expand All @@ -22,6 +23,7 @@ export const TCPResponse = z.object({
}),
error: z.string().optional(),
region: monitorFlyRegionSchema,
latency: z.number().optional(),
});

export type tcpPayload = z.infer<typeof tcpPayload>;
35 changes: 35 additions & 0 deletions apps/web/src/app/play/checker/api/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const data = {
method: "GET",
checks: [
{
type: "http",
status: 200,
latency: 889,
headers: {
Expand Down Expand Up @@ -55,6 +56,7 @@ export const data = {
region: "ams",
},
{
type: "http",
status: 200,
latency: 1602,
headers: {
Expand Down Expand Up @@ -91,6 +93,7 @@ export const data = {
region: "arn",
},
{
type: "http",
status: 200,
latency: 823,
headers: {
Expand Down Expand Up @@ -127,6 +130,7 @@ export const data = {
region: "atl",
},
{
type: "http",
status: 200,
latency: 1198,
headers: {
Expand Down Expand Up @@ -163,6 +167,7 @@ export const data = {
region: "bog",
},
{
type: "http",
status: 200,
latency: 1423,
headers: {
Expand Down Expand Up @@ -199,6 +204,7 @@ export const data = {
region: "bom",
},
{
type: "http",
status: 200,
latency: 1134,
headers: {
Expand Down Expand Up @@ -235,6 +241,7 @@ export const data = {
region: "bos",
},
{
type: "http",
status: 200,
latency: 812,
headers: {
Expand Down Expand Up @@ -271,6 +278,7 @@ export const data = {
region: "cdg",
},
{
type: "http",
status: 200,
latency: 1081,
headers: {
Expand Down Expand Up @@ -307,6 +315,7 @@ export const data = {
region: "den",
},
{
type: "http",
status: 200,
latency: 1329,
headers: {
Expand Down Expand Up @@ -343,6 +352,7 @@ export const data = {
region: "dfw",
},
{
type: "http",
status: 200,
latency: 380,
headers: {
Expand Down Expand Up @@ -379,6 +389,7 @@ export const data = {
region: "ewr",
},
{
type: "http",
status: 200,
latency: 802,
headers: {
Expand Down Expand Up @@ -415,6 +426,7 @@ export const data = {
region: "eze",
},
{
type: "http",
status: 200,
latency: 615,
headers: {
Expand Down Expand Up @@ -450,6 +462,7 @@ export const data = {
region: "fra",
},
{
type: "http",
status: 200,
latency: 1481,
headers: {
Expand Down Expand Up @@ -486,6 +499,7 @@ export const data = {
region: "gdl",
},
{
type: "http",
status: 200,
latency: 768,
headers: {
Expand Down Expand Up @@ -522,6 +536,7 @@ export const data = {
region: "gig",
},
{
type: "http",
status: 200,
latency: 662,
headers: {
Expand Down Expand Up @@ -558,6 +573,7 @@ export const data = {
region: "gru",
},
{
type: "http",
status: 200,
latency: 1543,
headers: {
Expand Down Expand Up @@ -594,6 +610,7 @@ export const data = {
region: "hkg",
},
{
type: "http",
status: 200,
latency: 369,
headers: {
Expand Down Expand Up @@ -630,6 +647,7 @@ export const data = {
region: "iad",
},
{
type: "http",
status: 200,
latency: 1264,
headers: {
Expand Down Expand Up @@ -666,6 +684,7 @@ export const data = {
region: "jnb",
},
{
type: "http",
status: 200,
latency: 642,
headers: {
Expand Down Expand Up @@ -702,6 +721,7 @@ export const data = {
region: "lax",
},
{
type: "http",
status: 200,
latency: 627,
headers: {
Expand Down Expand Up @@ -738,6 +758,7 @@ export const data = {
region: "lhr",
},
{
type: "http",
status: 200,
latency: 951,
headers: {
Expand Down Expand Up @@ -774,6 +795,7 @@ export const data = {
region: "mad",
},
{
type: "http",
status: 200,
latency: 808,
headers: {
Expand Down Expand Up @@ -810,6 +832,7 @@ export const data = {
region: "mia",
},
{
type: "http",
status: 200,
latency: 1301,
headers: {
Expand Down Expand Up @@ -846,6 +869,7 @@ export const data = {
region: "nrt",
},
{
type: "http",
status: 200,
latency: 1079,
headers: {
Expand Down Expand Up @@ -882,6 +906,7 @@ export const data = {
region: "ord",
},
{
type: "http",
status: 200,
latency: 1349,
headers: {
Expand Down Expand Up @@ -917,6 +942,7 @@ export const data = {
region: "otp",
},
{
type: "http",
status: 200,
latency: 970,
headers: {
Expand Down Expand Up @@ -953,6 +979,7 @@ export const data = {
region: "phx",
},
{
type: "http",
status: 200,
latency: 1539,
headers: {
Expand Down Expand Up @@ -989,6 +1016,7 @@ export const data = {
region: "qro",
},
{
type: "http",
status: 200,
latency: 1347,
headers: {
Expand Down Expand Up @@ -1025,6 +1053,7 @@ export const data = {
region: "scl",
},
{
type: "http",
status: 200,
latency: 400,
headers: {
Expand Down Expand Up @@ -1061,6 +1090,7 @@ export const data = {
region: "sjc",
},
{
type: "http",
status: 200,
latency: 883,
headers: {
Expand Down Expand Up @@ -1097,6 +1127,7 @@ export const data = {
region: "sea",
},
{
type: "http",
status: 200,
latency: 825,
headers: {
Expand Down Expand Up @@ -1133,6 +1164,7 @@ export const data = {
region: "sin",
},
{
type: "http",
status: 200,
latency: 526,
headers: {
Expand Down Expand Up @@ -1169,6 +1201,7 @@ export const data = {
region: "syd",
},
{
type: "http",
status: 200,
latency: 869,
headers: {
Expand Down Expand Up @@ -1204,6 +1237,7 @@ export const data = {
region: "waw",
},
{
type: "http",
status: 200,
latency: 1133,
headers: {
Expand Down Expand Up @@ -1240,6 +1274,7 @@ export const data = {
region: "yul",
},
{
type: "http",
status: 200,
latency: 447,
headers: {
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/forms/monitor/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ export function MonitorForm({
jobType,
} = form.getValues();

// FIXME: add support for TCP
// if (jobType !== "http")
// return { error: "Only HTTP tests are supported. Coming soon..." };

if (
body &&
body !== "" &&
Expand Down
24 changes: 13 additions & 11 deletions apps/web/src/components/forms/monitor/request-test-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,19 @@ export function RequestTestButton({ form, pingEndpoint, limits }: Props) {
{check ? (
<div className="grid gap-8">
<RegionInfo check={check.data} error={check.error} />
<ResponseDetailTabs
timing={check.data.timing}
headers={check.data.headers}
status={check.data.status}
assertions={deserialize(
JSON.stringify([
...(statusAssertions || []),
...(headerAssertions || []),
]),
)}
/>
{check.data.type === "http" ? (
<ResponseDetailTabs
timing={check.data.timing}
headers={check.data.headers}
status={check.data.status}
assertions={deserialize(
JSON.stringify([
...(statusAssertions || []),
...(headerAssertions || []),
]),
)}
/>
) : null}
</div>
) : null}
</DialogContent>
Expand Down
25 changes: 17 additions & 8 deletions apps/web/src/components/ping-response-analysis/region-info.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { StatusCodeBadge } from "@/components/monitor/status-code-badge";
import type { Region } from "@openstatus/db/src/schema/constants";
import { latencyFormatter, regionFormatter, timestampFormatter } from "./utils";
import type { RegionChecker } from "./utils";

export function RegionInfo({
check,
error,
}: {
check: Pick<RegionChecker, "region" | "timestamp" | "latency" | "status">;
check: {
region: Region;
timestamp: number;
latency: number;
status?: number;
};
error?: string;
}) {
return (
Expand All @@ -31,12 +36,16 @@ export function RegionInfo({
<code>{latencyFormatter(check.latency)}</code>
</p>
</div>
<div className="col-span-2">
<p className="text-muted-foreground">Status:</p>
</div>
<div className="col-span-3 sm:col-span-6">
<StatusCodeBadge statusCode={check.status} />
</div>
{check.status ? (
<>
<div className="col-span-2">
<p className="text-muted-foreground">Status:</p>
</div>
<div className="col-span-3 sm:col-span-6">
<StatusCodeBadge statusCode={check.status} />
</div>
</>
) : null}
{error ? (
<>
<div className="col-span-2">
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/components/ping-response-analysis/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const timingSchema = z.object({
});

export const checkerSchema = z.object({
type: z.literal("http").default("http"),
status: z.number(),
latency: z.number(),
headers: z.record(z.string()),
Expand All @@ -121,6 +122,7 @@ export const regionCheckerSchema = checkerSchema.extend({

export type Timing = z.infer<typeof timingSchema>;
export type Checker = z.infer<typeof checkerSchema>;
// FIXME: does not include TCP!
export type RegionChecker = z.infer<typeof regionCheckerSchema>;
export type Method = "GET" | "POST" | "PUT" | "DELETE" | "HEAD";
export type CachedRegionChecker = z.infer<typeof cachedCheckerSchema>;
Expand Down

0 comments on commit 0f88a9b

Please sign in to comment.