Skip to content

Commit 29c1272

Browse files
aquarapiddeepthi
authored andcommitted
Fix vitessio#14414: resilient_server metrics name/prefix logic is inverted, leading to no metrics being recorded (vitessio#14415)
Signed-off-by: Jacques Grove <aquarapid@gmail.com> Signed-off-by: deepthi <deepthi@planetscale.com> Co-authored-by: deepthi <deepthi@planetscale.com>
1 parent fd04502 commit 29c1272

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

go/vt/srvtopo/resilient_server.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ func NewResilientServer(ctx context.Context, base *topo.Server, counterPrefix st
8484
log.Fatalf("srv_topo_cache_refresh must be less than or equal to srv_topo_cache_ttl")
8585
}
8686

87-
var metric string
88-
if counterPrefix == "" {
87+
metric := ""
88+
if counterPrefix != "" {
8989
metric = counterPrefix + "Counts"
90-
} else {
91-
metric = ""
9290
}
9391
counts := stats.NewCountersWithSingleLabel(metric, "Resilient srvtopo server operations", "type")
9492

go/vt/srvtopo/resilient_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ func TestSrvKeyspaceListener(t *testing.T) {
811811
srvTopoCacheRefresh = 1 * time.Second
812812
}()
813813

814-
rs := NewResilientServer(ctx, ts, "TestGetSrvKeyspaceWatcher")
814+
rs := NewResilientServer(ctx, ts, "TestGetSrvKeyspaceListener")
815815

816816
cancelCtx, cancelFunc := context.WithCancel(context.Background())
817817
var callbackCount atomic.Int32

go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package testenv
2020
import (
2121
"context"
2222
"fmt"
23+
"math/rand"
2324
"os"
2425
"regexp"
2526
"strings"
@@ -75,7 +76,9 @@ func Init(ctx context.Context) (*Env, error) {
7576
if err := te.TopoServ.CreateShard(ctx, te.KeyspaceName, te.ShardName); err != nil {
7677
panic(err)
7778
}
78-
te.SrvTopo = srvtopo.NewResilientServer(ctx, te.TopoServ, "TestTopo")
79+
// Add a random suffix to metric name to avoid panic. Another option would have been to generate a random string.
80+
suffix := rand.Int()
81+
te.SrvTopo = srvtopo.NewResilientServer(ctx, te.TopoServ, "TestTopo"+fmt.Sprint(suffix))
7982

8083
cfg := vttest.Config{
8184
Topology: &vttestpb.VTTestTopology{

0 commit comments

Comments
 (0)