RunHealthCheck performs a health check against the /ready endpoint. Returns exit code 0 if healthy, 1 if unhealthy.
(url string)
| 16 | // RunHealthCheck performs a health check against the /ready endpoint. |
| 17 | // Returns exit code 0 if healthy, 1 if unhealthy. |
| 18 | func RunHealthCheck(url string) int { |
| 19 | if url == "" { |
| 20 | url = defaultHealthURL |
| 21 | } |
| 22 | |
| 23 | client := &http.Client{ |
| 24 | Timeout: healthTimeout, |
| 25 | } |
| 26 | |
| 27 | resp, err := client.Get(url) //nolint:gosec |
| 28 | if err != nil { |
| 29 | fmt.Fprintf(os.Stderr, "Health check failed: %v\n", err) |
| 30 | return 1 |
| 31 | } |
| 32 | defer resp.Body.Close() |
| 33 | |
| 34 | if resp.StatusCode == http.StatusOK { |
| 35 | fmt.Println("Tempo is healthy") |
| 36 | return 0 |
| 37 | } |
| 38 | |
| 39 | body, _ := io.ReadAll(resp.Body) |
| 40 | fmt.Fprintf(os.Stderr, "Tempo is unhealthy: status %d: %s\n", resp.StatusCode, string(body)) |
| 41 | return 1 |
| 42 | } |