Skip to content

Commit

Permalink
Merge pull request #7390 from planetscale/ds-ttype-counts
Browse files Browse the repository at this point in the history
Add 1 to statsTabletTypeCounts during startup
  • Loading branch information
deepthi authored Jan 27, 2021
2 parents 9ccb97e + 63f15b7 commit 4fea10e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/vt/vttablet/tabletmanager/tm_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions go/vt/vttablet/tabletmanager/tm_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions go/vt/vttablet/tabletmanager/tm_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,13 @@ 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()

assert.Equal(t, 1, len(statsTabletTypeCount.Counts()))
assert.Equal(t, int64(1), statsTabletTypeCount.Counts()["replica"])

alias := &topodatapb.TabletAlias{
Cell: "cell1",
Uid: 2,
Expand All @@ -185,6 +189,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)
Expand All @@ -193,6 +199,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) {
Expand Down

0 comments on commit 4fea10e

Please sign in to comment.