mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
re-implement prometheus metrics endpoint to be simpler (#13922)
data-structures were repeatedly initialized this causes GC pressure, instead re-use the collectors. Initialize collectors in `init()`, also make sure to honor the cache semantics for performance requirements. Avoid a global map and a global lock for metrics lookup instead let them all be lock-free unless the cache is being invalidated.
This commit is contained in:
parent
890f43ffa5
commit
818f0201fc
1497
cmd/metrics-v2.go
1497
cmd/metrics-v2.go
File diff suppressed because it is too large
Load Diff
@ -1113,7 +1113,7 @@ func (s *peerRESTServer) GetPeerMetrics(w http.ResponseWriter, r *http.Request)
|
|||||||
|
|
||||||
enc := gob.NewEncoder(w)
|
enc := gob.NewEncoder(w)
|
||||||
|
|
||||||
ch := ReportMetrics(r.Context(), GetGeneratorsForPeer)
|
ch := ReportMetrics(r.Context(), peerMetricsGroups)
|
||||||
for m := range ch {
|
for m := range ch {
|
||||||
if err := enc.Encode(m); err != nil {
|
if err := enc.Encode(m); err != nil {
|
||||||
s.writeErrorResponse(w, errors.New("Encoding metric failed: "+err.Error()))
|
s.writeErrorResponse(w, errors.New("Encoding metric failed: "+err.Error()))
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests maximum object size.
|
// Tests maximum object size.
|
||||||
@ -486,3 +487,32 @@ func TestGetMinioMode(t *testing.T) {
|
|||||||
testMinioMode(globalMinioModeGatewayPrefix + globalGatewayName)
|
testMinioMode(globalMinioModeGatewayPrefix + globalGatewayName)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTimedValue(t *testing.T) {
|
||||||
|
var cache timedValue
|
||||||
|
t.Parallel()
|
||||||
|
cache.Once.Do(func() {
|
||||||
|
cache.TTL = 2 * time.Second
|
||||||
|
cache.Update = func() (interface{}, error) {
|
||||||
|
return time.Now(), nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
i, _ := cache.Get()
|
||||||
|
t1 := i.(time.Time)
|
||||||
|
|
||||||
|
j, _ := cache.Get()
|
||||||
|
t2 := j.(time.Time)
|
||||||
|
|
||||||
|
if !t1.Equal(t2) {
|
||||||
|
t.Fatalf("expected time to be equal: %s != %s", t1, t2)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
k, _ := cache.Get()
|
||||||
|
t3 := k.(time.Time)
|
||||||
|
|
||||||
|
if t1.Equal(t3) {
|
||||||
|
t.Fatalf("expected time to be un-equal: %s == %s", t1, t3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user