From 3e4d2a1fb016f8fa19f4f3e81602f7367ca8a20f Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Sun, 22 Nov 2015 18:42:34 +0000 Subject: [PATCH] golint monitor package. Supports #4098 --- monitor/service.go | 12 +++++++++--- monitor/statement_executor.go | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/monitor/service.go b/monitor/service.go index 4e0285b39c..4aeb1d909d 100644 --- a/monitor/service.go +++ b/monitor/service.go @@ -18,6 +18,7 @@ import ( const leaderWaitTimeout = 30 * time.Second +// Policy constants. const ( MonitorRetentionPolicy = "monitor" MonitorRetentionPolicyDuration = 7 * 24 * time.Hour @@ -50,6 +51,7 @@ type Diagnostic struct { Rows [][]interface{} } +// NewDiagnostic initialises a new Diagnostic with the specified columns. func NewDiagnostic(columns []string) *Diagnostic { return &Diagnostic{ Columns: columns, @@ -57,6 +59,7 @@ func NewDiagnostic(columns []string) *Diagnostic { } } +// AddRow appends the provided row to the Diagnostic's rows. func (d *Diagnostic) AddRow(r []interface{}) { d.Rows = append(d.Rows, r) } @@ -172,7 +175,7 @@ func (m *Monitor) DeregisterDiagnosticsClient(name string) { // Statistics returns the combined statistics for all expvar data. The given // tags are added to each of the returned statistics. func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) { - statistics := make([]*Statistic, 0) + var statistics []*Statistic expvar.Do(func(kv expvar.KeyValue) { // Skip built-in expvar stats. @@ -281,6 +284,9 @@ func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) { return statistics, nil } +// Diagnostics fetches diagnostic information for each registered +// diagnostic client. It skips any clients that return an error when +// retrieving their diagnostics. func (m *Monitor) Diagnostics() (map[string]*Diagnostic, error) { m.mu.Lock() defer m.mu.Unlock() @@ -412,7 +418,7 @@ func newStatistic(name string, tags map[string]string, values map[string]interfa // valueNames returns a sorted list of the value names, if any. func (s *Statistic) valueNames() []string { a := make([]string, 0, len(s.Values)) - for k, _ := range s.Values { + for k := range s.Values { a = append(a, k) } sort.Strings(a) @@ -423,7 +429,7 @@ func (s *Statistic) valueNames() []string { func DiagnosticFromMap(m map[string]interface{}) *Diagnostic { // Display columns in deterministic order. sortedKeys := make([]string, 0, len(m)) - for k, _ := range m { + for k := range m { sortedKeys = append(sortedKeys, k) } sort.Strings(sortedKeys) diff --git a/monitor/statement_executor.go b/monitor/statement_executor.go index 450fc4894b..2461738d48 100644 --- a/monitor/statement_executor.go +++ b/monitor/statement_executor.go @@ -33,8 +33,8 @@ func (s *StatementExecutor) executeShowStatistics(module string) *influxql.Resul if err != nil { return &influxql.Result{Err: err} } - rows := make([]*models.Row, 0) + var rows []*models.Row for _, stat := range stats { if module != "" && stat.Name != module { continue @@ -61,7 +61,7 @@ func (s *StatementExecutor) executeShowDiagnostics(module string) *influxql.Resu // Get a sorted list of diagnostics keys. sortedKeys := make([]string, 0, len(diags)) - for k, _ := range diags { + for k := range diags { sortedKeys = append(sortedKeys, k) } sort.Strings(sortedKeys)