Openstatus www.openstatus.dev

Revert "Please help (#1518)" (#1519)

This reverts commit dafd3a7618ccb67970b22ec932d053524c42ad3a.

authored by

Thibault Le Ouay and committed by
GitHub
62592a9e dafd3a76

+14 -59
+14 -59
apps/checker/checker/update.go
··· 4 4 "bytes" 5 5 "context" 6 6 "encoding/json" 7 - "fmt" 8 - "github.com/rs/zerolog/log" 9 - "google.golang.org/api/option" 7 + "net/http" 10 8 "os" 9 + "time" 11 10 12 - "cloud.google.com/go/auth" 13 - cloudtasks "cloud.google.com/go/cloudtasks/apiv2" 14 - taskspb "cloud.google.com/go/cloudtasks/apiv2/cloudtaskspb" 11 + "github.com/rs/zerolog/log" 12 + 15 13 ) 16 14 17 15 type UpdateData struct { ··· 24 22 Latency int64 `json:"latency,omitempty"` 25 23 } 26 24 27 - func UpdateStatus(ctx context.Context, updateData UpdateData) error { 28 - 25 + func UpdateStatus(ctx context.Context, updateData UpdateData) { 29 26 url := "https://openstatus-workflows.fly.dev/updateStatus" 30 27 basic := "Basic " + os.Getenv("CRON_SECRET") 31 28 payloadBuf := new(bytes.Buffer) 32 29 33 - opts := &auth.Options2LO{ 34 - Email: os.Getenv("GCP_CLIENT_EMAIL"), 35 - PrivateKey: []byte(os.Getenv("GCP_PRIVATE_KEY")), 36 - PrivateKeyID: os.Getenv("GCP_PRIVATE_KEY_ID"), 37 - Scopes: []string{ 38 - "https://www.googleapis.com/auth/cloud-platform", 39 - }, 40 - TokenURL: "https://oauth2.googleapis.com/token", 41 - } 42 - 43 - tp, err := auth.New2LOTokenProvider(opts) 44 - if err != nil { 45 - log.Ctx(ctx).Error().Err(err).Msg("error while creating token provider") 46 - return err 47 - } 48 - 49 - creds := auth.NewCredentials(&auth.CredentialsOptions{ 50 - TokenProvider: tp, 51 - }) 52 - 53 - client, err := cloudtasks.NewClient(ctx, option.WithAuthCredentials(creds)) 54 - if err != nil { 55 - log.Ctx(ctx).Error().Err(err).Msg("error while creating cloud tasks client") 56 - 57 - } 58 - defer client.Close() 59 - 60 30 if err := json.NewEncoder(payloadBuf).Encode(updateData); err != nil { 61 31 log.Ctx(ctx).Error().Err(err).Msg("error while updating status") 62 - return err 63 - } 64 - projectID := os.Getenv("GCP_PROJECT_ID") 65 - queuePath := fmt.Sprintf("projects/%s/locations/europe-west1/queues/alerting", projectID) 66 - req := &taskspb.CreateTaskRequest{ 67 - Parent: queuePath, 68 - Task: &taskspb.Task{ 69 - // https://godoc.org/google.golang.org/genproto/googleapis/cloud/tasks/v2#HttpRequest 70 - MessageType: &taskspb.Task_HttpRequest{ 71 - HttpRequest: &taskspb.HttpRequest{ 72 - HttpMethod: taskspb.HttpMethod_POST, 73 - Url: url, 74 - Headers: map[string]string{"Authorization": basic, "Content-Type": "application/json"}, 75 - }, 76 - }, 77 - }, 32 + return 78 33 } 34 + req, _ := http.NewRequestWithContext(ctx, http.MethodPost, url, payloadBuf) 35 + req.Header.Set("Authorization", basic) 36 + req.Header.Set("Content-Type", "application/json") 79 37 80 - // Add a payload message if one is present. 81 - req.Task.GetHttpRequest().Body = payloadBuf.Bytes() 82 - 83 - _, err = client.CreateTask(ctx, req) 84 - if err != nil { 85 - log.Ctx(ctx).Error().Err(err).Msg("error while creating the cloud task") 86 - return fmt.Errorf("cloudtasks.CreateTask: %w", err) 38 + client := &http.Client{Timeout: time.Second * 10} 39 + if _, err := client.Do(req); err != nil { 40 + log.Ctx(ctx).Error().Err(err).Msg("error while updating status") 87 41 } 88 42 89 - return nil 43 + defer req.Body.Close() 44 + // Should we add a retry mechanism here? 90 45 }