fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

merging: add metrics for shard count and janitor jobs (#232)

This change gives us real time metrics for shard count, vacuuming and merging.

Co-authored-by: geoffrey@sourcegraph.com

author
Stefan Hengl
committer
GitHub
date (Dec 21, 2021, 10:40 AM +0100) commit af2e6058 parent 8a5ada5f
+42
+14
cmd/zoekt-sourcegraph-indexserver/cleanup.go
··· 273 273 } 274 274 } 275 275 276 + var metricVacuumRunning = promauto.NewGauge(prometheus.GaugeOpts{ 277 + Name: "index_vacuum_running", 278 + Help: "Set to 1 if indexserver's vacuum job is running.", 279 + }) 280 + 281 + var metricNumberCompoundShards = promauto.NewGauge(prometheus.GaugeOpts{ 282 + Name: "index_number_compound_shards", 283 + Help: "The number of compound shards.", 284 + }) 285 + 276 286 // vacuum removes tombstoned repos from compound shards and removes compound 277 287 // shards if they shrink below minSizeBytes. Vacuum locks the index directory for 278 288 // each compound shard it vacuums. 279 289 func (s *Server) vacuum() { 290 + metricVacuumRunning.Set(1) 291 + defer metricVacuumRunning.Set(0) 292 + 280 293 d, err := os.Open(s.IndexDir) 281 294 if err != nil { 282 295 return ··· 307 320 s.muIndexDir.Lock() 308 321 for _, p := range paths { 309 322 os.Remove(p) 323 + metricNumberCompoundShards.Dec() 310 324 } 311 325 s.muIndexDir.Unlock() 312 326 shardsLog(s.IndexDir, "delete", []shard{{Path: path}})
+10
cmd/zoekt-sourcegraph-indexserver/main.go
··· 673 673 return i 674 674 } 675 675 676 + func initializeCompoundShardCounter(indexDir string) { 677 + fns, err := filepath.Glob(filepath.Join(indexDir, "compound-*.zoekt")) 678 + if err != nil { 679 + log.Printf("initializeCompoundShardCounter: %s\n", err) 680 + return 681 + } 682 + metricNumberCompoundShards.Set(float64(len(fns))) 683 + } 684 + 676 685 func main() { 677 686 defaultIndexDir := os.Getenv("DATA_DIR") 678 687 if defaultIndexDir == "" { ··· 835 844 } 836 845 837 846 initializeGoogleCloudProfiler() 847 + initializeCompoundShardCounter(s.IndexDir) 838 848 839 849 if *listen != "" { 840 850 go func() {
+18
cmd/zoekt-sourcegraph-indexserver/merge.go
··· 12 12 "time" 13 13 14 14 "github.com/google/zoekt" 15 + "github.com/prometheus/client_golang/prometheus" 16 + "github.com/prometheus/client_golang/prometheus/promauto" 15 17 "gopkg.in/natefinch/lumberjack.v2" 16 18 ) 17 19 18 20 var reCompound = regexp.MustCompile(`compound-.*\.zoekt`) 19 21 22 + var metricShardMergingRunning = promauto.NewGauge(prometheus.GaugeOpts{ 23 + Name: "index_shard_merging_running", 24 + Help: "Set to 1 if indexserver's merge job is running.", 25 + }) 26 + 27 + var metricShardMergingDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ 28 + Name: "index_shard_merging_duration_seconds", 29 + Help: "The duration of 1 shard merge operation.", 30 + Buckets: prometheus.LinearBuckets(30, 30, 10), 31 + }, []string{"error"}) 32 + 20 33 // doMerge drives the merge process. 21 34 func doMerge(dir string, targetSizeBytes, maxSizeBytes int64, simulate bool) error { 35 + metricShardMergingRunning.Set(1) 36 + defer metricShardMergingRunning.Set(0) 22 37 23 38 wc := &lumberjack.Logger{ 24 39 Filename: filepath.Join(dir, "zoekt-merge-log.tsv"), ··· 47 62 for ix, comp := range compounds { 48 63 debug.Printf("compound %d: merging %d shards with total size %.2f MiB\n", ix, len(comp.shards), float64(comp.size)/(1024*1024)) 49 64 if !simulate { 65 + start := time.Now() 50 66 stdOut, stdErr, err := callMerge(comp.shards) 67 + metricShardMergingDuration.WithLabelValues(strconv.FormatBool(err != nil)).Observe(time.Since(start).Seconds()) 51 68 debug.Printf("callMerge: OUT: %s, ERR: %s\n", string(stdOut), string(stdErr)) 52 69 if err != nil { 53 70 debug.Printf("error during merging compound %d, stdErr: %s, err: %s\n", ix, stdErr, err) 54 71 continue 55 72 } 73 + metricNumberCompoundShards.Inc() 56 74 // for len(comp.shards)<=1, callMerge is a NOP. Hence there is no need to log 57 75 // anything here. 58 76 if len(comp.shards) > 1 {