Skip to content

Commit

Permalink
statistic: fix the issue of tombstone for label counter (#2060) (#2067)
Browse files Browse the repository at this point in the history
* statistic: fix the issue of tombstone for label counter

Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
sre-bot authored and nolouch committed Dec 31, 2019
1 parent 456c42b commit 330c108
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion server/statistics/store_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ func (s *storeStatistics) Observe(store *core.StoreInfo, stats *StoresStats) {
v = unknown
}
key := fmt.Sprintf("%s:%s", k, v)
s.LabelCounter[key]++
// exclude tombstone
if store.GetState() != metapb.StoreState_Tombstone {
s.LabelCounter[key]++
}
}
storeAddress := store.GetAddress()
id := strconv.FormatUint(store.GetID(), 10)
Expand Down Expand Up @@ -268,4 +271,5 @@ func (m *storeStatisticsMap) Collect() {
func (m *storeStatisticsMap) Reset() {
storeStatusGauge.Reset()
clusterStatusGauge.Reset()
placementStatusGauge.Reset()
}
3 changes: 2 additions & 1 deletion server/statistics/store_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (t *testStoreStatisticsSuite) TestStoreStatistics(c *C) {
{Id: 6, Address: "mock://tikv-6", Labels: []*metapb.StoreLabel{{Key: "zone", Value: "z3"}, {Key: "host", Value: "h2"}}},
{Id: 7, Address: "mock://tikv-7", Labels: []*metapb.StoreLabel{{Key: "host", Value: "h1"}}},
{Id: 8, Address: "mock://tikv-8", Labels: []*metapb.StoreLabel{{Key: "host", Value: "h2"}}},
{Id: 8, Address: "mock://tikv-9", Labels: []*metapb.StoreLabel{{Key: "host", Value: "h3"}}, State: metapb.StoreState_Tombstone},
}
storesStats := NewStoresStats()
var stores []*core.StoreInfo
Expand All @@ -65,7 +66,7 @@ func (t *testStoreStatisticsSuite) TestStoreStatistics(c *C) {
c.Assert(stats.RegionCount, Equals, 0)
c.Assert(stats.Unhealth, Equals, 0)
c.Assert(stats.Disconnect, Equals, 0)
c.Assert(stats.Tombstone, Equals, 0)
c.Assert(stats.Tombstone, Equals, 1)
c.Assert(stats.LowSpace, Equals, 8)
c.Assert(stats.LabelCounter["zone:z1"], Equals, 2)
c.Assert(stats.LabelCounter["zone:z2"], Equals, 2)
Expand Down

0 comments on commit 330c108

Please sign in to comment.