MCPcopy
hub / github.com/grafana/tempo / RunHealthCheck

Function RunHealthCheck

cmd/tempo/health.go:18–42  ·  view source on GitHub ↗

RunHealthCheck performs a health check against the /ready endpoint. Returns exit code 0 if healthy, 1 if unhealthy.

(url string)

Source from the content-addressed store, hash-verified

16// RunHealthCheck performs a health check against the /ready endpoint.
17// Returns exit code 0 if healthy, 1 if unhealthy.
18func 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}

Callers 4

TestRunHealthCheckFunction · 0.85
mainFunction · 0.85

Calls 3

GetMethod · 0.95
CloseMethod · 0.65
ReadAllMethod · 0.65

Tested by 3

TestRunHealthCheckFunction · 0.68