mirror of
https://github.com/status-im/consul.git
synced 2025-01-25 13:10:32 +00:00
test: TestServer_RPC_MetricsIntercept should use a concurrency-safe metrics store (#13157)
This commit is contained in:
parent
8513566872
commit
c27e186334
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -1167,7 +1168,7 @@ func TestServer_RPC_MetricsIntercept_Off(t *testing.T) {
|
|||||||
t.Skip("too slow for testing.Short")
|
t.Skip("too slow for testing.Short")
|
||||||
}
|
}
|
||||||
|
|
||||||
storage := make(map[string]float32)
|
storage := &sync.Map{} // string -> float32
|
||||||
keyMakingFunc := func(key []string, labels []metrics.Label) string {
|
keyMakingFunc := func(key []string, labels []metrics.Label) string {
|
||||||
allKey := strings.Join(key, "+")
|
allKey := strings.Join(key, "+")
|
||||||
|
|
||||||
@ -1181,7 +1182,7 @@ func TestServer_RPC_MetricsIntercept_Off(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
simpleRecorderFunc := func(key []string, val float32, labels []metrics.Label) {
|
simpleRecorderFunc := func(key []string, val float32, labels []metrics.Label) {
|
||||||
storage[keyMakingFunc(key, labels)] = val
|
storage.Store(keyMakingFunc(key, labels), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("test no net/rpc interceptor metric with nil func", func(t *testing.T) {
|
t.Run("test no net/rpc interceptor metric with nil func", func(t *testing.T) {
|
||||||
@ -1215,7 +1216,7 @@ func TestServer_RPC_MetricsIntercept_Off(t *testing.T) {
|
|||||||
|
|
||||||
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, []metrics.Label{{Name: "method", Value: "Status.Ping"}})
|
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, []metrics.Label{{Name: "method", Value: "Status.Ping"}})
|
||||||
|
|
||||||
if _, ok := storage[key]; ok {
|
if _, ok := storage.Load(key); ok {
|
||||||
t.Fatalf("Did not expect to find key %s in the metrics log, ", key)
|
t.Fatalf("Did not expect to find key %s in the metrics log, ", key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1256,7 +1257,7 @@ func TestServer_RPC_MetricsIntercept_Off(t *testing.T) {
|
|||||||
|
|
||||||
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, []metrics.Label{{Name: "method", Value: "Status.Ping"}})
|
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, []metrics.Label{{Name: "method", Value: "Status.Ping"}})
|
||||||
|
|
||||||
if _, ok := storage[key]; ok {
|
if _, ok := storage.Load(key); ok {
|
||||||
t.Fatalf("Did not expect to find key %s in the metrics log, ", key)
|
t.Fatalf("Did not expect to find key %s in the metrics log, ", key)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -1316,9 +1317,8 @@ func TestServer_RPC_MetricsIntercept(t *testing.T) {
|
|||||||
deps := newDefaultDeps(t, conf)
|
deps := newDefaultDeps(t, conf)
|
||||||
|
|
||||||
// The method used to record metric observations here is similar to that used in
|
// The method used to record metric observations here is similar to that used in
|
||||||
// interceptors_test.go; at present, we don't have a need to lock yet but if we do
|
// interceptors_test.go.
|
||||||
// we can imitate that set up further or just factor it out as a "mock" metrics backend
|
storage := &sync.Map{} // string -> float32
|
||||||
storage := make(map[string]float32)
|
|
||||||
keyMakingFunc := func(key []string, labels []metrics.Label) string {
|
keyMakingFunc := func(key []string, labels []metrics.Label) string {
|
||||||
allKey := strings.Join(key, "+")
|
allKey := strings.Join(key, "+")
|
||||||
|
|
||||||
@ -1330,7 +1330,7 @@ func TestServer_RPC_MetricsIntercept(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
simpleRecorderFunc := func(key []string, val float32, labels []metrics.Label) {
|
simpleRecorderFunc := func(key []string, val float32, labels []metrics.Label) {
|
||||||
storage[keyMakingFunc(key, labels)] = val
|
storage.Store(keyMakingFunc(key, labels), val)
|
||||||
}
|
}
|
||||||
deps.NewRequestRecorderFunc = func(logger hclog.Logger, isLeader func() bool, localDC string) *middleware.RequestRecorder {
|
deps.NewRequestRecorderFunc = func(logger hclog.Logger, isLeader func() bool, localDC string) *middleware.RequestRecorder {
|
||||||
// for the purposes of this test, we don't need isLeader or localDC
|
// for the purposes of this test, we don't need isLeader or localDC
|
||||||
@ -1374,7 +1374,7 @@ func TestServer_RPC_MetricsIntercept(t *testing.T) {
|
|||||||
|
|
||||||
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, expectedLabels)
|
key := keyMakingFunc(middleware.OneTwelveRPCSummary[0].Name, expectedLabels)
|
||||||
|
|
||||||
if _, ok := storage[key]; !ok {
|
if _, ok := storage.Load(key); !ok {
|
||||||
// the compound key will look like: "rpc+server+call+Status.Ping+false+read+test+unreported"
|
// the compound key will look like: "rpc+server+call+Status.Ping+false+read+test+unreported"
|
||||||
t.Fatalf("Did not find key %s in the metrics log, ", key)
|
t.Fatalf("Did not find key %s in the metrics log, ", key)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user