From 2f6b03f3dabceab3bff6324c028d4124ed20c89f Mon Sep 17 00:00:00 2001 From: deepthi Date: Tue, 26 Jan 2021 18:55:56 -0800 Subject: [PATCH 1/2] Add 1 to statsTabletTypeCounts during startup Signed-off-by: deepthi --- go/vt/vttablet/tabletmanager/tm_init.go | 1 + go/vt/vttablet/tabletmanager/tm_init_test.go | 2 ++ go/vt/vttablet/tabletmanager/tm_state_test.go | 7 +++++++ 3 files changed, 10 insertions(+) diff --git a/go/vt/vttablet/tabletmanager/tm_init.go b/go/vt/vttablet/tabletmanager/tm_init.go index 6c9734b3ffb..d91d48990e3 100644 --- a/go/vt/vttablet/tabletmanager/tm_init.go +++ b/go/vt/vttablet/tabletmanager/tm_init.go @@ -637,6 +637,7 @@ func (tm *TabletManager) exportStats() { statsKeyspace.Set(tablet.Keyspace) statsShard.Set(tablet.Shard) statsTabletType.Set(topoproto.TabletTypeLString(tm.tmState.tablet.Type)) + statsTabletTypeCount.Add(topoproto.TabletTypeLString(tm.tmState.tablet.Type), 1) if key.KeyRangeIsPartial(tablet.KeyRange) { statsKeyRangeStart.Set(hex.EncodeToString(tablet.KeyRange.Start)) statsKeyRangeEnd.Set(hex.EncodeToString(tablet.KeyRange.End)) diff --git a/go/vt/vttablet/tabletmanager/tm_init_test.go b/go/vt/vttablet/tabletmanager/tm_init_test.go index b7589e72bd0..0875a5f743d 100644 --- a/go/vt/vttablet/tabletmanager/tm_init_test.go +++ b/go/vt/vttablet/tabletmanager/tm_init_test.go @@ -127,6 +127,8 @@ func TestStartCreateKeyspaceShard(t *testing.T) { defer tm.Stop() assert.Equal(t, "replica", statsTabletType.Get()) + assert.Equal(t, 1, len(statsTabletTypeCount.Counts())) + assert.Equal(t, int64(1), statsTabletTypeCount.Counts()["replica"]) _, err := ts.GetShard(ctx, "ks", "0") require.NoError(t, err) diff --git a/go/vt/vttablet/tabletmanager/tm_state_test.go b/go/vt/vttablet/tabletmanager/tm_state_test.go index c61b120519f..2051274391f 100644 --- a/go/vt/vttablet/tabletmanager/tm_state_test.go +++ b/go/vt/vttablet/tabletmanager/tm_state_test.go @@ -173,6 +173,9 @@ func TestStateChangeTabletType(t *testing.T) { tm := newTestTM(t, ts, 2, "ks", "0") defer tm.Stop() + assert.Equal(t, 1, len(statsTabletTypeCount.Counts())) + assert.Equal(t, int64(1), statsTabletTypeCount.Counts()["replica"]) + alias := &topodatapb.TabletAlias{ Cell: "cell1", Uid: 2, @@ -185,6 +188,8 @@ func TestStateChangeTabletType(t *testing.T) { assert.Equal(t, topodatapb.TabletType_MASTER, ti.Type) assert.NotNil(t, ti.MasterTermStartTime) assert.Equal(t, "master", statsTabletType.Get()) + assert.Equal(t, 2, len(statsTabletTypeCount.Counts())) + assert.Equal(t, int64(1), statsTabletTypeCount.Counts()["master"]) err = tm.tmState.ChangeTabletType(ctx, topodatapb.TabletType_REPLICA, DBActionNone) require.NoError(t, err) @@ -193,6 +198,8 @@ func TestStateChangeTabletType(t *testing.T) { assert.Equal(t, topodatapb.TabletType_REPLICA, ti.Type) assert.Nil(t, ti.MasterTermStartTime) assert.Equal(t, "replica", statsTabletType.Get()) + assert.Equal(t, 2, len(statsTabletTypeCount.Counts())) + assert.Equal(t, int64(2), statsTabletTypeCount.Counts()["replica"]) } func TestPublishStateNew(t *testing.T) { From 63f15b7b09a9d857d0e8f596c430cd8863291ae1 Mon Sep 17 00:00:00 2001 From: deepthi Date: Tue, 26 Jan 2021 19:08:52 -0800 Subject: [PATCH 2/2] reset counters in unit test Signed-off-by: deepthi --- go/vt/vttablet/tabletmanager/tm_state_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/vt/vttablet/tabletmanager/tm_state_test.go b/go/vt/vttablet/tabletmanager/tm_state_test.go index 2051274391f..dcf586f2d4b 100644 --- a/go/vt/vttablet/tabletmanager/tm_state_test.go +++ b/go/vt/vttablet/tabletmanager/tm_state_test.go @@ -170,6 +170,7 @@ func TestStateNonServing(t *testing.T) { func TestStateChangeTabletType(t *testing.T) { ctx := context.Background() ts := memorytopo.NewServer("cell1") + statsTabletTypeCount.ResetAll() tm := newTestTM(t, ts, 2, "ks", "0") defer tm.Stop()