Skip to content

Commit

Permalink
Sumo Logic output plugin: only support HTTP POST (influxdata#8262)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek-sumo authored Oct 14, 2020
1 parent 1d6172b commit 190fdd2
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 65 deletions.
3 changes: 0 additions & 3 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions plugins/outputs/sumologic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 1 addition & 16 deletions plugins/outputs/sumologic/sumologic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"bytes"
"compress/gzip"
"context"
"fmt"
"log"
"net/http"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -352,7 +338,6 @@ func Default() *SumoLogic {
Timeout: internal.Duration{
Duration: defaultClientTimeout,
},
Method: defaultMethod,
MaxRequstBodySize: defaultMaxRequestBodySize,
headers: make(map[string]string),
}
Expand Down
43 changes: 0 additions & 43 deletions plugins/outputs/sumologic/sumologic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down Expand Up @@ -381,7 +341,6 @@ func TestDefaultUserAgent(t *testing.T) {

plugin := &SumoLogic{
URL: u.String(),
Method: defaultMethod,
MaxRequstBodySize: Default().MaxRequstBodySize,
}

Expand Down Expand Up @@ -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"
Expand All @@ -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"
`),
Expand Down

0 comments on commit 190fdd2

Please sign in to comment.