Skip to content

Commit 02efb1c

Browse files
vtorc: add tablets watched stats
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
1 parent 5f80483 commit 02efb1c

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

go/vt/vtorc/logic/tablet_discovery.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"google.golang.org/protobuf/encoding/prototext"
3232
"google.golang.org/protobuf/proto"
3333

34+
"vitess.io/vitess/go/stats"
3435
"vitess.io/vitess/go/vt/external/golib/sqlutils"
3536
"vitess.io/vitess/go/vt/key"
3637
"vitess.io/vitess/go/vt/log"
@@ -53,6 +54,20 @@ var (
5354
// We store the key range for all the shards that we want to watch.
5455
// This is populated by parsing `--clusters_to_watch` flag.
5556
shardsToWatch map[string][]*topodatapb.KeyRange
57+
statsMu sync.Mutex
58+
59+
// tabletsWatchedByCell is a map of the number of tablets watched by cell.
60+
tabletsWatchedByCell map[string]int64
61+
statsTabletsWatched = stats.NewGaugesFuncWithMultiLabels(
62+
"TabletsWatched",
63+
"Number of tablets watched by cell",
64+
[]string{"cell"},
65+
func() map[string]int64 {
66+
statsMu.Lock()
67+
defer statsMu.Unlock()
68+
return tabletsWatchedByCell
69+
},
70+
)
5671

5772
// ErrNoPrimaryTablet is a fixed error message.
5873
ErrNoPrimaryTablet = errors.New("no primary tablet found")
@@ -207,6 +222,7 @@ func refreshTabletsUsing(ctx context.Context, loader func(tabletAlias string), f
207222

208223
// Update each cell that provided a response. This ensures only cells that provided a
209224
// response are updated in the backend and are considered for forgetting stale tablets.
225+
newTabletsWatchedByCell := make(map[string]int64)
210226
for cell, tablets := range tabletsByCell {
211227
// Filter tablets that should not be watched using func shouldWatchTablet.
212228
matchedTablets := make([]*topo.TabletInfo, 0, len(tablets))
@@ -222,8 +238,13 @@ func refreshTabletsUsing(ctx context.Context, loader func(tabletAlias string), f
222238
query := "select alias from vitess_tablet where cell = ?"
223239
args := sqlutils.Args(cell)
224240
refreshTablets(matchedTablets, query, args, loader, forceRefresh, nil)
241+
newTabletsWatchedByCell[cell] = int64(len(matchedTablets))
225242
}
226243

244+
statsMu.Lock()
245+
defer statsMu.Unlock()
246+
tabletsWatchedByCell = newTabletsWatchedByCell
247+
227248
return nil
228249
}
229250

0 commit comments

Comments
 (0)