Register the fleet collector before the registry is built
CI / test (push) Successful in 1m31s

42fd0aa deployed and published nothing. RegisterMetrics appends to a slice
that AdminHandler reads when it constructs the registry, and I called it
after — a comment on the function says "called before AdminHandler, because
the registry is built there", written by me, immediately above the code
that did not.

Nothing failed. The build was clean, the tests passed, the endpoint
returned 200 with fourteen kilobytes of metrics, and not one of them was a
node. Only grepping the live endpoint for what was supposed to be there
showed it.

So there is now a test that a registered collector reaches /metrics, which
is the assertion that was missing: everything around it was tested and the
wiring between them was not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-17 15:27:39 +02:00
1 parent 42fd0aa31e
commit 3a4cc0c719
2 files changed
+57 -7

No files matched your search

+11 -7
View File
@@ -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
+46
View File
@@ -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")
}
}