InstantQuery evaluates instant PromQL queries against monitoring service.
(query string)
| 306 | |
| 307 | // InstantQuery evaluates instant PromQL queries against monitoring service. |
| 308 | func (s *Service) InstantQuery(query string) (string, error) { |
| 309 | if !s.p.IsRunning() { |
| 310 | return "", errors.Newf("%s is not running", s.p.Name()) |
| 311 | } |
| 312 | |
| 313 | res, err := (&http.Client{}).Get("http://" + s.p.Endpoint("http") + "/api/v1/query?query=" + query) |
| 314 | if err != nil { |
| 315 | return "", err |
| 316 | } |
| 317 | |
| 318 | if res.StatusCode < 200 || res.StatusCode >= 300 { |
| 319 | return "", errors.Newf("unexpected status code %d while fetching metrics", res.StatusCode) |
| 320 | } |
| 321 | defer errcapture.ExhaustClose(&err, res.Body, "metrics response") |
| 322 | |
| 323 | body, err := io.ReadAll(res.Body) |
| 324 | return string(body), err |
| 325 | } |
| 326 | |
| 327 | // GetMonitoringRunnable returns a Prometheus monitoring runnable. |
| 328 | func (s *Service) GetMonitoringRunnable() e2e.Runnable { |