Skip to content

Open-source status page, incident response and uptime monitoring

test (#1514)

Thibault Le Ouay684524d59ffa
diff --git a/apps/checker/checker/update.go b/apps/checker/checker/update.go
index c6ed17019..8f530e80b 100644
--- a/apps/checker/checker/update.go
+++ b/apps/checker/checker/update.go
@@ -4,15 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
- "fmt"
+ "net/http"
"os"
+ "time"
"github.com/rs/zerolog/log"
- "google.golang.org/api/option"
- "cloud.google.com/go/auth"
- cloudtasks "cloud.google.com/go/cloudtasks/apiv2"
- taskspb "cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb"
)
type UpdateData struct {
@@ -25,66 +22,24 @@ type UpdateData struct {
Latency int64 `json:"latency,omitempty"`
}
-func UpdateStatus(ctx context.Context, updateData UpdateData) error {
-
+func UpdateStatus(ctx context.Context, updateData UpdateData) {
url := "https://openstatus-workflows.fly.dev/updateStatus"
basic := "Basic " + os.Getenv("CRON_SECRET")
payloadBuf := new(bytes.Buffer)
- opts := &auth.Options2LO{
- Email: os.Getenv("GCP_CLIENT_EMAIL"),
- PrivateKey: []byte(os.Getenv("GCP_PRIVATE_KEY")),
- Scopes: []string{
- "https://www.googleapis.com/auth/cloud-platform",
- },
- TokenURL: "https://oauth2.googleapis.com/token",
- }
-
- tp, err := auth.New2LOTokenProvider(opts)
- if err != nil {
- log.Ctx(ctx).Error().Err(err).Msg("error while creating token provider")
- return err
- }
-
- creds := auth.NewCredentials(&auth.CredentialsOptions{
- TokenProvider: tp,
- })
-
- client, err := cloudtasks.NewClient(ctx, option.WithAuthCredentials(creds))
- if err != nil {
- log.Ctx(ctx).Error().Err(err).Msg("error while creating cloud tasks client")
-
- }
- defer client.Close()
-
if err := json.NewEncoder(payloadBuf).Encode(updateData); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("error while updating status")
- return err
+ return
}
- projectID := os.Getenv("GCP_PROJECT_ID")
- queuePath := fmt.Sprintf("projects/%s/locations/europe-west1/queues/alerting", projectID)
- req := &taskspb.CreateTaskRequest{
- Parent: queuePath,
- Task: &taskspb.Task{
- // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#HttpRequest
- MessageType: &taskspb.Task_HttpRequest{
- HttpRequest: &taskspb.HttpRequest{
- HttpMethod: taskspb.HttpMethod_POST,
- Url: url,
- Headers: map[string]string{"Authorization": basic, "Content-Type": "application/json"},
- },
- },
- },
- }
-
- // Add a payload message if one is present.
- req.Task.GetHttpRequest().Body = payloadBuf.Bytes()
+ req, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, payloadBuf)
+ req.Header.Set("Authorization", basic)
+ req.Header.Set("Content-Type", "application/json")
- _, err = client.CreateTask(ctx, req)
- if err != nil {
- log.Ctx(ctx).Error().Err(err).Msg("error while creating the cloud task")
- return fmt.Errorf("cloudtasks.CreateTask: %w", err)
+ client := &http.Client{Timeout: time.Second * 10}
+ if _, err := client.Do(req); err != nil {
+ log.Ctx(ctx).Error().Err(err).Msg("error while updating status")
}
- return nil
+ defer req.Body.Close()
+ // Should we add a retry mechanism here?
}