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)) }