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

Configure Feed

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

all: remove detailed debug file logging (#707)

We have noticed profiles where lumberjack is responsible for 1GB of
memory. This is surprising and we haven't used the log output in a long
time. Rather than debugging, we are going to remove it for now and when
we need detailed logs again we can add something back.

Test Plan: go test

+5 -82
+1 -25
build/builder.go
··· 39 39 "github.com/bmatcuk/doublestar" 40 40 "github.com/grafana/regexp" 41 41 "github.com/rs/xid" 42 - "gopkg.in/natefinch/lumberjack.v2" 43 42 44 43 "github.com/sourcegraph/zoekt" 45 44 "github.com/sourcegraph/zoekt/ctags" ··· 250 249 size int 251 250 252 251 parserFactory ctags.ParserFactory 253 - building sync.WaitGroup 252 + building sync.WaitGroup 254 253 255 254 errMu sync.Mutex 256 255 buildError error ··· 258 257 // temp name => final name for finished shards. We only rename 259 258 // them once all shards succeed to avoid Frankstein corpuses. 260 259 finishedShards map[string]string 261 - 262 - shardLogger io.WriteCloser 263 260 264 261 // indexTime is set by tests for doing reproducible builds. 265 262 indexTime time.Time ··· 575 572 576 573 b.parserFactory = parserFactory 577 574 578 - b.shardLogger = &lumberjack.Logger{ 579 - Filename: filepath.Join(opts.IndexDir, "zoekt-builder-shard-log.tsv"), 580 - MaxSize: 100, // Megabyte 581 - MaxBackups: 5, 582 - } 583 - 584 575 if opts.IsDelta { 585 576 // Delta shards build on top of previously existing shards. 586 577 // As a consequence, the shardNum for delta shards starts from ··· 746 737 if len(artifactPaths) == 0 { 747 738 return b.buildError 748 739 } 749 - 750 - defer b.shardLogger.Close() 751 740 752 741 // Collect a map of the old shards on disk. For each new shard we replace we 753 742 // delete it from toDelete. Anything remaining in toDelete will be removed ··· 779 768 } 780 769 781 770 delete(toDelete, final) 782 - 783 - b.shardLog("upsert", final, b.opts.RepositoryDescription.Name) 784 771 } 785 772 786 773 b.finishedShards = map[string]string{} ··· 791 778 if !strings.HasSuffix(p, ".zoekt") { 792 779 continue 793 780 } 794 - b.shardLog("tomb", p, b.opts.RepositoryDescription.Name) 795 781 err := zoekt.SetTombstone(p, b.opts.RepositoryDescription.ID) 796 782 b.buildError = err 797 783 continue 798 784 } 799 785 log.Printf("removing old shard file: %s", p) 800 - b.shardLog("remove", p, b.opts.RepositoryDescription.Name) 801 786 if err := os.Remove(p); err != nil { 802 787 b.buildError = err 803 788 } ··· 876 861 } 877 862 878 863 return nil 879 - } 880 - 881 - func (b *Builder) shardLog(action, shard string, repoName string) { 882 - shard = filepath.Base(shard) 883 - var shardSize int64 884 - if fi, err := os.Stat(filepath.Join(b.opts.IndexDir, shard)); err == nil { 885 - shardSize = fi.Size() 886 - } 887 - _, _ = fmt.Fprintf(b.shardLogger, "%s\t%s\t%s\t%d\t%s\n", time.Now().UTC().Format(time.RFC3339), action, shard, shardSize, repoName) 888 864 } 889 865 890 866 var profileNumber int
+4 -40
cmd/zoekt-sourcegraph-indexserver/cleanup.go
··· 13 13 "github.com/grafana/regexp" 14 14 "github.com/prometheus/client_golang/prometheus" 15 15 "github.com/prometheus/client_golang/prometheus/promauto" 16 - "gopkg.in/natefinch/lumberjack.v2" 17 16 18 17 "github.com/sourcegraph/zoekt" 19 18 ) ··· 97 96 simple := shards[:0] 98 97 for _, s := range shards { 99 98 if shardMerging && maybeSetTombstone([]shard{s}, repo) { 100 - shardsLog(indexDir, "tombname", []shard{s}) 101 - } else { 102 - simple = append(simple, s) 99 + continue 103 100 } 101 + 102 + simple = append(simple, s) 104 103 } 105 104 106 105 if len(simple) == 0 { ··· 108 107 } 109 108 110 109 removeAll(simple...) 111 - shardsLog(indexDir, "removename", simple) 112 110 } 113 111 114 112 // index: Move missing repos from trash into index ··· 121 119 if shards, ok := trash[repo]; ok { 122 120 log.Printf("restoring shards from trash for %v", repo) 123 121 moveAll(indexDir, shards) 124 - shardsLog(indexDir, "restore", shards) 125 122 continue 126 123 } 127 124 ··· 130 127 err := zoekt.UnsetTombstone(s.Path, repo) 131 128 if err != nil { 132 129 log.Printf("error removing tombstone for %v: %s", repo, err) 133 - } else { 134 - shardsLog(indexDir, "untomb", []shard{s}) 135 130 } 136 131 } 137 132 } ··· 145 140 } 146 141 147 142 if shardMerging && maybeSetTombstone(shards, repo) { 148 - shardsLog(indexDir, "tomb", shards) 149 143 continue 150 144 } 151 145 moveAll(trashDir, shards) 152 - shardsLog(indexDir, "remove", shards) 153 146 } 154 147 155 148 // Remove .tmp files from crashed indexer runs-- for example, if an indexer ··· 382 375 return true 383 376 } 384 377 385 - func shardsLog(indexDir, action string, shards []shard) { 386 - shardLogger := &lumberjack.Logger{ 387 - Filename: filepath.Join(indexDir, "zoekt-indexserver-shard-log.tsv"), 388 - MaxSize: 100, // Megabyte 389 - MaxBackups: 5, 390 - } 391 - defer shardLogger.Close() 392 - 393 - for _, s := range shards { 394 - shardName := filepath.Base(s.Path) 395 - var shardSize int64 396 - if fi, err := os.Stat(filepath.Join(indexDir, shardName)); err == nil { 397 - shardSize = fi.Size() 398 - } 399 - _, _ = fmt.Fprintf(shardLogger, "%s\t%s\t%s\t%d\t%s\t%d\n", time.Now().UTC().Format(time.RFC3339), action, shardName, shardSize, s.RepoName, s.RepoID) 400 - } 401 - } 402 - 403 378 var metricVacuumRunning = promauto.NewGauge(prometheus.GaugeOpts{ 404 379 Name: "index_vacuum_running", 405 380 Help: "Set to 1 if indexserver's vacuum job is running.", ··· 448 423 449 424 if err != nil { 450 425 debug.Printf("failed to explode compound shard %s: %s", path, string(b)) 451 - } else { 452 - shardsLog(s.IndexDir, "explode", []shard{{Path: path}}) 453 426 } 454 427 continue 455 428 } 456 429 457 - var removed []*zoekt.Repository 458 430 s.muIndexDir.Global(func() { 459 - removed, err = removeTombstones(path) 431 + _, err = removeTombstones(path) 460 432 }) 461 433 462 434 if err != nil { 463 435 debug.Printf("error while removing tombstones in %s: %s", fn, err) 464 - } 465 - for _, repo := range removed { 466 - shardsLog(s.IndexDir, "vac", []shard{{ 467 - RepoID: repo.ID, 468 - RepoName: repo.Name, 469 - Path: filepath.Join(s.IndexDir, fn), 470 - ModTime: info.ModTime(), 471 - }}) 472 436 } 473 437 } 474 438 }
-14
cmd/zoekt-sourcegraph-indexserver/merge.go
··· 1 1 package main 2 2 3 3 import ( 4 - "fmt" 5 4 "log" 6 5 "os" 7 6 "os/exec" ··· 13 12 "github.com/prometheus/client_golang/prometheus" 14 13 "github.com/prometheus/client_golang/prometheus/promauto" 15 14 "go.uber.org/atomic" 16 - "gopkg.in/natefinch/lumberjack.v2" 17 15 18 16 "github.com/sourcegraph/zoekt" 19 17 ) ··· 71 69 metricShardMergingRunning.Set(1) 72 70 defer metricShardMergingRunning.Set(0) 73 71 74 - wc := &lumberjack.Logger{ 75 - Filename: filepath.Join(s.IndexDir, "zoekt-merge-log.tsv"), 76 - MaxSize: 100, // Megabyte 77 - MaxBackups: 5, 78 - } 79 - 80 72 // We keep creating compound shards until we run out of shards to merge or until 81 73 // we encounter an error during merging. 82 74 next := true ··· 105 97 if err != nil { 106 98 log.Printf("mergeCmd: out=%s, err=%s", out, err) 107 99 return 108 - } 109 - 110 - newCompoundName := reCompound.Find(out) 111 - now := time.Now() 112 - for _, s := range c.shards { 113 - _, _ = fmt.Fprintf(wc, "%s\t%s\t%s\t%s\n", now.UTC().Format(time.RFC3339), "merge", filepath.Base(s.path), string(newCompoundName)) 114 100 } 115 101 116 102 next = true
-1
go.mod
··· 56 56 golang.org/x/sys v0.11.0 57 57 google.golang.org/grpc v1.56.1 58 58 google.golang.org/protobuf v1.31.0 59 - gopkg.in/natefinch/lumberjack.v2 v2.2.1 60 59 ) 61 60 62 61 require (
-2
go.sum
··· 558 558 gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 559 559 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 560 560 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= 561 - gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= 562 - gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= 563 561 gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= 564 562 gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= 565 563 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=