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

Configure Feed

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

shards: log a summary of shards in toLoad

We don't log every shard we load due to logspam on startup. However,
while zoekt-webserver is running it is useful to see more detailed
information since we are normally only loading a small number of shards
at a time.

This commit strikes a balance by only logging 5 of the shard names in
the list of shards to load.

Additionally for the unloading log line we only mention the base of the
path since it should always be in the indexdir.

Change-Id: I444a594cf5ea3359772b5f42651ee860b2a0fc1f

+42 -3
+20 -3
shards/watcher.go
··· 20 20 "os" 21 21 "path/filepath" 22 22 "runtime" 23 + "sort" 23 24 "strconv" 24 25 "strings" 25 26 "sync" ··· 160 161 } 161 162 162 163 if len(toDrop) > 0 { 163 - log.Printf("unloading %d shards", len(toDrop)) 164 + log.Printf("unloading %d shard(s)", len(toDrop)) 164 165 } 165 166 for _, t := range toDrop { 166 - log.Printf("unloading: %s", t) 167 + log.Printf("unloading: %s", filepath.Base(t)) 167 168 s.loader.drop(t) 168 169 } 169 170 ··· 171 172 return nil 172 173 } 173 174 174 - log.Printf("loading %d shards", len(toLoad)) 175 + log.Printf("loading %d shard(s): %s", len(toLoad), humanTruncateList(toLoad, 5)) 175 176 176 177 // Limit amount of concurrent shard loads. 177 178 throttle := make(chan struct{}, runtime.GOMAXPROCS(0)) ··· 194 195 } 195 196 196 197 return nil 198 + } 199 + 200 + func humanTruncateList(paths []string, max int) string { 201 + sort.Strings(paths) 202 + var b strings.Builder 203 + for i, p := range paths { 204 + if i >= max { 205 + fmt.Fprintf(&b, "... %d more", len(paths)-i) 206 + break 207 + } 208 + if i > 0 { 209 + b.WriteString(", ") 210 + } 211 + b.WriteString(filepath.Base(p)) 212 + } 213 + return b.String() 197 214 } 198 215 199 216 func (s *DirectoryWatcher) watch() error {
+22
shards/watcher_test.go
··· 218 218 default: 219 219 } 220 220 } 221 + 222 + func TestHumanTruncateList(t *testing.T) { 223 + paths := []string{ 224 + "dir/1", 225 + "dir/2", 226 + "dir/3", 227 + "dir/4", 228 + } 229 + 230 + assert := func(max int, want string) { 231 + got := humanTruncateList(paths, max) 232 + if got != want { 233 + t.Errorf("unexpected humanTruncateList max=%d.\ngot: %s\nwant: %s", max, got, want) 234 + } 235 + } 236 + 237 + assert(1, "1... 3 more") 238 + assert(2, "1, 2... 2 more") 239 + assert(3, "1, 2, 3... 1 more") 240 + assert(4, "1, 2, 3, 4") 241 + assert(5, "1, 2, 3, 4") 242 + }