diff --git a/internal/cli/server.go b/internal/cli/server.go index e076da7..6f6bfcb 100644 --- a/internal/cli/server.go +++ b/internal/cli/server.go @@ -112,6 +112,17 @@ func newServerCmd() *cobra.Command { admin = ctl agentPath, agentHandler = svc.Handler() + // Before AdminHandler, which is where the registry is built — + // registering after it silently publishes nothing, which is + // exactly what the first version of this did. + // + // On the same /metrics as the traffic figures: correlating + // "the cluster was full" with "requests were queueing" should + // not need two systems. + if err := rt.RegisterMetrics(fleetmetrics.New(ctl)); err != nil { + return err + } + log.Info("control plane running", "models", len(cfg.Models), "agent_listen", cfg.AgentListen, "agent_mtls", cfg.AgentTLS.Enabled()) @@ -122,13 +133,6 @@ func newServerCmd() *cobra.Command { return err } if admin != nil { - // What the cluster is made of, on the same /metrics as the - // traffic figures: correlating "the cluster was full" with - // "requests were queueing" should not need two systems. - if err := rt.RegisterMetrics(fleetmetrics.New(admin)); err != nil { - return err - } - api := adminapi.New(admin) // Catalog changes need somewhere to persist, so this is wired // only when there is a store. Without one, the endpoints say so diff --git a/internal/router/admin_test.go b/internal/router/admin_test.go new file mode 100644 index 0000000..99cc6e1 --- /dev/null +++ b/internal/router/admin_test.go @@ -0,0 +1,46 @@ +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") + } +}