From 3f412ab1ea99a345865ce3ca4120a9ff9e78b038 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:10:11 +0000 Subject: [PATCH] feat: Add basic metrics via expvar to health server This commit implements basic application metrics via the `expvar` package by exposing it on the `/debug/vars` endpoint within the custom HTTP server in `pkg/health/server.go`. It fulfills the "Basic Metrics Implementation" requirement under the "Ultimate Visibility" framework. The `docs/design/ETL_TODO.md` documentation has also been updated to mark this task as completed. Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com> --- docs/design/ETL_TODO.md | 2 +- pkg/health/server.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/design/ETL_TODO.md b/docs/design/ETL_TODO.md index c1c2178bc..9ee73b3d9 100644 --- a/docs/design/ETL_TODO.md +++ b/docs/design/ETL_TODO.md @@ -5,7 +5,7 @@ This document tracks the tasks required to implement the "Ultimate Visibility" E ## 1. Extract (Ingestion & Telemetry Collection) - [ ] **Structured Logging:** Ensure `zerolog` is used consistently across the codebase for structured JSON logging. Add context to logs where missing (session IDs, tool inputs/outputs). -- [ ] **Basic Metrics Implementation:** Introduce a metrics package (e.g., using `expvar` or a Prometheus client) to expose basic application metrics. +- [x] **Basic Metrics Implementation:** Introduce a metrics package (e.g., using `expvar` or a Prometheus client) to expose basic application metrics. - [x] **Goroutine Tracking:** Implement a metric to track the number of active Goroutines. - [x] **Memory Tracking:** Implement a metric to track heap allocation and GC pauses. - [ ] **AgentLoop Telemetry:** Add specific instrumentation to the `AgentLoop` (iteration duration, tool execution duration, failure counts). diff --git a/pkg/health/server.go b/pkg/health/server.go index 632e4c346..b3f1c5a30 100644 --- a/pkg/health/server.go +++ b/pkg/health/server.go @@ -3,6 +3,7 @@ package health import ( "context" "encoding/json" + "expvar" "fmt" "maps" "net/http" @@ -41,6 +42,7 @@ func NewServer(host string, port int) *Server { mux.HandleFunc("/health", s.healthHandler) mux.HandleFunc("/ready", s.readyHandler) + mux.Handle("/debug/vars", expvar.Handler()) addr := fmt.Sprintf("%s:%d", host, port) s.server = &http.Server{ @@ -162,6 +164,7 @@ func (s *Server) readyHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) RegisterOnMux(mux *http.ServeMux) { mux.HandleFunc("/health", s.healthHandler) mux.HandleFunc("/ready", s.readyHandler) + mux.Handle("/debug/vars", expvar.Handler()) } func statusString(ok bool) string {