package router import ( "net/http" "net/http/httptest" "strings" "testing" "github.com/prometheus/client_golang/prometheus" "gitea.mynodes.xyz/ilker/llmgw/internal/config" ) type constantCollector struct{ desc *prometheus.Desc } func (c constantCollector) Describe(ch chan<- *prometheus.Desc) { ch <- c.desc } func (c constantCollector) Collect(ch chan<- prometheus.Metric) { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, 1) } func TestARegisteredCollectorReachesTheMetricsEndpoint(t *testing.T) { // Registering after AdminHandler silently published nothing, because that // is where the registry is built. The fleet metrics were deployed and // absent, and only looking at the live endpoint showed it — a wiring // mistake that no type checks and nothing fails on. e := newFakeEngine(t, "m") rt := newTestRouter(t, baseConfig(config.Endpoint{ID: "a", URL: e.srv.URL, Models: []string{"m"}})) if err := rt.RegisterMetrics(constantCollector{ desc: prometheus.NewDesc("llmgw_test_collector", "proof it was registered", nil, nil), }); err != nil { t.Fatal(err) } mux, err := rt.AdminHandler() if err != nil { t.Fatal(err) } req := httptest.NewRequest(http.MethodGet, "/metrics", nil) rec := httptest.NewRecorder() mux.ServeHTTP(rec, req) if !strings.Contains(rec.Body.String(), "llmgw_test_collector") { t.Error("a registered collector did not reach /metrics") } }