Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
🥅 add retry (#502)
Thibault Le Ouay6f2de3968365
diff --git a/apps/checker/main.go b/apps/checker/main.goindex 1f61b4ab4..a3e6390fb 100644--- a/apps/checker/main.go+++ b/apps/checker/main.go@@ -29,86 +29,7 @@ type InputData struct {func main() {r := chi.NewRouter()r.Use(middleware.Logger)- r.Post("/", func(w http.ResponseWriter, r *http.Request) {- if r.Header.Get("Authorization") != "Basic "+os.Getenv("CRON_SECRET") {- http.Error(w, "Unauthorized", 401)- return- }- i, err := strconv.Atoi(r.Header.Get("X-CloudTasks-TaskRetryCount"))- if err != nil {- http.Error(w, "Something went whont", 400)- return- }- // If something went wrong we only try it twice- if i > 1 {- w.WriteHeader(http.StatusOK)- w.Write([]byte("Ok"))- return- }-- if r.Body == nil {- http.Error(w, "Please send a request body", 400)- return- }- var u InputData- // region := os.Getenv("FLY_REGION")-- err = json.NewDecoder(r.Body).Decode(&u)-- fmt.Printf("🚀 Start checker for %+v \n", u)-- if err != nil {- w.Write([]byte("Ok"))- w.WriteHeader(200)- return- }-- client := &http.Client{}- defer client.CloseIdleConnections()-- response, error := ping(client, u)-- if error != nil {- sendToTinybird(response)- if u.Status == "active" {- // updateStatus(UpdateData{- // MonitorId: u.MonitorId,- // Status: "error",- // Message: error.Error(),- // Region: region,- // })- }- w.Write([]byte("Ok"))- w.WriteHeader(200)- return- }-- sendToTinybird(response)- if response.StatusCode < 200 || response.StatusCode >= 300 {- // If the status code is not within the 200 range, we update the status to error- // updateStatus(UpdateData{- // MonitorId: u.MonitorId,- // Status: "error",- // StatusCode: response.StatusCode,- // Region: region,- // })- }- if u.Status == "error" {- // If the status was error, we update it to active- // updateStatus(UpdateData{- // MonitorId: u.MonitorId,- // Status: "active",- // Region: region,- // StatusCode: response.StatusCode,- // })- }-- fmt.Printf("⏱️ End checker for %+v with latency %+d and statusCode %+d", u, response.Latency, response.StatusCode)- w.Write([]byte("Ok"))- w.WriteHeader(200)- return- })// That's the new checker sending to the correct ingest endpointr.Post("/checker", func(w http.ResponseWriter, r *http.Request) {if r.Header.Get("Authorization") != "Basic "+os.Getenv("CRON_SECRET") {@@ -150,32 +71,40 @@ func main() {response, error := ping(client, u)if error != nil {- sendToTinybirdNew(response)- if u.Status == "active" {- updateStatus(UpdateData{- MonitorId: u.MonitorId,- Status: "error",- Message: error.Error(),- Region: region,- })+ // Add one more retry+ response, error = ping(client, u)+ if error != nil {+ sendToTinybirdNew(response)+ if u.Status == "active" {+ updateStatus(UpdateData{+ MonitorId: u.MonitorId,+ Status: "error",+ Message: error.Error(),+ Region: region,+ })+ }+ w.Write([]byte("Ok"))+ w.WriteHeader(200)+ return}- w.Write([]byte("Ok"))- w.WriteHeader(200)- return}- sendToTinybirdNew(response)-if response.StatusCode < 200 || response.StatusCode >= 300 {- // If the status code is not within the 200 range, we update the status to error- updateStatus(UpdateData{- MonitorId: u.MonitorId,- Status: "error",- StatusCode: response.StatusCode,- Region: region,- })+ // Add one more retry+ response, error = ping(client, u)+ if response.StatusCode < 200 || response.StatusCode >= 300 && u.Status == "active" {+ // If the status code is not within the 200 range, we update the status to error+ updateStatus(UpdateData{+ MonitorId: u.MonitorId,+ Status: "error",+ StatusCode: response.StatusCode,+ Region: region,+ })+ }}- if u.Status == "error" {++ // If the status was error and the status code is within the 200 range, we update the status to active+ if u.Status == "error" && response.StatusCode >= 200 && response.StatusCode < 300 {// If the status was error, we update it to activeupdateStatus(UpdateData{MonitorId: u.MonitorId,@@ -184,8 +113,10 @@ func main() {StatusCode: response.StatusCode,})}+ // We send the data to Tinybird+ sendToTinybirdNew(response)- fmt.Printf("⏱️ End checker for %+v with latency %+d and statusCode %+d", u, response.Latency, response.StatusCode)+ fmt.Printf("⏱️ End checker for %v with latency %d and statusCode %d", u, response.Latency, response.StatusCode)w.Write([]byte("Ok"))w.WriteHeader(200)returndiff --git a/apps/docs/package.json b/apps/docs/package.jsonindex 9752a59c1..287687c80 100644--- a/apps/docs/package.json+++ b/apps/docs/package.json@@ -3,7 +3,8 @@"version": "0.0.0","private": true,"scripts": {- "dev": "npx mintlify@latest dev"+ "dev": "npx mintlify@latest dev",+ "verify": "npx mintlify@latest broken-links"},"keywords": [],"author": "OpenStatus"