Skip to content

Commit

Permalink
Add metric for total number of shards (#891)
Browse files Browse the repository at this point in the history
Currently, we only record the number of compound shards. This PR adds a metric
for the total number of index shards. This metric is helpful for alerting, as
it's important to catch a significant decrease in the number of indexed data.
  • Loading branch information
jtibshirani authored Jan 16, 2025
1 parent 27f6d0b commit 6875281
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions cmd/zoekt-sourcegraph-indexserver/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ var metricVacuumRunning = promauto.NewGauge(prometheus.GaugeOpts{
Help: "Set to 1 if indexserver's vacuum job is running.",
})

var metricNumberShards = promauto.NewGauge(prometheus.GaugeOpts{
Name: "index_number_shards",
Help: "The number of total shards.",
})

var metricNumberCompoundShards = promauto.NewGauge(prometheus.GaugeOpts{
Name: "index_number_compound_shards",
Help: "The number of compound shards.",
Expand Down
18 changes: 13 additions & 5 deletions cmd/zoekt-sourcegraph-indexserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func (s *Server) Run() {
missing := s.queue.Bump(repos.IDs)
s.Sourcegraph.ForceIterateIndexOptions(s.queue.AddOrUpdate, func(uint32, error) {}, missing...)

setCompoundShardCounter(s.IndexDir)
setShardsCounter(s.IndexDir)

<-cleanupDone
}
Expand Down Expand Up @@ -1208,12 +1208,20 @@ func joinStringSet(set map[string]struct{}, sep string) string {
return strings.Join(xs, sep)
}

func setCompoundShardCounter(indexDir string) {
fns, err := filepath.Glob(filepath.Join(indexDir, "compound-*.zoekt"))
func setShardsCounter(indexDir string) {
fns, err := filepath.Glob(filepath.Join(indexDir, "*.zoekt"))
if err != nil {
errorLog.Printf("setCompoundShardCounter: %s\n", err)
errorLog.Printf("setShardsCounter: %s\n", err)
return
}
metricNumberShards.Set(float64(len(fns)))

compoundFns := make([]string, 0, len(fns))
for _, fn := range fns {
if strings.HasPrefix(filepath.Base(fn), "compound-") {
compoundFns = append(compoundFns, fn)
}
}
metricNumberCompoundShards.Set(float64(len(fns)))
}

Expand Down Expand Up @@ -1288,7 +1296,7 @@ func startServer(conf rootConfig) error {
}

profiler.Init("zoekt-sourcegraph-indexserver")
setCompoundShardCounter(s.IndexDir)
setShardsCounter(s.IndexDir)

if conf.listen != "" {

Expand Down

0 comments on commit 6875281

Please sign in to comment.