Openstatus www.openstatus.dev

๐Ÿ› api (#1293)

* ๐Ÿ›

* ๐Ÿ›

authored by

Thibault Le Ouay and committed by
GitHub
4b58137a b405ae9c

+138 -23
+14 -2
apps/server/src/routes/v1/monitors/get.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { and, db, eq, isNull } from "@openstatus/db"; 4 4 import { monitor } from "@openstatus/db/src/schema"; ··· 51 51 message: `Monitor ${id} not found`, 52 52 }); 53 53 } 54 + const otelHeader = _monitor.otelHeaders 55 + ? z 56 + .array( 57 + z.object({ 58 + key: z.string(), 59 + value: z.string(), 60 + }), 61 + ) 62 + .parse(JSON.parse(_monitor.otelHeaders)) 63 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 64 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 65 + : undefined; 54 66 55 67 const data = MonitorSchema.parse({ 56 68 ..._monitor, 57 69 openTelemetry: _monitor.otelEndpoint 58 70 ? { 59 - headers: _monitor.otelHeaders ?? undefined, 71 + headers: otelHeader, 60 72 endpoint: _monitor.otelEndpoint ?? undefined, 61 73 } 62 74 : undefined,
+23 -9
apps/server/src/routes/v1/monitors/get_all.ts
··· 39 39 .all(); 40 40 41 41 const data = z.array(MonitorSchema).parse( 42 - _monitors.map((monitor) => ({ 43 - ...monitor, 44 - openTelemetry: monitor.otelEndpoint 45 - ? { 46 - endpoint: monitor.otelEndpoint ?? undefined, 47 - headers: monitor.otelHeaders ?? undefined, 48 - } 49 - : undefined, 50 - })), 42 + _monitors.map((monitor) => { 43 + const otelHeader = monitor.otelHeaders 44 + ? z 45 + .array( 46 + z.object({ 47 + key: z.string(), 48 + value: z.string(), 49 + }), 50 + ) 51 + .parse(JSON.parse(monitor.otelHeaders)) 52 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 53 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 54 + : undefined; 55 + return { 56 + ...monitor, 57 + openTelemetry: monitor.otelEndpoint 58 + ? { 59 + endpoint: monitor.otelEndpoint ?? undefined, 60 + headers: otelHeader, 61 + } 62 + : undefined, 63 + }; 64 + }), 51 65 ); 52 66 53 67 return c.json(data, 200);
+15 -2
apps/server/src/routes/v1/monitors/post.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { Events } from "@openstatus/analytics"; 4 4 import { and, db, eq, isNull, sql } from "@openstatus/db"; ··· 104 104 .returning() 105 105 .get(); 106 106 107 + const otelHeader = _newMonitor.otelHeaders 108 + ? z 109 + .array( 110 + z.object({ 111 + key: z.string(), 112 + value: z.string(), 113 + }), 114 + ) 115 + .parse(JSON.parse(_newMonitor.otelHeaders)) 116 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 117 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 118 + : undefined; 119 + 107 120 const data = MonitorSchema.parse({ 108 121 ..._newMonitor, 109 122 openTelemetry: _newMonitor.otelEndpoint 110 123 ? { 111 - headers: _newMonitor.otelHeaders ?? undefined, 124 + headers: otelHeader, 112 125 endpoint: _newMonitor.otelEndpoint ?? undefined, 113 126 } 114 127 : undefined,
+15 -2
apps/server/src/routes/v1/monitors/post_http.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { Events } from "@openstatus/analytics"; 4 4 import { and, db, eq, isNull, sql } from "@openstatus/db"; ··· 118 118 .returning() 119 119 .get(); 120 120 121 + const otelHeader = _newMonitor.otelHeaders 122 + ? z 123 + .array( 124 + z.object({ 125 + key: z.string(), 126 + value: z.string(), 127 + }), 128 + ) 129 + .parse(JSON.parse(_newMonitor.otelHeaders)) 130 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 131 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 132 + : undefined; 133 + 121 134 const data = MonitorSchema.parse({ 122 135 ..._newMonitor, 123 136 openTelemetry: _newMonitor.otelEndpoint 124 137 ? { 125 - headers: _newMonitor.otelHeaders ?? undefined, 138 + headers: otelHeader, 126 139 endpoint: _newMonitor.otelEndpoint ?? undefined, 127 140 } 128 141 : undefined,
+15 -2
apps/server/src/routes/v1/monitors/post_tcp.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { Events } from "@openstatus/analytics"; 4 4 import { and, db, eq, isNull, sql } from "@openstatus/db"; ··· 104 104 .returning() 105 105 .get(); 106 106 107 + const otelHeader = _newMonitor.otelHeaders 108 + ? z 109 + .array( 110 + z.object({ 111 + key: z.string(), 112 + value: z.string(), 113 + }), 114 + ) 115 + .parse(JSON.parse(_newMonitor.otelHeaders)) 116 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 117 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 118 + : undefined; 119 + 107 120 const data = MonitorSchema.parse({ 108 121 ..._newMonitor, 109 122 openTelemetry: _newMonitor.otelEndpoint 110 123 ? { 111 - headers: _newMonitor.otelHeaders ?? undefined, 124 + headers: otelHeader, 112 125 endpoint: _newMonitor.otelEndpoint ?? undefined, 113 126 } 114 127 : undefined,
+15 -2
apps/server/src/routes/v1/monitors/put.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { and, db, eq, isNull } from "@openstatus/db"; 4 4 import { monitor } from "@openstatus/db/src/schema"; ··· 111 111 .returning() 112 112 .get(); 113 113 114 + const otelHeader = _newMonitor.otelHeaders 115 + ? z 116 + .array( 117 + z.object({ 118 + key: z.string(), 119 + value: z.string(), 120 + }), 121 + ) 122 + .parse(JSON.parse(_newMonitor.otelHeaders)) 123 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 124 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 125 + : undefined; 126 + 114 127 const data = MonitorSchema.parse({ 115 128 ..._newMonitor, 116 129 openTelemetry: _newMonitor.otelEndpoint 117 130 ? { 118 - headers: _newMonitor.otelHeaders ?? undefined, 131 + headers: otelHeader, 119 132 endpoint: _newMonitor.otelEndpoint ?? undefined, 120 133 } 121 134 : undefined,
+15 -2
apps/server/src/routes/v1/monitors/put_http.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { and, db, eq, isNull } from "@openstatus/db"; 4 4 import { monitor } from "@openstatus/db/src/schema"; ··· 131 131 .returning() 132 132 .get(); 133 133 134 + const otelHeader = _newMonitor.otelHeaders 135 + ? z 136 + .array( 137 + z.object({ 138 + key: z.string(), 139 + value: z.string(), 140 + }), 141 + ) 142 + .parse(JSON.parse(_newMonitor.otelHeaders)) 143 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 144 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 145 + : undefined; 146 + 134 147 const data = MonitorSchema.parse({ 135 148 ..._newMonitor, 136 149 openTelemetry: _newMonitor.otelEndpoint 137 150 ? { 138 - headers: _newMonitor.otelHeaders ?? undefined, 151 + headers: otelHeader, 139 152 endpoint: _newMonitor.otelEndpoint ?? undefined, 140 153 } 141 154 : undefined,
+14 -2
apps/server/src/routes/v1/monitors/put_tcp.ts
··· 1 - import { createRoute } from "@hono/zod-openapi"; 1 + import { createRoute, z } from "@hono/zod-openapi"; 2 2 3 3 import { and, db, eq, isNull } from "@openstatus/db"; 4 4 import { monitor } from "@openstatus/db/src/schema"; ··· 116 116 .where(eq(monitor.id, Number(_monitor.id))) 117 117 .returning() 118 118 .get(); 119 + const otelHeader = _newMonitor.otelHeaders 120 + ? z 121 + .array( 122 + z.object({ 123 + key: z.string(), 124 + value: z.string(), 125 + }), 126 + ) 127 + .parse(JSON.parse(_newMonitor.otelHeaders)) 128 + // biome-ignore lint/performance/noAccumulatingSpread: <explanation> 129 + .reduce((a, v) => ({ ...a, [v.key]: v.value }), {}) 130 + : undefined; 119 131 120 132 const data = MonitorSchema.parse({ 121 133 ..._newMonitor, 122 134 openTelemetry: _newMonitor.otelEndpoint 123 135 ? { 124 - headers: _newMonitor.otelHeaders ?? undefined, 136 + headers: otelHeader, 125 137 endpoint: _newMonitor.otelEndpoint ?? undefined, 126 138 } 127 139 : undefined,
+12
packages/db/src/seed.mts
··· 93 93 headers: '[{"key":"key", "value":"value"}]', 94 94 body: '{"hello":"world"}', 95 95 }, 96 + { 97 + id: 4, 98 + active: true, 99 + workspaceId: 1, 100 + periodicity: "10m", 101 + url: "https://www.google.com", 102 + method: "GET", 103 + regions: "gru", 104 + public: true, 105 + otelEndpoint: "https://otel.com:4337", 106 + otelHeaders: '[{"key":"Authorization","value":"Basic"}]', 107 + }, 96 108 ]) 97 109 .onConflictDoNothing() 98 110 .run();