Openstatus www.openstatus.dev

๐Ÿ› checker (#531)

authored by

Thibault Le Ouay and committed by
GitHub
f1dabcfb 25a8f9a4

+50 -3
+9 -1
apps/checker/main.go
··· 74 74 // Add one more retry 75 75 response, error = ping(client, u) 76 76 if error != nil { 77 - sendToTinybirdNew(response) 77 + sendToTinybirdNew(PingData{ 78 + Url: u.Url, 79 + Region: region, 80 + Message: error.Error(), 81 + CronTimestamp: u.CronTimestamp, 82 + Timestamp: u.CronTimestamp, 83 + MonitorId: u.MonitorId, 84 + WorkspaceId: u.WorkspaceId, 85 + }) 78 86 if u.Status == "active" { 79 87 updateStatus(UpdateData{ 80 88 MonitorId: u.MonitorId,
+1 -1
apps/checker/ping.go
··· 83 83 start := time.Now() 84 84 response, err := client.Do(request) 85 85 latency := time.Since(start).Milliseconds() 86 - defer response.Body.Close() 87 86 88 87 if err != nil { 89 88 if urlErr, ok := err.(*url.Error); ok { ··· 102 101 103 102 return PingData{}, fmt.Errorf("Error with monitor %s: %w", inputData.Url, err) 104 103 } 104 + defer response.Body.Close() 105 105 106 106 _, err = io.ReadAll(response.Body) 107 107
+38
apps/checker/ping_test.go
··· 1 + package main 2 + 3 + import ( 4 + "net/http" 5 + "testing" 6 + ) 7 + 8 + func Test_ping(t *testing.T) { 9 + type args struct { 10 + client *http.Client 11 + inputData InputData 12 + } 13 + tests := []struct { 14 + name string 15 + args args 16 + want PingData 17 + wantErr bool 18 + }{ 19 + {name: "200", args: args{client: &http.Client{}, inputData: InputData{Url: "https://openstat.us", CronTimestamp: 1}}, want: PingData{Url: "https://openstat.us", StatusCode: 200}, wantErr: false}, 20 + {name: "500", args: args{client: &http.Client{}, inputData: InputData{Url: "https://openstat.us/500", CronTimestamp: 1}}, want: PingData{Url: "https://openstat.us/500", StatusCode: 500}, wantErr: false}, 21 + {name: "500", args: args{client: &http.Client{}, inputData: InputData{Url: "https://somethingthatwillfail.ed", CronTimestamp: 1}}, want: PingData{Url: "https://openstat.us/500", StatusCode: 0}, wantErr: true}, 22 + 23 + // TODO: Add test cases. 24 + } 25 + for _, tt := range tests { 26 + t.Run(tt.name, func(t *testing.T) { 27 + got, err := ping(tt.args.client, tt.args.inputData) 28 + 29 + if (err != nil) != tt.wantErr { 30 + t.Errorf("ping() error = %v, wantErr %v", err, tt.wantErr) 31 + return 32 + } 33 + if got.StatusCode != tt.want.StatusCode { 34 + t.Errorf("ping() = %v, want %v", got, tt.want) 35 + } 36 + }) 37 + } 38 + }
+2 -1
apps/web/src/app/shared-metadata.ts
··· 1 1 import type { Metadata } from "next"; 2 2 3 3 export const TITLE = "OpenStatus"; 4 - export const DESCRIPTION = "Open-Source monitoring with incident management."; 4 + export const DESCRIPTION = 5 + "A better way to monitor your services. Don't let your down time ruin your day."; 5 6 6 7 export const defaultMetadata: Metadata = { 7 8 title: {