Skip to content

Commit 742bac7

Browse files
committed
cleanup
follow up of #46 (#46 (comment))
1 parent 4ea8210 commit 742bac7

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

couchdb-exporter.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -180,37 +180,37 @@ func init() {
180180
func main() {
181181
var appAction = func(c *cli.Context) error {
182182
var databases []string
183-
if *&exporterConfig.databases != "" {
184-
databases = strings.Split(*&exporterConfig.databases, ",")
183+
if exporterConfig.databases != "" {
184+
databases = strings.Split(exporterConfig.databases, ",")
185185
}
186186

187187
exporter := lib.NewExporter(
188-
*&exporterConfig.couchdbURI,
188+
exporterConfig.couchdbURI,
189189
lib.BasicAuth{
190-
Username: *&exporterConfig.couchdbUsername,
191-
Password: *&exporterConfig.couchdbPassword},
190+
Username: exporterConfig.couchdbUsername,
191+
Password: exporterConfig.couchdbPassword},
192192
lib.CollectorConfig{
193193
Databases: databases,
194-
CollectViews: *&exporterConfig.databaseViews,
195-
CollectSchedulerJobs: *&exporterConfig.schedulerJobs,
196-
ConcurrentRequests: *&exporterConfig.databaseConcurrentRequests,
194+
CollectViews: exporterConfig.databaseViews,
195+
CollectSchedulerJobs: exporterConfig.schedulerJobs,
196+
ConcurrentRequests: exporterConfig.databaseConcurrentRequests,
197197
},
198-
*&exporterConfig.couchdbInsecure)
198+
exporterConfig.couchdbInsecure)
199199
prometheus.MustRegister(exporter)
200200

201-
http.Handle(*&exporterConfig.metricsEndpoint, promhttp.Handler())
201+
http.Handle(exporterConfig.metricsEndpoint, promhttp.Handler())
202202
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
203203
_, err := fmt.Fprint(w, "OK")
204204
if err != nil {
205205
klog.Error(err)
206206
}
207207
})
208208
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
209-
http.Error(w, fmt.Sprintf("Please GET %s", *&exporterConfig.metricsEndpoint), http.StatusNotFound)
209+
http.Error(w, fmt.Sprintf("Please GET %s", exporterConfig.metricsEndpoint), http.StatusNotFound)
210210
})
211211

212-
klog.Infof("Starting exporter at '%s' to read from CouchDB at '%s'", *&exporterConfig.listenAddress, *&exporterConfig.couchdbURI)
213-
err := http.ListenAndServe(*&exporterConfig.listenAddress, nil)
212+
klog.Infof("Starting exporter at '%s' to read from CouchDB at '%s'", exporterConfig.listenAddress, exporterConfig.couchdbURI)
213+
err := http.ListenAndServe(exporterConfig.listenAddress, nil)
214214
if err != nil {
215215
klog.Fatal(err)
216216
}

lib/couchdb-client.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
257263
func (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

310311
func (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

Comments
 (0)