@@ -254,15 +254,16 @@ func (c *CouchdbClient) getStats(config CollectorConfig) (Stats, error) {
254254 }
255255}
256256
257+ type dbStatsResult struct {
258+ dbName string
259+ dbStats DatabaseStats
260+ err error
261+ }
262+
257263func (c * CouchdbClient ) getDatabasesStatsByDbName (databases []string , concurrency uint ) (map [string ]DatabaseStats , error ) {
258264 dbStatsByDbName := make (map [string ]DatabaseStats )
259- type result struct {
260- dbName string
261- dbStats DatabaseStats
262- err error
263- }
264265 // Setup for concurrent scatter/gather scrapes, with concurrency limit
265- r := make (chan result , len (databases ))
266+ r := make (chan dbStatsResult , len (databases ))
266267 semaphore := NewSemaphore (concurrency ) // semaphore to limit concurrency
267268
268269 // scatter
@@ -277,13 +278,13 @@ func (c *CouchdbClient) getDatabasesStatsByDbName(databases []string, concurrenc
277278 data , err := c .Request ("GET" , fmt .Sprintf ("%s/%s" , c .BaseUri , dbName ), nil )
278279 semaphore .Release ()
279280 if err != nil {
280- r <- result {err : fmt .Errorf ("error reading database '%s' stats: %v" , dbName , err )}
281+ r <- dbStatsResult {err : fmt .Errorf ("error reading database '%s' stats: %v" , dbName , err )}
281282 return
282283 }
283284
284285 err = json .Unmarshal (data , & dbStats )
285286 if err != nil {
286- r <- result {err : fmt .Errorf ("error unmarshalling database '%s' stats: %v" , dbName , err )}
287+ r <- dbStatsResult {err : fmt .Errorf ("error unmarshalling database '%s' stats: %v" , dbName , err )}
287288 return
288289 }
289290 dbStats .DiskSizeOverhead = dbStats .DiskSize - dbStats .DataSize
@@ -292,7 +293,7 @@ func (c *CouchdbClient) getDatabasesStatsByDbName(databases []string, concurrenc
292293 } else {
293294 dbStats .CompactRunning = 0
294295 }
295- r <- result {dbName , dbStats , nil }
296+ r <- dbStatsResult {dbName , dbStats , nil }
296297 }()
297298 }
298299 // gather
@@ -308,13 +309,8 @@ func (c *CouchdbClient) getDatabasesStatsByDbName(databases []string, concurrenc
308309}
309310
310311func (c * CouchdbClient ) enhanceWithViewUpdateSeq (dbStatsByDbName map [string ]DatabaseStats , concurrency uint ) error {
311- type result struct {
312- dbName string
313- dbStats DatabaseStats
314- err error
315- }
316312 // Setup for concurrent scatter/gather scrapes, with concurrency limit
317- r := make (chan result , len (dbStatsByDbName ))
313+ r := make (chan dbStatsResult , len (dbStatsByDbName ))
318314 semaphore := NewSemaphore (concurrency ) // semaphore to limit concurrency
319315
320316 // scatter
@@ -334,14 +330,14 @@ func (c *CouchdbClient) enhanceWithViewUpdateSeq(dbStatsByDbName map[string]Data
334330 designDocData , err := c .Request ("GET" , fmt .Sprintf ("%s/%s/_all_docs?%s" , c .BaseUri , dbName , query ), nil )
335331 semaphore .Release ()
336332 if err != nil {
337- r <- result {err : fmt .Errorf ("error reading database '%s' stats: %v" , dbName , err )}
333+ r <- dbStatsResult {err : fmt .Errorf ("error reading database '%s' stats: %v" , dbName , err )}
338334 return
339335 }
340336
341337 var designDocs DocsResponse
342338 err = json .Unmarshal (designDocData , & designDocs )
343339 if err != nil {
344- r <- result {err : fmt .Errorf ("error unmarshalling design docs for database '%s': %v" , dbName , err )}
340+ r <- dbStatsResult {err : fmt .Errorf ("error unmarshalling design docs for database '%s': %v" , dbName , err )}
345341 return
346342 }
347343 views := make (ViewStatsByDesignDocName )
@@ -393,7 +389,7 @@ func (c *CouchdbClient) enhanceWithViewUpdateSeq(dbStatsByDbName map[string]Data
393389 for range row .Doc .Views {
394390 res := <- v
395391 if res .err != nil {
396- r <- result {err : res .err }
392+ r <- dbStatsResult {err : res .err }
397393 return
398394 }
399395 updateSeqByView [res .viewName ] = res .updateSeq
@@ -408,7 +404,7 @@ func (c *CouchdbClient) enhanceWithViewUpdateSeq(dbStatsByDbName map[string]Data
408404 <- done
409405 }
410406 dbStats .Views = views
411- r <- result {dbName , dbStats , nil }
407+ r <- dbStatsResult {dbName , dbStats , nil }
412408 }()
413409 }
414410 // gather
0 commit comments