Skip to content

Commit

Permalink
🚀 ci for tcp (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultleouay authored Nov 7, 2024
1 parent aaf3e67 commit 88dea54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/server/src/v1/monitors/run/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { HTTPException } from "hono/http-exception";
import type { monitorsApi } from "..";
import { env } from "../../../env";
import { openApiErrorResponses } from "../../../libs/errors/openapi-error-responses";
import { HTTPTriggerResult, ParamsSchema } from "../schema";
import { HTTPTriggerResult, ParamsSchema, TCPTriggerResult } from "../schema";

const triggerMonitor = createRoute({
method: "post",
Expand All @@ -37,7 +37,7 @@ const triggerMonitor = createRoute({
200: {
content: {
"application/json": {
schema: z.array(HTTPTriggerResult),
schema: z.array(HTTPTriggerResult).or(z.array(TCPTriggerResult)),
},
},
description: "All the historical metrics",
Expand Down Expand Up @@ -193,8 +193,17 @@ export function registerRunMonitor(api: typeof monitorsApi) {
// console.log(result);

const bodies = await Promise.all(result.map((r) => r.json()));
console.log(bodies);
const data = z.array(HTTPTriggerResult).safeParse(bodies);
let data = null;
if (row.jobType === "http") {
data = z.array(HTTPTriggerResult).safeParse(bodies);
}
if (row.jobType === "tcp") {
data = z.array(TCPTriggerResult).safeParse(bodies);
}

if (!data) {
throw new HTTPException(400, { message: "Something went wrong" });
}

if (!data.success) {
console.log(data.error);
Expand Down
14 changes: 14 additions & 0 deletions apps/server/src/v1/monitors/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,20 @@ export const HTTPTriggerResult = z.object({
error: z.string().optional().nullable(),
});

const tcptimingSchema = z.object({
tcpStart: z.number(),
tcpDone: z.number(),
});

export const TCPTriggerResult = z.object({
latency: z.number(),
region: z.enum(flyRegions),
timestamp: z.number(),
timing: tcptimingSchema,
error: z.number().optional().nullable(),
errorMessage: z.string().optional().nullable(),
});

export const ResultRun = z.object({
latency: z.number().int(), // in ms
statusCode: z.number().int().nullable().default(null),
Expand Down

0 comments on commit 88dea54

Please sign in to comment.