Files
sift/internal/metrics/batch.go
T
kyleandornith-1.5-35b-a3b e0168f7d65 metrics: sift_batch_* series (jobs, targets, depth, in-flight, durations, bytes)
New internal/metrics/batch.go adds the batch series to metrics.Set, registered
in New: BatchJobsTotal and BatchTargetsTotal counters (label "outcome", any
value outside the known set folded to "other" so a raw string never becomes a
label), BatchQueueDepth and BatchTargetsInflight gauges, BatchJobSeconds and
BatchTargetSeconds histograms (the existing request buckets) and
BatchResultBytes (1K,4K,16K,64K,256K,1M). The Observe…/Set… methods are
nil-receiver safe like ObservePDF and flow through the existing /metrics
handler; no new endpoint or Snapshot change.

Co-Authored-By: ornith-1.5-35b-a3b <ornith-1.5-35b-a3b@llama.cpp.invalid>
2026-09-26 22:21:59 -07:00

81 lines
2.1 KiB
Go

package metrics
import "time"
var batchResultBytesBuckets = []float64{1024, 4096, 16384, 65536, 262144, 1048576}
var batchJobOutcomes = map[string]struct{}{
"created": {}, "reused": {}, "done": {}, "partial": {},
"failed": {}, "cancelled": {}, "restart": {},
}
var batchTargetOutcomes = map[string]struct{}{
"ok": {}, "blocked": {}, "timeout": {}, "busy": {},
"upstream_4xx": {}, "upstream_5xx": {}, "unsupported": {},
"too_long": {}, "cancel": {},
}
// ObserveBatchJob records one batch outcome. Values outside the known set fold
// to "other" so a raw string never becomes a label.
func (s *Set) ObserveBatchJob(outcome string) {
if s == nil {
return
}
if _, ok := batchJobOutcomes[outcome]; !ok {
outcome = "other"
}
s.BatchJobsTotal.WithLabelValues(outcome).Inc()
}
// ObserveBatchTarget records one target outcome. Values outside the known set
// fold to "other" so a raw string never becomes a label.
func (s *Set) ObserveBatchTarget(outcome string) {
if s == nil {
return
}
if _, ok := batchTargetOutcomes[outcome]; !ok {
outcome = "other"
}
s.BatchTargetsTotal.WithLabelValues(outcome).Inc()
}
// SetBatchQueueDepth sets the live job count gauge (queued+running).
func (s *Set) SetBatchQueueDepth(n int) {
if s == nil {
return
}
s.BatchQueueDepth.Set(float64(n))
}
// SetBatchTargetsInflight sets the in-flight targets gauge.
func (s *Set) SetBatchTargetsInflight(n int) {
if s == nil {
return
}
s.BatchTargetsInflight.Set(float64(n))
}
// ObserveBatchJobSeconds records the wall time from submit to a batch's terminal status.
func (s *Set) ObserveBatchJobSeconds(d time.Duration) {
if s == nil {
return
}
s.BatchJobSeconds.Observe(d.Seconds())
}
// ObserveBatchTargetSeconds records the wall time for one target fetch.
func (s *Set) ObserveBatchTargetSeconds(d time.Duration) {
if s == nil {
return
}
s.BatchTargetSeconds.Observe(d.Seconds())
}
// ObserveBatchResultBytes records the stored byte count of one target result.
func (s *Set) ObserveBatchResultBytes(n int) {
if s == nil {
return
}
s.BatchResultBytes.Observe(float64(n))
}