Openstatus www.openstatus.dev

๐Ÿ› more and more single checker (#1057)

* ๐Ÿ› more and more

* ci: apply automated fixes

* ๐Ÿšง single check

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Thibault Le Ouay
autofix-ci[bot]
and committed by
GitHub
ff8c1a03 f38efd2d

+26 -8
+14 -4
apps/checker/handlers/tcp.go
··· 23 23 Timing checker.TCPResponseTiming `json:"timing"` 24 24 } 25 25 26 - // Only used for Tinybird 26 + // Only used for Tinybird. 27 27 type TCPData struct { 28 28 Timing string `json:"timing"` 29 29 ErrorMessage string `json:"errorMessage"` 30 30 Region string `json:"region"` 31 31 Trigger string `json:"trigger"` 32 + URI string `json:"uri"` 32 33 33 34 RequestId int64 `json:"requestId,omitempty"` 34 35 WorkspaceID int64 `json:"workspaceId"` ··· 85 86 return 86 87 } 87 88 89 + var trigger = "cron" 90 + if req.Trigger != "" { 91 + trigger = req.Trigger 92 + } 93 + 88 94 var called int 89 95 90 96 op := func() error { ··· 112 118 Timing: string(timingAsString), 113 119 Latency: latency, 114 120 CronTimestamp: req.CronTimestamp, 115 - Trigger: "cron", 121 + Trigger: trigger, 122 + URI: req.URL, 116 123 } 117 124 118 125 if req.Status == "active" && req.DegradedAfter > 0 && latency > req.DegradedAfter { ··· 169 176 Region: h.Region, 170 177 MonitorID: monitorId, 171 178 Error: 1, 172 - Trigger: "cron", 179 + Trigger: trigger, 180 + URI: req.URL, 173 181 }, dataSourceName); err != nil { 174 182 log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird") 175 183 } ··· 280 288 Timing: string(timingAsString), 281 289 Latency: latency, 282 290 RequestId: req.RequestId, 283 - Trigger: "API", 291 + Trigger: "api", 292 + URI: req.URL, 284 293 } 285 294 286 295 if req.RequestId != 0 { ··· 302 311 Error: 1, 303 312 RequestId: req.RequestId, 304 313 Trigger: "api", 314 + URI: req.URL, 305 315 }, dataSourceName); err != nil { 306 316 log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird") 307 317 }
+1
apps/checker/request/request.go
··· 68 68 WorkspaceID string `json:"workspaceId"` 69 69 URL string `json:"url"` 70 70 MonitorID string `json:"monitorId"` 71 + Trigger string `json:"trigger,omitempty"` 71 72 RawAssertions []json.RawMessage `json:"assertions,omitempty"` 72 73 RequestId int64 `json:"requestId,omitempty"` 73 74 CronTimestamp int64 `json:"cronTimestamp"`
+5 -2
apps/server/src/v1/monitors/trigger/post.ts
··· 13 13 import { env } from "../../../env"; 14 14 import { openApiErrorResponses } from "../../../libs/errors/openapi-error-responses"; 15 15 import { ParamsSchema } from "../schema"; 16 + 16 17 const triggerMonitor = createRoute({ 17 - method: "get", 18 + method: "post", 18 19 tags: ["monitor"], 19 20 description: "Trigger a monitor check", 20 21 path: "/:id/trigger", ··· 143 144 assertions: row.assertions ? JSON.parse(row.assertions) : null, 144 145 degradedAfter: row.degradedAfter, 145 146 timeout: row.timeout, 147 + trigger: "api", 146 148 }; 147 149 } 148 150 if (row.jobType === "tcp") { 149 151 payload = { 150 152 workspaceId: String(row.workspaceId), 151 153 monitorId: String(row.id), 152 - url: row.url, 154 + uri: row.url, 153 155 status: status, 154 156 assertions: row.assertions ? JSON.parse(row.assertions) : null, 155 157 cronTimestamp: timestamp, 156 158 degradedAfter: row.degradedAfter, 157 159 timeout: row.timeout, 160 + trigger: "api", 158 161 }; 159 162 } 160 163
+3 -1
apps/web/src/app/api/checker/cron/_cron.ts
··· 174 174 assertions: row.assertions ? JSON.parse(row.assertions) : null, 175 175 degradedAfter: row.degradedAfter, 176 176 timeout: row.timeout, 177 + trigger: "cron", 177 178 }; 178 179 } 179 180 if (row.jobType === "tcp") { 180 181 payload = { 181 182 workspaceId: String(row.workspaceId), 182 183 monitorId: String(row.id), 183 - url: row.url, 184 + uri: row.url, 184 185 status: status, 185 186 assertions: row.assertions ? JSON.parse(row.assertions) : null, 186 187 cronTimestamp: timestamp, 187 188 degradedAfter: row.degradedAfter, 188 189 timeout: row.timeout, 190 + trigger: "cron", 189 191 }; 190 192 } 191 193
+3 -1
packages/utils/index.ts
··· 445 445 assertions: z.array(base).nullable(), 446 446 timeout: z.number().default(45000), 447 447 degradedAfter: z.number().nullable(), 448 + trigger: z.enum(["cron", "api"]).optional().nullable().default("cron"), 448 449 }); 449 450 450 451 export type HttpPayload = z.infer<typeof httpPayloadSchema>; ··· 452 453 export const tpcPayloadSchema = z.object({ 453 454 status: z.enum(monitorStatus), 454 455 workspaceId: z.string(), 455 - url: z.string(), 456 + uri: z.string(), 456 457 monitorId: z.string(), 457 458 assertions: z.array(base).nullable(), 458 459 cronTimestamp: z.number(), 459 460 timeout: z.number().default(45000), 460 461 degradedAfter: z.number().nullable(), 462 + trigger: z.enum(["cron", "api"]).optional().nullable().default("cron"), 461 463 });