From 8d7d89d8edf4653ad3d7376fc748f5c12bec4625 Mon Sep 17 00:00:00 2001 From: rw Date: Tue, 23 Aug 2016 11:45:12 -0700 Subject: [PATCH] Fix "nil map" panic in statistics collection. --- models/statistic.go | 8 ++++++++ monitor/service.go | 9 ++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/models/statistic.go b/models/statistic.go index 7e51a2c13d..8ce4a326c2 100644 --- a/models/statistic.go +++ b/models/statistic.go @@ -5,3 +5,11 @@ type Statistic struct { Tags map[string]string `json:"tags"` Values map[string]interface{} `json:"values"` } + +func NewStatistic(name string) Statistic { + return Statistic{ + Name: name, + Tags: make(map[string]string), + Values: make(map[string]interface{}), + } +} diff --git a/monitor/service.go b/monitor/service.go index 7c81794f74..6a9f827d91 100644 --- a/monitor/service.go +++ b/monitor/service.go @@ -210,9 +210,7 @@ func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) { } statistic := &Statistic{ - Statistic: models.Statistic{ - Values: make(map[string]interface{}), - }, + Statistic: models.NewStatistic(""), } // Add any supplied tags. @@ -277,10 +275,7 @@ func (m *Monitor) Statistics(tags map[string]string) ([]*Statistic, error) { // Add Go memstats. statistic := &Statistic{ - Statistic: models.Statistic{ - Name: "runtime", - Values: make(map[string]interface{}), - }, + Statistic: models.NewStatistic("runtime"), } // Add any supplied tags to Go memstats