Openstatus www.openstatus.dev

fix: tcp test button (#1078)

* fix: tcp

* fix: ts error

authored by

Maximilian Kaske and committed by
GitHub
0f88a9b7 a973cae5

+69 -23
+2
apps/web/src/app/api/checker/test/tcp/schema.ts
··· 12 12 }); 13 13 14 14 export const TCPResponse = z.object({ 15 + type: z.literal("tcp").default("tcp"), 15 16 requestId: z.number().optional(), 16 17 workspaceId: z.number().optional(), 17 18 monitorId: z.number().optional(), ··· 22 23 }), 23 24 error: z.string().optional(), 24 25 region: monitorFlyRegionSchema, 26 + latency: z.number().optional(), 25 27 }); 26 28 27 29 export type tcpPayload = z.infer<typeof tcpPayload>;
+35
apps/web/src/app/play/checker/api/mock.ts
··· 20 20 method: "GET", 21 21 checks: [ 22 22 { 23 + type: "http", 23 24 status: 200, 24 25 latency: 889, 25 26 headers: { ··· 55 56 region: "ams", 56 57 }, 57 58 { 59 + type: "http", 58 60 status: 200, 59 61 latency: 1602, 60 62 headers: { ··· 91 93 region: "arn", 92 94 }, 93 95 { 96 + type: "http", 94 97 status: 200, 95 98 latency: 823, 96 99 headers: { ··· 127 130 region: "atl", 128 131 }, 129 132 { 133 + type: "http", 130 134 status: 200, 131 135 latency: 1198, 132 136 headers: { ··· 163 167 region: "bog", 164 168 }, 165 169 { 170 + type: "http", 166 171 status: 200, 167 172 latency: 1423, 168 173 headers: { ··· 199 204 region: "bom", 200 205 }, 201 206 { 207 + type: "http", 202 208 status: 200, 203 209 latency: 1134, 204 210 headers: { ··· 235 241 region: "bos", 236 242 }, 237 243 { 244 + type: "http", 238 245 status: 200, 239 246 latency: 812, 240 247 headers: { ··· 271 278 region: "cdg", 272 279 }, 273 280 { 281 + type: "http", 274 282 status: 200, 275 283 latency: 1081, 276 284 headers: { ··· 307 315 region: "den", 308 316 }, 309 317 { 318 + type: "http", 310 319 status: 200, 311 320 latency: 1329, 312 321 headers: { ··· 343 352 region: "dfw", 344 353 }, 345 354 { 355 + type: "http", 346 356 status: 200, 347 357 latency: 380, 348 358 headers: { ··· 379 389 region: "ewr", 380 390 }, 381 391 { 392 + type: "http", 382 393 status: 200, 383 394 latency: 802, 384 395 headers: { ··· 415 426 region: "eze", 416 427 }, 417 428 { 429 + type: "http", 418 430 status: 200, 419 431 latency: 615, 420 432 headers: { ··· 450 462 region: "fra", 451 463 }, 452 464 { 465 + type: "http", 453 466 status: 200, 454 467 latency: 1481, 455 468 headers: { ··· 486 499 region: "gdl", 487 500 }, 488 501 { 502 + type: "http", 489 503 status: 200, 490 504 latency: 768, 491 505 headers: { ··· 522 536 region: "gig", 523 537 }, 524 538 { 539 + type: "http", 525 540 status: 200, 526 541 latency: 662, 527 542 headers: { ··· 558 573 region: "gru", 559 574 }, 560 575 { 576 + type: "http", 561 577 status: 200, 562 578 latency: 1543, 563 579 headers: { ··· 594 610 region: "hkg", 595 611 }, 596 612 { 613 + type: "http", 597 614 status: 200, 598 615 latency: 369, 599 616 headers: { ··· 630 647 region: "iad", 631 648 }, 632 649 { 650 + type: "http", 633 651 status: 200, 634 652 latency: 1264, 635 653 headers: { ··· 666 684 region: "jnb", 667 685 }, 668 686 { 687 + type: "http", 669 688 status: 200, 670 689 latency: 642, 671 690 headers: { ··· 702 721 region: "lax", 703 722 }, 704 723 { 724 + type: "http", 705 725 status: 200, 706 726 latency: 627, 707 727 headers: { ··· 738 758 region: "lhr", 739 759 }, 740 760 { 761 + type: "http", 741 762 status: 200, 742 763 latency: 951, 743 764 headers: { ··· 774 795 region: "mad", 775 796 }, 776 797 { 798 + type: "http", 777 799 status: 200, 778 800 latency: 808, 779 801 headers: { ··· 810 832 region: "mia", 811 833 }, 812 834 { 835 + type: "http", 813 836 status: 200, 814 837 latency: 1301, 815 838 headers: { ··· 846 869 region: "nrt", 847 870 }, 848 871 { 872 + type: "http", 849 873 status: 200, 850 874 latency: 1079, 851 875 headers: { ··· 882 906 region: "ord", 883 907 }, 884 908 { 909 + type: "http", 885 910 status: 200, 886 911 latency: 1349, 887 912 headers: { ··· 917 942 region: "otp", 918 943 }, 919 944 { 945 + type: "http", 920 946 status: 200, 921 947 latency: 970, 922 948 headers: { ··· 953 979 region: "phx", 954 980 }, 955 981 { 982 + type: "http", 956 983 status: 200, 957 984 latency: 1539, 958 985 headers: { ··· 989 1016 region: "qro", 990 1017 }, 991 1018 { 1019 + type: "http", 992 1020 status: 200, 993 1021 latency: 1347, 994 1022 headers: { ··· 1025 1053 region: "scl", 1026 1054 }, 1027 1055 { 1056 + type: "http", 1028 1057 status: 200, 1029 1058 latency: 400, 1030 1059 headers: { ··· 1061 1090 region: "sjc", 1062 1091 }, 1063 1092 { 1093 + type: "http", 1064 1094 status: 200, 1065 1095 latency: 883, 1066 1096 headers: { ··· 1097 1127 region: "sea", 1098 1128 }, 1099 1129 { 1130 + type: "http", 1100 1131 status: 200, 1101 1132 latency: 825, 1102 1133 headers: { ··· 1133 1164 region: "sin", 1134 1165 }, 1135 1166 { 1167 + type: "http", 1136 1168 status: 200, 1137 1169 latency: 526, 1138 1170 headers: { ··· 1169 1201 region: "syd", 1170 1202 }, 1171 1203 { 1204 + type: "http", 1172 1205 status: 200, 1173 1206 latency: 869, 1174 1207 headers: { ··· 1204 1237 region: "waw", 1205 1238 }, 1206 1239 { 1240 + type: "http", 1207 1241 status: 200, 1208 1242 latency: 1133, 1209 1243 headers: { ··· 1240 1274 region: "yul", 1241 1275 }, 1242 1276 { 1277 + type: "http", 1243 1278 status: 200, 1244 1279 latency: 447, 1245 1280 headers: {
-4
apps/web/src/components/forms/monitor/form.tsx
··· 184 184 jobType, 185 185 } = form.getValues(); 186 186 187 - // FIXME: add support for TCP 188 - // if (jobType !== "http") 189 - // return { error: "Only HTTP tests are supported. Coming soon..." }; 190 - 191 187 if ( 192 188 body && 193 189 body !== "" &&
+13 -11
apps/web/src/components/forms/monitor/request-test-button.tsx
··· 138 138 {check ? ( 139 139 <div className="grid gap-8"> 140 140 <RegionInfo check={check.data} error={check.error} /> 141 - <ResponseDetailTabs 142 - timing={check.data.timing} 143 - headers={check.data.headers} 144 - status={check.data.status} 145 - assertions={deserialize( 146 - JSON.stringify([ 147 - ...(statusAssertions || []), 148 - ...(headerAssertions || []), 149 - ]), 150 - )} 151 - /> 141 + {check.data.type === "http" ? ( 142 + <ResponseDetailTabs 143 + timing={check.data.timing} 144 + headers={check.data.headers} 145 + status={check.data.status} 146 + assertions={deserialize( 147 + JSON.stringify([ 148 + ...(statusAssertions || []), 149 + ...(headerAssertions || []), 150 + ]), 151 + )} 152 + /> 153 + ) : null} 152 154 </div> 153 155 ) : null} 154 156 </DialogContent>
+17 -8
apps/web/src/components/ping-response-analysis/region-info.tsx
··· 1 1 import { StatusCodeBadge } from "@/components/monitor/status-code-badge"; 2 + import type { Region } from "@openstatus/db/src/schema/constants"; 2 3 import { latencyFormatter, regionFormatter, timestampFormatter } from "./utils"; 3 - import type { RegionChecker } from "./utils"; 4 4 5 5 export function RegionInfo({ 6 6 check, 7 7 error, 8 8 }: { 9 - check: Pick<RegionChecker, "region" | "timestamp" | "latency" | "status">; 9 + check: { 10 + region: Region; 11 + timestamp: number; 12 + latency: number; 13 + status?: number; 14 + }; 10 15 error?: string; 11 16 }) { 12 17 return ( ··· 31 36 <code>{latencyFormatter(check.latency)}</code> 32 37 </p> 33 38 </div> 34 - <div className="col-span-2"> 35 - <p className="text-muted-foreground">Status:</p> 36 - </div> 37 - <div className="col-span-3 sm:col-span-6"> 38 - <StatusCodeBadge statusCode={check.status} /> 39 - </div> 39 + {check.status ? ( 40 + <> 41 + <div className="col-span-2"> 42 + <p className="text-muted-foreground">Status:</p> 43 + </div> 44 + <div className="col-span-3 sm:col-span-6"> 45 + <StatusCodeBadge statusCode={check.status} /> 46 + </div> 47 + </> 48 + ) : null} 40 49 {error ? ( 41 50 <> 42 51 <div className="col-span-2">
+2
apps/web/src/components/ping-response-analysis/utils.ts
··· 100 100 }); 101 101 102 102 export const checkerSchema = z.object({ 103 + type: z.literal("http").default("http"), 103 104 status: z.number(), 104 105 latency: z.number(), 105 106 headers: z.record(z.string()), ··· 121 122 122 123 export type Timing = z.infer<typeof timingSchema>; 123 124 export type Checker = z.infer<typeof checkerSchema>; 125 + // FIXME: does not include TCP! 124 126 export type RegionChecker = z.infer<typeof regionCheckerSchema>; 125 127 export type Method = "GET" | "POST" | "PUT" | "DELETE" | "HEAD"; 126 128 export type CachedRegionChecker = z.infer<typeof cachedCheckerSchema>;