Accumulator.AddError() interface instead of returning err

This commit is contained in:
Lukasz Jagiello 2016-09-09 09:45:00 +00:00
parent e46e9ab79c
commit 43a9b37eab
2 changed files with 7 additions and 8 deletions

View File

@ -374,28 +374,28 @@ func (s *Solr) gatherCoreStats(url string, core string, acc telegraf.Accumulator
for _, category := range []string{"CORE", "QUERYHANDLER", "UPDATEHANDLER", "CACHE"} { for _, category := range []string{"CORE", "QUERYHANDLER", "UPDATEHANDLER", "CACHE"} {
metrics := &Metrics{} metrics := &Metrics{}
if err := s.gatherData(fmt.Sprintf("%s&cat=%s", url, category), metrics); err != nil { if err := s.gatherData(fmt.Sprintf("%s&cat=%s", url, category), metrics); err != nil {
return err acc.AddError(fmt.Errorf("JSON fetch error: %s", err))
} }
switch category { switch category {
case "CORE": case "CORE":
if err := gatherCoreMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil { if err := gatherCoreMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil {
return err acc.AddError(fmt.Errorf("core category: %s", err))
} }
case "QUERYHANDLER": case "QUERYHANDLER":
if err := gatherQueryHandlerMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil { if err := gatherQueryHandlerMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil {
return err acc.AddError(fmt.Errorf("query handler category: %s", err))
} }
case "UPDATEHANDLER": case "UPDATEHANDLER":
if err := gatherUpdateHandlerMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil { if err := gatherUpdateHandlerMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil {
return err acc.AddError(fmt.Errorf("update handler category: %s", err))
} }
case "CACHE": case "CACHE":
if err := gatherCacheMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil { if err := gatherCacheMetrics(metrics.SolrMbeans[1], core, category, acc); err != nil {
return err acc.AddError(fmt.Errorf("cache category: %s", err))
} }
default: default:
err := errors.New("unrecognized category") err := errors.New("unrecognized category")
return err acc.AddError(fmt.Errorf("category: %s", err))
} }
} }
return nil return nil

View File

@ -8,7 +8,6 @@ import (
"testing" "testing"
"github.com/influxdata/telegraf/testutil" "github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -43,7 +42,7 @@ func TestSetDefaults(t *testing.T) {
solr.Servers = []string{"http://example.com:8983"} solr.Servers = []string{"http://example.com:8983"}
solr.client.Transport = newTransportMock(http.StatusOK, adminCoresResponse) solr.client.Transport = newTransportMock(http.StatusOK, adminCoresResponse)
cores, max, err := solr.setDefaults() _, max, err := solr.setDefaults()
if max != 5 { if max != 5 {
err = fmt.Errorf("Received unexpected error: max number of cores: %v, expected 5", max) err = fmt.Errorf("Received unexpected error: max number of cores: %v, expected 5", max)
} }