First real code for hanzoai/metrics — the prometheus-free replacement for the
vendored Grafana/Prometheus observability backends. In-memory time-series store
(Append/Query, bounded per-series retention) that ingests luxfi/metric.MetricBatch
(the ZAP MsgMetricBatch wire shape) and mounts into the hanzo cloud unified binary
via cloud.Register("metrics", 40, …), serving /v1/metrics/{health,batch,write,query}.
Zero prometheus, zero /api/ paths. Durable per-tenant backend can replace the
in-memory map behind the same Store API.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1020 B
Go
34 lines
1020 B
Go
package metrics
|
|
|
|
import metric "github.com/luxfi/metric"
|
|
|
|
// IngestBatch writes every sample in a luxfi/metric.MetricBatch into the store.
|
|
// This is the exact wire type the ZAP MsgMetricBatch transport carries, so the
|
|
// same code path serves both the HTTP /v1/metrics/batch endpoint and a future
|
|
// ZAP receiver. Counter/gauge values land directly; histogram/summary families
|
|
// contribute derived <name>_sum and <name>_count series. Returns samples written.
|
|
func (s *Store) IngestBatch(b *metric.MetricBatch) int {
|
|
if b == nil {
|
|
return 0
|
|
}
|
|
ts := b.TimestampNs
|
|
n := 0
|
|
for _, fam := range b.Families {
|
|
for _, m := range fam.Metrics {
|
|
if m.Value != nil {
|
|
s.Append(fam.Name, m.Labels, Sample{TsNs: ts, Value: *m.Value})
|
|
n++
|
|
}
|
|
if m.SampleSum != nil {
|
|
s.Append(fam.Name+"_sum", m.Labels, Sample{TsNs: ts, Value: *m.SampleSum})
|
|
n++
|
|
}
|
|
if m.SampleCount != nil {
|
|
s.Append(fam.Name+"_count", m.Labels, Sample{TsNs: ts, Value: float64(*m.SampleCount)})
|
|
n++
|
|
}
|
|
}
|
|
}
|
|
return n
|
|
}
|