Files
GreatHatoandGitHub d56356bbc0 [Feature] Add cleanup for terminated RayJob/RayCluster metrics (#3923)
* [Feature] Add cleanup for terminated RayJob/RayCluster metrics

* [Tests] Add test code

* Use Delete API for rayClusterProvisionedDurationSeconds

* Add helper function to avoid nil MetricsManager

* Fix wrong annotation

* test: add helper function for executing metrics requests

* Add comment for Delete API

* refactor the helper

* fix linting issue

* revert Delete API
2025-08-29 09:10:58 -07:00

27 lines
839 B
Go

package support
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/stretchr/testify/require"
)
// GetMetricsResponseAndCode simulates an HTTP GET request to the /metrics endpoint,
// processes it using a Prometheus handler built from the provided registry,
// and returns the resulting response body as a string along with the HTTP status code.
func GetMetricsResponseAndCode(t *testing.T, reg *prometheus.Registry) (string, int) {
t.Helper()
req, err := http.NewRequestWithContext(t.Context(), http.MethodGet, "/metrics", nil)
require.NoError(t, err)
rr := httptest.NewRecorder()
handler := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
handler.ServeHTTP(rr, req)
return rr.Body.String(), rr.Code
}