From 864177a8505f8b8e40edf519d00350abfc2e5397 Mon Sep 17 00:00:00 2001 From: Ali Alrahahleh Date: Tue, 24 May 2016 23:33:49 -0700 Subject: [PATCH] format code for CI --- plugins/inputs/graylog/graylog.go | 26 ++++++++++---------- plugins/inputs/graylog/graylog_test.go | 34 ++++++++++++-------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/plugins/inputs/graylog/graylog.go b/plugins/inputs/graylog/graylog.go index 99644fb36..de9a89fa8 100644 --- a/plugins/inputs/graylog/graylog.go +++ b/plugins/inputs/graylog/graylog.go @@ -1,18 +1,18 @@ package graylog import ( + "bytes" + "encoding/json" "errors" "fmt" - "strconv" - "bytes" - "regexp" "io/ioutil" "net/http" "net/url" + "regexp" + "strconv" "strings" "sync" "time" - "encoding/json" "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/internal" @@ -21,11 +21,11 @@ import ( ) type GrayLog struct { - Name string - Servers []string - TagKeys []string - Metrics []string - Headers map[string]string + Name string + Servers []string + TagKeys []string + Metrics []string + Headers map[string]string // Path to CA file SSLCA string `toml:"ssl_ca"` @@ -55,7 +55,7 @@ type HTTPClient interface { } type Messagebody struct { - Metrics []string `json:"metrics"` + Metrics []string `json:"metrics"` } type RealHTTPClient struct { @@ -202,7 +202,7 @@ func (h *GrayLog) gatherServer( return err } if err := json.Unmarshal([]byte(resp), &dat); err != nil { - return err + return err } if rec, ok := dat["metrics"].([]interface{}); ok { for _, metric := range rec { @@ -222,10 +222,10 @@ func (h *GrayLog) gatherServer( for k, v := range metric.Fields() { re, _ := regexp.Compile(`metrics_([0-9]+)`) match := re.FindAllStringSubmatch(k, -1) - if(match != nil) { + if match != nil { i, _ := strconv.Atoi(match[0][1]) fields[name_list[i]] = v - } + } } fields["response_time"] = responseTime acc.AddFields(metric.Name(), fields, metric.Tags()) diff --git a/plugins/inputs/graylog/graylog_test.go b/plugins/inputs/graylog/graylog_test.go index 99d3ba84e..fc7b54c54 100644 --- a/plugins/inputs/graylog/graylog_test.go +++ b/plugins/inputs/graylog/graylog_test.go @@ -1,10 +1,10 @@ package graylog import ( -// "fmt" + // "fmt" "io/ioutil" "net/http" -// "net/http/httptest" + // "net/http/httptest" "strings" "testing" @@ -36,10 +36,9 @@ const validJSON = ` ] }` - var expectedFields = map[string]interface{}{ - "jvm.memory.pools.Metaspace.committed": float64(108040192), - "jvm.cl.loaded": float64(18910), + "jvm.memory.pools.Metaspace.committed": float64(108040192), + "jvm.cl.loaded": float64(18910), } const invalidJSON = "I don't think this is JSON" @@ -97,29 +96,29 @@ func genMockGrayLog(response string, statusCode int) []*GrayLog { Servers: []string{ "http://localhost:12900/system/metrics/multiple", }, - Name: "my_webapp", + Name: "my_webapp", Metrics: []string{ - "jvm.cl.loaded", + "jvm.cl.loaded", }, Headers: map[string]string{ - "Content-Type" : "application/json", - "Accept" : "application/json", - "Authorization" : "Basic DESfdsfffoffo", + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": "Basic DESfdsfffoffo", }, }, &GrayLog{ client: &mockHTTPClient{responseBody: response, statusCode: statusCode}, - Servers: []string{ + Servers: []string{ "http://server2:12900/system/metrics/multiple", }, - Name: "other_webapp", - Metrics: []string{ - "jvm.memory.pools.Metaspace.committed", + Name: "other_webapp", + Metrics: []string{ + "jvm.memory.pools.Metaspace.committed", }, Headers: map[string]string{ - "Content-Type" : "application/json", - "Accept" : "application/json", - "Authorization" : "Basic DESfdsfffoffo", + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": "Basic DESfdsfffoffo", }, TagKeys: []string{ "role", @@ -152,7 +151,6 @@ func TestNormalResponse(t *testing.T) { } } - // Test response to HTTP 500 func TestHttpJson500(t *testing.T) { graylog := genMockGrayLog(validJSON, 500)