mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
This allows deployments using our Prometheus export t determine the number of active users in the past hour. The interval is an hour to align with API key last used refresh times. SSH connections poll to check shutdown time, so this will be accurate even on long-running connections without dashboard requests.
32 lines
867 B
Go
32 lines
867 B
Go
package httpmw_test
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
chimw "github.com/go-chi/chi/v5/middleware"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/coderd/httpmw"
|
|
)
|
|
|
|
func TestPrometheus(t *testing.T) {
|
|
t.Parallel()
|
|
t.Run("All", func(t *testing.T) {
|
|
req := httptest.NewRequest("GET", "/", nil)
|
|
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, chi.NewRouteContext()))
|
|
res := chimw.NewWrapResponseWriter(httptest.NewRecorder(), 0)
|
|
reg := prometheus.NewRegistry()
|
|
httpmw.Prometheus(reg)(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
})).ServeHTTP(res, req)
|
|
metrics, err := reg.Gather()
|
|
require.NoError(t, err)
|
|
require.Greater(t, len(metrics), 0)
|
|
})
|
|
}
|