From 190fdd24fa419465e5d1bc706c3a3d249c4bd199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= <69143962+pmalek-sumo@users.noreply.github.com> Date: Wed, 14 Oct 2020 18:11:23 +0200 Subject: [PATCH] Sumo Logic output plugin: only support HTTP POST (#8262) --- etc/telegraf.conf | 3 -- plugins/outputs/sumologic/README.md | 3 -- plugins/outputs/sumologic/sumologic.go | 17 +------- plugins/outputs/sumologic/sumologic_test.go | 43 --------------------- 4 files changed, 1 insertion(+), 65 deletions(-) diff --git a/etc/telegraf.conf b/etc/telegraf.conf index 486ec5941..a07e922c3 100644 --- a/etc/telegraf.conf +++ b/etc/telegraf.conf @@ -1328,9 +1328,6 @@ # ## Timeout used for HTTP request # # timeout = "5s" # -# ## HTTP method, one of: "POST" or "PUT". "POST" is used by default if unset. -# # method = "POST" -# # ## Max HTTP request body size in bytes before compression (if applied). # ## By default 1MB is recommended. # ## NOTE: diff --git a/plugins/outputs/sumologic/README.md b/plugins/outputs/sumologic/README.md index d3a90df37..78f0eb337 100644 --- a/plugins/outputs/sumologic/README.md +++ b/plugins/outputs/sumologic/README.md @@ -39,9 +39,6 @@ by Sumologic HTTP Source: ## Timeout used for HTTP request # timeout = "5s" - ## HTTP method, one of: "POST" or "PUT". "POST" is used by default if unset. - # method = "POST" - ## Max HTTP request body size in bytes before compression (if applied). ## By default 1MB is recommended. ## NOTE: diff --git a/plugins/outputs/sumologic/sumologic.go b/plugins/outputs/sumologic/sumologic.go index 5497da606..3c3f4a649 100644 --- a/plugins/outputs/sumologic/sumologic.go +++ b/plugins/outputs/sumologic/sumologic.go @@ -4,10 +4,8 @@ import ( "bytes" "compress/gzip" "context" - "fmt" "log" "net/http" - "strings" "time" "github.com/pkg/errors" @@ -46,9 +44,6 @@ const ( ## Timeout used for HTTP request # timeout = "5s" - ## HTTP method, one of: "POST" or "PUT". "POST" is used by default if unset. - # method = "POST" - ## Max HTTP request body size in bytes before compression (if applied). ## By default 1MB is recommended. ## NOTE: @@ -100,7 +95,6 @@ const ( type SumoLogic struct { URL string `toml:"url"` Timeout internal.Duration `toml:"timeout"` - Method string `toml:"method"` MaxRequstBodySize config.Size `toml:"max_request_body_size"` SourceName string `toml:"source_name"` @@ -159,14 +153,6 @@ func (s *SumoLogic) Connect() error { return errors.Wrap(s.err, "sumologic: incorrect configuration") } - if s.Method == "" { - s.Method = defaultMethod - } - s.Method = strings.ToUpper(s.Method) - if s.Method != http.MethodPost && s.Method != http.MethodPut { - return fmt.Errorf("invalid method [%s] %s", s.URL, s.Method) - } - if s.Timeout.Duration == 0 { s.Timeout.Duration = defaultClientTimeout } @@ -245,7 +231,7 @@ func (s *SumoLogic) write(reqBody []byte) error { return err } - req, err := http.NewRequest(s.Method, s.URL, &buff) + req, err := http.NewRequest(defaultMethod, s.URL, &buff) if err != nil { return err } @@ -352,7 +338,6 @@ func Default() *SumoLogic { Timeout: internal.Duration{ Duration: defaultClientTimeout, }, - Method: defaultMethod, MaxRequstBodySize: defaultMaxRequestBodySize, headers: make(map[string]string), } diff --git a/plugins/outputs/sumologic/sumologic_test.go b/plugins/outputs/sumologic/sumologic_test.go index 9c86e0b80..48450ab45 100644 --- a/plugins/outputs/sumologic/sumologic_test.go +++ b/plugins/outputs/sumologic/sumologic_test.go @@ -64,16 +64,6 @@ func getMetrics(t *testing.T, count int) []telegraf.Metric { return metrics } -func TestInvalidMethod(t *testing.T) { - plugin := &SumoLogic{ - URL: "", - Method: http.MethodGet, - } - - err := plugin.Connect() - require.Error(t, err) -} - func TestMethod(t *testing.T) { ts := httptest.NewServer(http.NotFoundHandler()) defer ts.Close() @@ -96,36 +86,6 @@ func TestMethod(t *testing.T) { }, expectedMethod: http.MethodPost, }, - { - name: "put is okay", - plugin: func() *SumoLogic { - s := Default() - s.URL = u.String() - s.Method = http.MethodPut - return s - }, - expectedMethod: http.MethodPut, - }, - { - name: "get is invalid", - plugin: func() *SumoLogic { - s := Default() - s.URL = u.String() - s.Method = http.MethodGet - return s - }, - connectError: true, - }, - { - name: "method is case insensitive", - plugin: func() *SumoLogic { - s := Default() - s.URL = u.String() - s.Method = "poST" - return s - }, - expectedMethod: http.MethodPost, - }, } for _, tt := range tests { @@ -381,7 +341,6 @@ func TestDefaultUserAgent(t *testing.T) { plugin := &SumoLogic{ URL: u.String(), - Method: defaultMethod, MaxRequstBodySize: Default().MaxRequstBodySize, } @@ -451,7 +410,6 @@ func TestTOMLConfig(t *testing.T) { url = "https://localhost:3000" data_format = "carbon2" timeout = "5s" - method = "POST" source_name = "name" source_host = "hosta" source_category = "category" @@ -466,7 +424,6 @@ func TestTOMLConfig(t *testing.T) { url = "https://localhost:3000" data_format = "carbon2" timeout = "5s" - method = "POST" source_name = "name" sumo_metadata = "metadata" `),