Skip to content

Commit

Permalink
Merge pull request #718 from undeadcat/bugfix-expired-metric-not-retu…
Browse files Browse the repository at this point in the history
…rned

fix #717: tile38_expired_keys and several other metrics not returned
  • Loading branch information
tidwall authored Feb 15, 2024
2 parents 9460314 + c78c8b4 commit a75ea88
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/server/expire.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (s *Server) backgroundExpireObjects(now time.Time) {
if nano < o.Expires() {
return false
}
s.statsExpired.Add(1)
msgs = append(msgs, &Message{Args: []string{"del", key, o.ID()}})
return true
})
Expand Down
36 changes: 29 additions & 7 deletions internal/server/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,7 @@ func (s *Server) Collect(ch chan<- prometheus.Metric) {
s.extStats(m)

for metric, descr := range metricDescriptions {
val, ok := m[metric].(float64)
if !ok {
val2, ok2 := m[metric].(int)
if ok2 {
val, ok = float64(val2), true
}
}
val, ok := toFloat(m[metric])
if ok {
ch <- prometheus.MustNewConstMetric(descr, prometheus.GaugeValue, val)
}
Expand Down Expand Up @@ -155,3 +149,31 @@ func (s *Server) Collect(ch chan<- prometheus.Metric) {
return true
})
}

func toFloat(val interface{}) (float64, bool) {
switch v := val.(type) {
case float64:
return v, true
case int64:
return float64(v), true
case uint64:
return float64(v), true
case float32:
return float64(v), true
case int:
return float64(v), true
case int32:
return float64(v), true
case uint32:
return float64(v), true
case int16:
return float64(v), true
case uint16:
return float64(v), true
case int8:
return float64(v), true
case uint8:
return float64(v), true
}
return 0, false
}

0 comments on commit a75ea88

Please sign in to comment.