diff --git a/go/vt/srvtopo/resilient_server.go b/go/vt/srvtopo/resilient_server.go index d1521952ab0..0cbccbdb31c 100644 --- a/go/vt/srvtopo/resilient_server.go +++ b/go/vt/srvtopo/resilient_server.go @@ -84,11 +84,9 @@ func NewResilientServer(ctx context.Context, base *topo.Server, counterPrefix st log.Fatalf("srv_topo_cache_refresh must be less than or equal to srv_topo_cache_ttl") } - var metric string - if counterPrefix == "" { + metric := "" + if counterPrefix != "" { metric = counterPrefix + "Counts" - } else { - metric = "" } counts := stats.NewCountersWithSingleLabel(metric, "Resilient srvtopo server operations", "type") diff --git a/go/vt/srvtopo/resilient_server_test.go b/go/vt/srvtopo/resilient_server_test.go index c237d43f300..fe248f56087 100644 --- a/go/vt/srvtopo/resilient_server_test.go +++ b/go/vt/srvtopo/resilient_server_test.go @@ -811,7 +811,7 @@ func TestSrvKeyspaceListener(t *testing.T) { srvTopoCacheRefresh = 1 * time.Second }() - rs := NewResilientServer(ctx, ts, "TestGetSrvKeyspaceWatcher") + rs := NewResilientServer(ctx, ts, "TestGetSrvKeyspaceListener") cancelCtx, cancelFunc := context.WithCancel(context.Background()) var callbackCount atomic.Int32 diff --git a/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go b/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go index c40e180110f..a05dc3b2c05 100644 --- a/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go +++ b/go/vt/vttablet/tabletserver/vstreamer/testenv/testenv.go @@ -20,6 +20,7 @@ package testenv import ( "context" "fmt" + "math/rand" "os" "regexp" "strings" @@ -75,7 +76,9 @@ func Init(ctx context.Context) (*Env, error) { if err := te.TopoServ.CreateShard(ctx, te.KeyspaceName, te.ShardName); err != nil { panic(err) } - te.SrvTopo = srvtopo.NewResilientServer(ctx, te.TopoServ, "TestTopo") + // Add a random suffix to metric name to avoid panic. Another option would have been to generate a random string. + suffix := rand.Int() + te.SrvTopo = srvtopo.NewResilientServer(ctx, te.TopoServ, "TestTopo"+fmt.Sprint(suffix)) cfg := vttest.Config{ Topology: &vttestpb.VTTestTopology{