Sumo Logic output plugin: only support HTTP POST (#8262)
This commit is contained in:
parent
1d6172bd2d
commit
190fdd24fa
|
|
@ -1328,9 +1328,6 @@
|
||||||
# ## Timeout used for HTTP request
|
# ## Timeout used for HTTP request
|
||||||
# # timeout = "5s"
|
# # 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).
|
# ## Max HTTP request body size in bytes before compression (if applied).
|
||||||
# ## By default 1MB is recommended.
|
# ## By default 1MB is recommended.
|
||||||
# ## NOTE:
|
# ## NOTE:
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,6 @@ by Sumologic HTTP Source:
|
||||||
## Timeout used for HTTP request
|
## Timeout used for HTTP request
|
||||||
# timeout = "5s"
|
# 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).
|
## Max HTTP request body size in bytes before compression (if applied).
|
||||||
## By default 1MB is recommended.
|
## By default 1MB is recommended.
|
||||||
## NOTE:
|
## NOTE:
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
@ -46,9 +44,6 @@ const (
|
||||||
## Timeout used for HTTP request
|
## Timeout used for HTTP request
|
||||||
# timeout = "5s"
|
# 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).
|
## Max HTTP request body size in bytes before compression (if applied).
|
||||||
## By default 1MB is recommended.
|
## By default 1MB is recommended.
|
||||||
## NOTE:
|
## NOTE:
|
||||||
|
|
@ -100,7 +95,6 @@ const (
|
||||||
type SumoLogic struct {
|
type SumoLogic struct {
|
||||||
URL string `toml:"url"`
|
URL string `toml:"url"`
|
||||||
Timeout internal.Duration `toml:"timeout"`
|
Timeout internal.Duration `toml:"timeout"`
|
||||||
Method string `toml:"method"`
|
|
||||||
MaxRequstBodySize config.Size `toml:"max_request_body_size"`
|
MaxRequstBodySize config.Size `toml:"max_request_body_size"`
|
||||||
|
|
||||||
SourceName string `toml:"source_name"`
|
SourceName string `toml:"source_name"`
|
||||||
|
|
@ -159,14 +153,6 @@ func (s *SumoLogic) Connect() error {
|
||||||
return errors.Wrap(s.err, "sumologic: incorrect configuration")
|
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 {
|
if s.Timeout.Duration == 0 {
|
||||||
s.Timeout.Duration = defaultClientTimeout
|
s.Timeout.Duration = defaultClientTimeout
|
||||||
}
|
}
|
||||||
|
|
@ -245,7 +231,7 @@ func (s *SumoLogic) write(reqBody []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(s.Method, s.URL, &buff)
|
req, err := http.NewRequest(defaultMethod, s.URL, &buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +338,6 @@ func Default() *SumoLogic {
|
||||||
Timeout: internal.Duration{
|
Timeout: internal.Duration{
|
||||||
Duration: defaultClientTimeout,
|
Duration: defaultClientTimeout,
|
||||||
},
|
},
|
||||||
Method: defaultMethod,
|
|
||||||
MaxRequstBodySize: defaultMaxRequestBodySize,
|
MaxRequstBodySize: defaultMaxRequestBodySize,
|
||||||
headers: make(map[string]string),
|
headers: make(map[string]string),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,16 +64,6 @@ func getMetrics(t *testing.T, count int) []telegraf.Metric {
|
||||||
return metrics
|
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) {
|
func TestMethod(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.NotFoundHandler())
|
ts := httptest.NewServer(http.NotFoundHandler())
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
@ -96,36 +86,6 @@ func TestMethod(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedMethod: http.MethodPost,
|
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 {
|
for _, tt := range tests {
|
||||||
|
|
@ -381,7 +341,6 @@ func TestDefaultUserAgent(t *testing.T) {
|
||||||
|
|
||||||
plugin := &SumoLogic{
|
plugin := &SumoLogic{
|
||||||
URL: u.String(),
|
URL: u.String(),
|
||||||
Method: defaultMethod,
|
|
||||||
MaxRequstBodySize: Default().MaxRequstBodySize,
|
MaxRequstBodySize: Default().MaxRequstBodySize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -451,7 +410,6 @@ func TestTOMLConfig(t *testing.T) {
|
||||||
url = "https://localhost:3000"
|
url = "https://localhost:3000"
|
||||||
data_format = "carbon2"
|
data_format = "carbon2"
|
||||||
timeout = "5s"
|
timeout = "5s"
|
||||||
method = "POST"
|
|
||||||
source_name = "name"
|
source_name = "name"
|
||||||
source_host = "hosta"
|
source_host = "hosta"
|
||||||
source_category = "category"
|
source_category = "category"
|
||||||
|
|
@ -466,7 +424,6 @@ func TestTOMLConfig(t *testing.T) {
|
||||||
url = "https://localhost:3000"
|
url = "https://localhost:3000"
|
||||||
data_format = "carbon2"
|
data_format = "carbon2"
|
||||||
timeout = "5s"
|
timeout = "5s"
|
||||||
method = "POST"
|
|
||||||
source_name = "name"
|
source_name = "name"
|
||||||
sumo_metadata = "metadata"
|
sumo_metadata = "metadata"
|
||||||
`),
|
`),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue