1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| begun := time.Now() req, err := http.NewRequest(*webhookMethod, h.String(), nil) if err != nil { setFailureMetrics(h.String(), "client_request_create") log.Println("error:", err) continue } userInfo := h.User if userInfo != nil { if password, passwordSet := userInfo.Password(); passwordSet { req.SetBasicAuth(userInfo.Username(), password) } }
successfulReloadWebhook := false
for retries := *webhookRetries; retries != 0; retries-- { log.Printf("performing webhook request (%d/%d)", retries, *webhookRetries) resp, err := http.DefaultClient.Do(req) if err != nil { setFailureMetrics(h.String(), "client_request_do") log.Println("error:", err) time.Sleep(time.Second * 10) continue } resp.Body.Close() requestsByStatusCode.WithLabelValues(h.String(), strconv.Itoa(resp.StatusCode)).Inc() if resp.StatusCode != *webhookStatusCode { setFailureMetrics(h.String(), "client_response") log.Println("error:", "Received response code", resp.StatusCode, ", expected", *webhookStatusCode) time.Sleep(time.Second * 10) continue }
setSuccessMetrics(h.String(), begun) log.Println("successfully triggered reload") successfulReloadWebhook = true break }
if !successfulReloadWebhook { setFailureMetrics(h.String(), "retries_exhausted") log.Println("error:", "Webhook reload retries exhausted") }
|