Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› fix bug api (#873)

* ๐Ÿ› fix bug api

* ๐Ÿงช fix test

authored by

Thibault Le Ouay and committed by
GitHub
beabcb7c e396a1f0

+19 -16
+1 -1
apps/checker/cmd/main.go
··· 261 261 return fmt.Errorf("unable to ping: %w", err) 262 262 } 263 263 r.Region = flyRegion 264 + res = r 264 265 if err := tinybirdClient.SendEvent(ctx, res, dataSourceName); err != nil { 265 266 log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird") 266 267 } 267 - res = r 268 268 return nil 269 269 } 270 270 if err := backoff.Retry(op, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 3)); err != nil {
+3 -3
apps/server/src/v1/check/post.test.ts
··· 65 65 latency: 100, 66 66 region: "ams", 67 67 status: 200, 68 - timestamp: 1234567890, 68 + time: 1234567890, 69 69 timing: { 70 70 connectDone: 4, 71 71 connectStart: 3, ··· 93 93 mockFetch.mockReturnValue( 94 94 Promise.resolve( 95 95 new Response( 96 - '{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"timestamp":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}', 96 + '{"status":200,"latency":100,"body":"Hello World","headers":{"Content-Type":"application/json"},"time":1234567890,"timing":{"dnsStart":1,"dnsDone":2,"connectStart":3,"connectDone":4,"tlsHandshakeStart":5,"tlsHandshakeDone":6,"firstByteStart":7,"firstByteDone":8,"transferStart":9,"transferDone":10},"region":"ams"}', 97 97 { status: 200, headers: { "content-type": "application/json" } } 98 98 ) 99 99 ) ··· 134 134 latency: 100, 135 135 region: "ams", 136 136 status: 200, 137 - timestamp: 1234567890, 137 + time: 1234567890, 138 138 timing: { 139 139 connectDone: 4, 140 140 connectStart: 3,
+3 -12
apps/server/src/v1/check/post.ts
··· 8 8 import type { checkAPI } from "./index"; 9 9 import { 10 10 AggregatedResponseSchema, 11 + AggregatedResult, 11 12 CheckPostResponseSchema, 12 13 CheckSchema, 13 14 ResponseSchema, ··· 93 94 const allResults = await Promise.allSettled(currentFetch); 94 95 result.push(...allResults); 95 96 } 96 - console.log(result); 97 97 const filteredResult = result.filter((r) => r.status === "fulfilled"); 98 98 const fulfilledRequest = []; 99 99 for await (const r of filteredResult) { 100 100 if (r.status !== "fulfilled") throw new Error("No value"); 101 101 102 102 const json = await r.value.json(); 103 - console.log(ResponseSchema.safeParse(json)); 104 103 fulfilledRequest.push(ResponseSchema.parse(json)); 105 104 } 106 105 ··· 144 143 latencyArray 145 144 ) as number[]; 146 145 147 - const aggregate = z.object({ 148 - dms: AggregatedResponseSchema, 149 - connect: AggregatedResponseSchema, 150 - tls: AggregatedResponseSchema, 151 - firstByte: AggregatedResponseSchema, 152 - transfert: AggregatedResponseSchema, 153 - latency: AggregatedResponseSchema, 154 - }); 155 146 const aggregatedDNS = AggregatedResponseSchema.parse({ 156 147 p50: dnsPercentile[0], 157 148 p75: dnsPercentile[1], ··· 202 193 max: Math.max(...latencyArray), 203 194 }); 204 195 205 - aggregatedResponse = aggregate.parse({ 196 + aggregatedResponse = AggregatedResult.parse({ 206 197 dns: aggregatedDNS, 207 198 connection: aggregatedConnect, 208 199 tls: aggregatedTls, ··· 218 209 id: newCheck.id, 219 210 raw: allTimings, 220 211 response: lastResponse, 221 - aggregated: aggregatedResponse, 212 + aggregated: aggregatedResponse ? aggregatedResponse : undefined, 222 213 }); 223 214 224 215 return c.json(responseResult);
+12
apps/server/src/v1/check/schema.ts
··· 120 120 region: z.string().openapi({ description: "The region where the check ran" }), 121 121 }); 122 122 123 + export const AggregatedResult = z.object({ 124 + dns: AggregatedResponseSchema, 125 + connect: AggregatedResponseSchema, 126 + tls: AggregatedResponseSchema, 127 + firstByte: AggregatedResponseSchema, 128 + transfer: AggregatedResponseSchema, 129 + latency: AggregatedResponseSchema, 130 + }); 131 + 123 132 export const CheckPostResponseSchema = z.object({ 124 133 id: z.number().int().openapi({ description: "The id of the check" }), 125 134 raw: z.array(TimingSchema).openapi({ ··· 127 136 }), 128 137 response: ResponseSchema.openapi({ 129 138 description: "The last response of the check", 139 + }), 140 + aggregated: AggregatedResult.optional().openapi({ 141 + description: "The aggregated data of the check", 130 142 }), 131 143 });