| 278 | } |
| 279 | |
| 280 | func scrapeMetrics(t *testing.T, service *e2e.HTTPService, port int, searchString string) bool { |
| 281 | t.Helper() |
| 282 | |
| 283 | // create HTTPS client with insecure skip verify |
| 284 | client := &http.Client{ |
| 285 | Transport: &http.Transport{ |
| 286 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 287 | }, |
| 288 | Timeout: util.MetricsTimeout, |
| 289 | } |
| 290 | |
| 291 | found := false |
| 292 | |
| 293 | require.Eventually(t, func() bool { |
| 294 | url := "https://" + service.Endpoint(port) + "/metrics" |
| 295 | resp, err := client.Get(url) |
| 296 | if err != nil { |
| 297 | t.Logf("failed to scrape metrics: %v", err) |
| 298 | return false |
| 299 | } |
| 300 | defer resp.Body.Close() |
| 301 | |
| 302 | if resp.StatusCode != http.StatusOK { |
| 303 | t.Logf("unexpected status code: %d", resp.StatusCode) |
| 304 | return false |
| 305 | } |
| 306 | |
| 307 | body, err := io.ReadAll(resp.Body) |
| 308 | if err != nil { |
| 309 | t.Logf("failed to read response body: %v", err) |
| 310 | return false |
| 311 | } |
| 312 | |
| 313 | found = bytes.Contains(body, []byte(searchString)) |
| 314 | return found |
| 315 | }, time.Minute, time.Second, "could not write trace to tempo") |
| 316 | |
| 317 | return found |
| 318 | } |