Skip to content

Commit

Permalink
🔥 improvment (#874)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultleouay authored Jun 13, 2024
1 parent beabcb7 commit f1457bb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions apps/checker/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,12 @@ func main() {
if err != nil {
return fmt.Errorf("unable to ping: %w", err)
}

r.Region = flyRegion

res = r
res.RequestId = req.RequestId
res.WorkspaceId = req.WorkspaceId
if err := tinybirdClient.SendEvent(ctx, res, dataSourceName); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("failed to send event to tinybird")
}
Expand Down
20 changes: 11 additions & 9 deletions apps/checker/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ type Timing struct {
}

type Response struct {
Status int `json:"status,omitempty"`
Latency int64 `json:"latency"`
Body string `json:"body,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Time int64 `json:"time"`
Timing Timing `json:"timing"`
Error string `json:"error,omitempty"`
Tags []string `json:"tags,omitempty"`
Region string `json:"region"`
RequestId int64 `json:"requestId,omitempty"`
WorkspaceId int64 `json:"workspaceId,omitempty"`
Status int `json:"status,omitempty"`
Latency int64 `json:"latency"`
Body string `json:"body,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Time int64 `json:"time"`
Timing Timing `json:"timing"`
Error string `json:"error,omitempty"`
Tags []string `json:"tags,omitempty"`
Region string `json:"region"`
}

func Ping(ctx context.Context, client *http.Client, inputData request.CheckerRequest) (PingData, error) {
Expand Down
11 changes: 6 additions & 5 deletions apps/checker/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ type CheckerRequest struct {
}

type PingRequest struct {
ID string `json:"id"`
URL string `json:"url"`
Method string `json:"method"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
RequestId int64 `json:"requestId"`
WorkspaceId int64 `json:"workspaceId"`
URL string `json:"url"`
Method string `json:"method"`
Body string `json:"body"`
Headers map[string]string `json:"headers"`
}
6 changes: 3 additions & 3 deletions apps/server/src/v1/check/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const postRoute = createRoute({
export function registerPostCheck(api: typeof checkAPI) {
return api.openapi(postRoute, async (c) => {
const data = c.req.valid("json");
const workspaceId = c.get("workspaceId");
const workspaceId = Number(c.get("workspaceId"));
const input = c.req.valid("json");

const { headers, regions, runCount, aggregated, ...rest } = data;
Expand All @@ -72,7 +72,7 @@ export function registerPostCheck(api: typeof checkAPI) {
},
method: "POST",
body: JSON.stringify({
checkId: newCheck.id,
requestId: newCheck.id,
workspaceId: workspaceId,
url: input.url,
method: input.method,
Expand Down Expand Up @@ -195,7 +195,7 @@ export function registerPostCheck(api: typeof checkAPI) {

aggregatedResponse = AggregatedResult.parse({
dns: aggregatedDNS,
connection: aggregatedConnect,
connect: aggregatedConnect,
tls: aggregatedTls,
firstByte: aggregatedFirst,
transfer: aggregatedTransfer,
Expand Down

0 comments on commit f1457bb

Please sign in to comment.