chore(linters): Bump golangci-lint to v1.56.1 (#14759)
This commit is contained in:
parent
af2704f98a
commit
c4dbe65732
|
|
@ -96,7 +96,7 @@ jobs:
|
||||||
- run: 'make check-deps'
|
- run: 'make check-deps'
|
||||||
- run:
|
- run:
|
||||||
name: "Install golangci-lint"
|
name: "Install golangci-lint"
|
||||||
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.0
|
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
|
||||||
- run:
|
- run:
|
||||||
name: "golangci-lint/Linux"
|
name: "golangci-lint/Linux"
|
||||||
command: GOGC=80 GOMEMLIMIT=6656MiB /go/bin/golangci-lint run --verbose
|
command: GOGC=80 GOMEMLIMIT=6656MiB /go/bin/golangci-lint run --verbose
|
||||||
|
|
@ -107,7 +107,7 @@ jobs:
|
||||||
- check-changed-files-or-halt
|
- check-changed-files-or-halt
|
||||||
- run:
|
- run:
|
||||||
name: "Install golangci-lint"
|
name: "Install golangci-lint"
|
||||||
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.0
|
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
|
||||||
- run:
|
- run:
|
||||||
name: "golangci-lint/macOS"
|
name: "golangci-lint/macOS"
|
||||||
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=darwin /go/bin/golangci-lint run --verbose --timeout=30m
|
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=darwin /go/bin/golangci-lint run --verbose --timeout=30m
|
||||||
|
|
@ -119,7 +119,7 @@ jobs:
|
||||||
- check-changed-files-or-halt
|
- check-changed-files-or-halt
|
||||||
- run:
|
- run:
|
||||||
name: "Install golangci-lint"
|
name: "Install golangci-lint"
|
||||||
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.0
|
command: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
|
||||||
- run:
|
- run:
|
||||||
name: "golangci-lint/Windows"
|
name: "golangci-lint/Windows"
|
||||||
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=windows /go/bin/golangci-lint run --verbose --timeout=30m
|
command: GOGC=80 GOMEMLIMIT=6656MiB GOOS=windows /go/bin/golangci-lint run --verbose --timeout=30m
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -174,7 +174,7 @@ vet:
|
||||||
.PHONY: lint-install
|
.PHONY: lint-install
|
||||||
lint-install:
|
lint-install:
|
||||||
@echo "Installing golangci-lint"
|
@echo "Installing golangci-lint"
|
||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.0
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
|
||||||
|
|
||||||
@echo "Installing markdownlint"
|
@echo "Installing markdownlint"
|
||||||
npm install -g markdownlint-cli
|
npm install -g markdownlint-cli
|
||||||
|
|
|
||||||
|
|
@ -362,7 +362,7 @@ func runApp(args []string, outputBuffer io.Writer, pprof Server, c TelegrafConfi
|
||||||
{
|
{
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "print current version to stdout",
|
Usage: "print current version to stdout",
|
||||||
Action: func(cCtx *cli.Context) error {
|
Action: func(*cli.Context) error {
|
||||||
fmt.Fprintf(outputBuffer, "%s\n", internal.FormatFullVersion())
|
fmt.Fprintf(outputBuffer, "%s\n", internal.FormatFullVersion())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -497,7 +497,7 @@ func TestConfig_AzureMonitorNamespacePrefix(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetDefaultConfigPathFromEnvURL(t *testing.T) {
|
func TestGetDefaultConfigPathFromEnvURL(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, _ = w.Write([]byte("[agent]\ndebug = true"))
|
_, _ = w.Write([]byte("[agent]\ndebug = true"))
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -377,7 +377,7 @@ func TestRemoveComments(t *testing.T) {
|
||||||
func TestURLRetries3Fails(t *testing.T) {
|
func TestURLRetries3Fails(t *testing.T) {
|
||||||
httpLoadConfigRetryInterval = 0 * time.Second
|
httpLoadConfigRetryInterval = 0 * time.Second
|
||||||
responseCounter := 0
|
responseCounter := 0
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
responseCounter++
|
responseCounter++
|
||||||
}))
|
}))
|
||||||
|
|
@ -395,7 +395,7 @@ func TestURLRetries3Fails(t *testing.T) {
|
||||||
func TestURLRetries3FailsThenPasses(t *testing.T) {
|
func TestURLRetries3FailsThenPasses(t *testing.T) {
|
||||||
httpLoadConfigRetryInterval = 0 * time.Second
|
httpLoadConfigRetryInterval = 0 * time.Second
|
||||||
responseCounter := 0
|
responseCounter := 0
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
if responseCounter <= 2 {
|
if responseCounter <= 2 {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -814,7 +814,7 @@ func (s *MockupSecretStore) GetResolver(key string) (telegraf.ResolveFunc, error
|
||||||
func init() {
|
func init() {
|
||||||
// Register the mockup input plugin for the required names
|
// Register the mockup input plugin for the required names
|
||||||
inputs.Add("mockup", func() telegraf.Input { return &MockupSecretPlugin{} })
|
inputs.Add("mockup", func() telegraf.Input { return &MockupSecretPlugin{} })
|
||||||
secretstores.Add("mockup", func(id string) telegraf.SecretStore {
|
secretstores.Add("mockup", func(string) telegraf.SecretStore {
|
||||||
return &MockupSecretStore{}
|
return &MockupSecretStore{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ type Config struct {
|
||||||
type BackoffFunc func(retries, maxRetries int) time.Duration
|
type BackoffFunc func(retries, maxRetries int) time.Duration
|
||||||
|
|
||||||
func makeBackoffFunc(backoff, maxDuration time.Duration) BackoffFunc {
|
func makeBackoffFunc(backoff, maxDuration time.Duration) BackoffFunc {
|
||||||
return func(retries, maxRetries int) time.Duration {
|
return func(retries, _ int) time.Duration {
|
||||||
d := time.Duration(math.Pow(2, float64(retries))) * backoff
|
d := time.Duration(math.Pow(2, float64(retries))) * backoff
|
||||||
if maxDuration != 0 && d > maxDuration {
|
if maxDuration != 0 && d > maxDuration {
|
||||||
return maxDuration
|
return maxDuration
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ func builtinAttr(recv starlark.Value, name string, methods map[string]builtinMet
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a closure over 'method'.
|
// Allocate a closure over 'method'.
|
||||||
impl := func(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
impl := func(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||||
return method(b, args, kwargs)
|
return method(b, args, kwargs)
|
||||||
}
|
}
|
||||||
return starlark.NewBuiltin(name, impl).BindReceiver(recv), nil
|
return starlark.NewBuiltin(name, impl).BindReceiver(recv), nil
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
// Builds a module that defines all the supported logging functions which will log using the provided logger
|
// Builds a module that defines all the supported logging functions which will log using the provided logger
|
||||||
func LogModule(logger telegraf.Logger) *starlarkstruct.Module {
|
func LogModule(logger telegraf.Logger) *starlarkstruct.Module {
|
||||||
var logFunc = func(t *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
var logFunc = func(_ *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
|
||||||
return log(b, args, kwargs, logger)
|
return log(b, args, kwargs, logger)
|
||||||
}
|
}
|
||||||
return &starlarkstruct.Module{
|
return &starlarkstruct.Module{
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ func (s *Common) Init() error {
|
||||||
|
|
||||||
s.thread = &starlark.Thread{
|
s.thread = &starlark.Thread{
|
||||||
Print: func(_ *starlark.Thread, msg string) { s.Log.Debug(msg) },
|
Print: func(_ *starlark.Thread, msg string) { s.Log.Debug(msg) },
|
||||||
Load: func(thread *starlark.Thread, module string) (starlark.StringDict, error) {
|
Load: func(_ *starlark.Thread, module string) (starlark.StringDict, error) {
|
||||||
return s.StarlarkLoadFunc(module, s.Log)
|
return s.StarlarkLoadFunc(module, s.Log)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ func TestConnect(t *testing.T) {
|
||||||
serverTLSConfig, err := serverConfig.TLSConfig()
|
serverTLSConfig, err := serverConfig.TLSConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}))
|
}))
|
||||||
ts.TLS = serverTLSConfig
|
ts.TLS = serverTLSConfig
|
||||||
|
|
@ -499,7 +499,7 @@ func TestConnectClientMinTLSVersion(t *testing.T) {
|
||||||
serverTLSConfig.MaxVersion = serverTLSMaxVersion
|
serverTLSConfig.MaxVersion = serverTLSMaxVersion
|
||||||
|
|
||||||
// Start the server
|
// Start the server
|
||||||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}))
|
}))
|
||||||
ts.TLS = serverTLSConfig
|
ts.TLS = serverTLSConfig
|
||||||
|
|
@ -553,7 +553,7 @@ func TestConnectWrongDNS(t *testing.T) {
|
||||||
serverTLSConfig, err := serverConfig.TLSConfig()
|
serverTLSConfig, err := serverConfig.TLSConfig()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}))
|
}))
|
||||||
ts.TLS = serverTLSConfig
|
ts.TLS = serverTLSConfig
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ Scoreboard: WW_____W_RW_R_W__RRR____WR_W___WW________W_WW_W_____R__R_WR__WRWR_RR
|
||||||
`
|
`
|
||||||
|
|
||||||
func TestHTTPApache(t *testing.T) {
|
func TestHTTPApache(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, apacheStatus)
|
_, err := fmt.Fprintln(w, apacheStatus)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ func TestAurora(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "minimal",
|
name: "minimal",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
body := `{
|
body := `{
|
||||||
"variable_scrape_events": 2958,
|
"variable_scrape_events": 2958,
|
||||||
"variable_scrape_events_per_sec": 1.0,
|
"variable_scrape_events_per_sec": 1.0,
|
||||||
|
|
@ -71,7 +71,7 @@ func TestAurora(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "disabled role",
|
name: "disabled role",
|
||||||
roles: []string{"leader"},
|
roles: []string{"leader"},
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
},
|
},
|
||||||
check: func(t *testing.T, err error, acc *testutil.Accumulator) {
|
check: func(t *testing.T, err error, acc *testutil.Accumulator) {
|
||||||
|
|
@ -82,10 +82,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no metrics available",
|
name: "no metrics available",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write([]byte("{}"))
|
_, err := w.Write([]byte("{}"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -98,10 +98,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "string metrics skipped",
|
name: "string metrics skipped",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
body := `{
|
body := `{
|
||||||
"foo": "bar"
|
"foo": "bar"
|
||||||
}`
|
}`
|
||||||
|
|
@ -117,10 +117,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "float64 unparseable",
|
name: "float64 unparseable",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
// too large
|
// too large
|
||||||
body := `{
|
body := `{
|
||||||
"foo": 1e309
|
"foo": 1e309
|
||||||
|
|
@ -137,10 +137,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "int64 unparseable",
|
name: "int64 unparseable",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
// too large
|
// too large
|
||||||
body := `{
|
body := `{
|
||||||
"foo": 9223372036854775808
|
"foo": 9223372036854775808
|
||||||
|
|
@ -157,10 +157,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bad json",
|
name: "bad json",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
body := `{]`
|
body := `{]`
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write([]byte(body))
|
_, err := w.Write([]byte(body))
|
||||||
|
|
@ -174,10 +174,10 @@ func TestAurora(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "wrong status code",
|
name: "wrong status code",
|
||||||
leaderhealth: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
leaderhealth: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
varsjson: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
varsjson: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
body := `{
|
body := `{
|
||||||
"value": 42
|
"value": 42
|
||||||
}`
|
}`
|
||||||
|
|
|
||||||
|
|
@ -107,11 +107,11 @@ func TestGather(t *testing.T) {
|
||||||
perfDump = saveDump
|
perfDump = saveDump
|
||||||
}()
|
}()
|
||||||
|
|
||||||
findSockets = func(c *Ceph) ([]*socket, error) {
|
findSockets = func(*Ceph) ([]*socket, error) {
|
||||||
return []*socket{{"osd.1", typeOsd, ""}}, nil
|
return []*socket{{"osd.1", typeOsd, ""}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
perfDump = func(binary string, s *socket) (string, error) {
|
perfDump = func(string, *socket) (string, error) {
|
||||||
return osdPerfDump, nil
|
return osdPerfDump, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -536,7 +536,7 @@ func TestGatherClickhouseCloud(t *testing.T) {
|
||||||
|
|
||||||
func TestWrongJSONMarshalling(t *testing.T) {
|
func TestWrongJSONMarshalling(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
type result struct {
|
type result struct {
|
||||||
Data interface{} `json:"data"`
|
Data interface{} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ func (s *stubSub) Receive(ctx context.Context, f func(context.Context, message))
|
||||||
type receiveFunc func(ctx context.Context, f func(context.Context, message)) error
|
type receiveFunc func(ctx context.Context, f func(context.Context, message)) error
|
||||||
|
|
||||||
func testMessagesError(expectedErr error) receiveFunc {
|
func testMessagesError(expectedErr error) receiveFunc {
|
||||||
return func(ctx context.Context, f func(context.Context, message)) error {
|
return func(context.Context, func(context.Context, message)) error {
|
||||||
return expectedErr
|
return expectedErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/boschrexroth/ctrlx-datalayer-golang/pkg/token"
|
"github.com/boschrexroth/ctrlx-datalayer-golang/pkg/token"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
httpconfig "github.com/influxdata/telegraf/plugins/common/http"
|
httpconfig "github.com/influxdata/telegraf/plugins/common/http"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const path = "/automation/api/v2/events"
|
const path = "/automation/api/v2/events"
|
||||||
|
|
@ -33,7 +34,7 @@ func getMultiEntries() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCtrlXCreateSubscriptionBasic(t *testing.T) {
|
func TestCtrlXCreateSubscriptionBasic(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
_, err := w.Write([]byte("201 created"))
|
_, err := w.Write([]byte("201 created"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -77,7 +78,7 @@ func TestCtrlXCreateSubscriptionDriven(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.res, func(t *testing.T) {
|
t.Run(test.res, func(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(test.status)
|
w.WriteHeader(test.status)
|
||||||
_, err := w.Write([]byte(test.res))
|
_, err := w.Write([]byte(test.res))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -116,23 +117,23 @@ func TestCtrlXCreateSubscriptionDriven(t *testing.T) {
|
||||||
func newServer(t *testing.T) *httptest.Server {
|
func newServer(t *testing.T) *httptest.Server {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
// Handle request to fetch token
|
// Handle request to fetch token
|
||||||
mux.HandleFunc("/identity-manager/api/v2/auth/token", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/identity-manager/api/v2/auth/token", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := w.Write([]byte("{\"access_token\": \"eyJhbGciOiJIU.xxx.xxx\", \"token_type\":\"Bearer\"}"))
|
_, err := w.Write([]byte("{\"access_token\": \"eyJhbGciOiJIU.xxx.xxx\", \"token_type\":\"Bearer\"}"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
})
|
||||||
// Handle request to validate token
|
// Handle request to validate token
|
||||||
mux.HandleFunc("/identity-manager/api/v2/auth/token/validity", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/identity-manager/api/v2/auth/token/validity", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := w.Write([]byte("{\"valid\": \"true\"}"))
|
_, err := w.Write([]byte("{\"valid\": \"true\"}"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
})
|
||||||
// Handle request to create subscription
|
// Handle request to create subscription
|
||||||
mux.HandleFunc(path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc(path, func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
_, err := w.Write([]byte("201 created"))
|
_, err := w.Write([]byte("201 created"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
})
|
||||||
// Handle request to fetch sse data
|
// Handle request to fetch sse data
|
||||||
mux.HandleFunc(path+"/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc(path+"/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodGet {
|
if r.Method == http.MethodGet {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write([]byte("event: update\n"))
|
_, err := w.Write([]byte("event: update\n"))
|
||||||
|
|
@ -157,7 +158,7 @@ func newServer(t *testing.T) *httptest.Server {
|
||||||
_, err = w.Write([]byte("\n"))
|
_, err = w.Write([]byte("\n"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
}))
|
})
|
||||||
return httptest.NewServer(mux)
|
return httptest.NewServer(mux)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
jwt "github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
|
|
@ -53,7 +53,7 @@ func TestLogin(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(tt.responseCode)
|
w.WriteHeader(tt.responseCode)
|
||||||
fmt.Fprintln(w, tt.responseBody)
|
fmt.Fprintln(w, tt.responseBody)
|
||||||
})
|
})
|
||||||
|
|
@ -126,7 +126,7 @@ func TestGetSummary(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
// check the path
|
// check the path
|
||||||
w.WriteHeader(tt.responseCode)
|
w.WriteHeader(tt.responseCode)
|
||||||
fmt.Fprintln(w, tt.responseBody)
|
fmt.Fprintln(w, tt.responseBody)
|
||||||
|
|
@ -167,7 +167,7 @@ func TestGetNodeMetrics(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
// check the path
|
// check the path
|
||||||
w.WriteHeader(tt.responseCode)
|
w.WriteHeader(tt.responseCode)
|
||||||
fmt.Fprintln(w, tt.responseBody)
|
fmt.Fprintln(w, tt.responseBody)
|
||||||
|
|
@ -208,7 +208,7 @@ func TestGetContainerMetrics(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
// check the path
|
// check the path
|
||||||
w.WriteHeader(tt.responseCode)
|
w.WriteHeader(tt.responseCode)
|
||||||
fmt.Fprintln(w, tt.responseBody)
|
fmt.Fprintln(w, tt.responseBody)
|
||||||
|
|
|
||||||
|
|
@ -11,33 +11,33 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type mockClient struct {
|
type mockClient struct {
|
||||||
SetTokenF func(token string)
|
SetTokenF func()
|
||||||
LoginF func(ctx context.Context, sa *ServiceAccount) (*AuthToken, error)
|
LoginF func(ctx context.Context, sa *ServiceAccount) (*AuthToken, error)
|
||||||
GetSummaryF func(ctx context.Context) (*Summary, error)
|
GetSummaryF func() (*Summary, error)
|
||||||
GetContainersF func(ctx context.Context, node string) ([]Container, error)
|
GetContainersF func() ([]Container, error)
|
||||||
GetNodeMetricsF func(ctx context.Context, node string) (*Metrics, error)
|
GetNodeMetricsF func() (*Metrics, error)
|
||||||
GetContainerMetricsF func(ctx context.Context, node, container string) (*Metrics, error)
|
GetContainerMetricsF func(ctx context.Context, node, container string) (*Metrics, error)
|
||||||
GetAppMetricsF func(ctx context.Context, node, container string) (*Metrics, error)
|
GetAppMetricsF func(ctx context.Context, node, container string) (*Metrics, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) SetToken(token string) {
|
func (c *mockClient) SetToken(string) {
|
||||||
c.SetTokenF(token)
|
c.SetTokenF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) Login(ctx context.Context, sa *ServiceAccount) (*AuthToken, error) {
|
func (c *mockClient) Login(ctx context.Context, sa *ServiceAccount) (*AuthToken, error) {
|
||||||
return c.LoginF(ctx, sa)
|
return c.LoginF(ctx, sa)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) GetSummary(ctx context.Context) (*Summary, error) {
|
func (c *mockClient) GetSummary(context.Context) (*Summary, error) {
|
||||||
return c.GetSummaryF(ctx)
|
return c.GetSummaryF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) GetContainers(ctx context.Context, node string) ([]Container, error) {
|
func (c *mockClient) GetContainers(context.Context, string) ([]Container, error) {
|
||||||
return c.GetContainersF(ctx, node)
|
return c.GetContainersF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) GetNodeMetrics(ctx context.Context, node string) (*Metrics, error) {
|
func (c *mockClient) GetNodeMetrics(context.Context, string) (*Metrics, error) {
|
||||||
return c.GetNodeMetricsF(ctx, node)
|
return c.GetNodeMetricsF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *mockClient) GetContainerMetrics(ctx context.Context, node, container string) (*Metrics, error) {
|
func (c *mockClient) GetContainerMetrics(ctx context.Context, node, container string) (*Metrics, error) {
|
||||||
|
|
@ -362,8 +362,8 @@ func TestGatherFilterNode(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "cluster without nodes has no metrics",
|
name: "cluster without nodes has no metrics",
|
||||||
client: &mockClient{
|
client: &mockClient{
|
||||||
SetTokenF: func(token string) {},
|
SetTokenF: func() {},
|
||||||
GetSummaryF: func(ctx context.Context) (*Summary, error) {
|
GetSummaryF: func() (*Summary, error) {
|
||||||
return &Summary{
|
return &Summary{
|
||||||
Cluster: "a",
|
Cluster: "a",
|
||||||
Slaves: []Slave{},
|
Slaves: []Slave{},
|
||||||
|
|
@ -380,8 +380,8 @@ func TestGatherFilterNode(t *testing.T) {
|
||||||
name: "node include",
|
name: "node include",
|
||||||
nodeInclude: []string{"x"},
|
nodeInclude: []string{"x"},
|
||||||
client: &mockClient{
|
client: &mockClient{
|
||||||
SetTokenF: func(token string) {},
|
SetTokenF: func() {},
|
||||||
GetSummaryF: func(ctx context.Context) (*Summary, error) {
|
GetSummaryF: func() (*Summary, error) {
|
||||||
return &Summary{
|
return &Summary{
|
||||||
Cluster: "a",
|
Cluster: "a",
|
||||||
Slaves: []Slave{
|
Slaves: []Slave{
|
||||||
|
|
@ -390,10 +390,10 @@ func TestGatherFilterNode(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
GetContainersF: func(ctx context.Context, node string) ([]Container, error) {
|
GetContainersF: func() ([]Container, error) {
|
||||||
return []Container{}, nil
|
return []Container{}, nil
|
||||||
},
|
},
|
||||||
GetNodeMetricsF: func(ctx context.Context, node string) (*Metrics, error) {
|
GetNodeMetricsF: func() (*Metrics, error) {
|
||||||
return &Metrics{
|
return &Metrics{
|
||||||
Datapoints: []DataPoint{
|
Datapoints: []DataPoint{
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ func (monitor *DirectoryMonitor) Gather(_ telegraf.Accumulator) error {
|
||||||
|
|
||||||
if monitor.Recursive {
|
if monitor.Recursive {
|
||||||
err := filepath.Walk(monitor.Directory,
|
err := filepath.Walk(monitor.Directory,
|
||||||
func(path string, info os.FileInfo, err error) error {
|
func(path string, _ os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,70 +22,48 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockClient struct {
|
type MockClient struct {
|
||||||
InfoF func(ctx context.Context) (system.Info, error)
|
InfoF func() (system.Info, error)
|
||||||
ContainerListF func(ctx context.Context, options typeContainer.ListOptions) ([]types.Container, error)
|
ContainerListF func(options typeContainer.ListOptions) ([]types.Container, error)
|
||||||
ContainerStatsF func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)
|
ContainerStatsF func(containerID string) (types.ContainerStats, error)
|
||||||
ContainerInspectF func(ctx context.Context, containerID string) (types.ContainerJSON, error)
|
ContainerInspectF func() (types.ContainerJSON, error)
|
||||||
ServiceListF func(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
|
ServiceListF func() ([]swarm.Service, error)
|
||||||
TaskListF func(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
|
TaskListF func() ([]swarm.Task, error)
|
||||||
NodeListF func(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
|
NodeListF func() ([]swarm.Node, error)
|
||||||
DiskUsageF func(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
|
DiskUsageF func() (types.DiskUsage, error)
|
||||||
ClientVersionF func() string
|
ClientVersionF func() string
|
||||||
CloseF func() error
|
CloseF func() error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) Info(ctx context.Context) (system.Info, error) {
|
func (c *MockClient) Info(context.Context) (system.Info, error) {
|
||||||
return c.InfoF(ctx)
|
return c.InfoF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerList(
|
func (c *MockClient) ContainerList(_ context.Context, options typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
ctx context.Context,
|
return c.ContainerListF(options)
|
||||||
options typeContainer.ListOptions,
|
|
||||||
) ([]types.Container, error) {
|
|
||||||
return c.ContainerListF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerStats(
|
func (c *MockClient) ContainerStats(_ context.Context, containerID string, _ bool) (types.ContainerStats, error) {
|
||||||
ctx context.Context,
|
return c.ContainerStatsF(containerID)
|
||||||
containerID string,
|
|
||||||
stream bool,
|
|
||||||
) (types.ContainerStats, error) {
|
|
||||||
return c.ContainerStatsF(ctx, containerID, stream)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerInspect(
|
func (c *MockClient) ContainerInspect(context.Context, string) (types.ContainerJSON, error) {
|
||||||
ctx context.Context,
|
return c.ContainerInspectF()
|
||||||
containerID string,
|
|
||||||
) (types.ContainerJSON, error) {
|
|
||||||
return c.ContainerInspectF(ctx, containerID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ServiceList(
|
func (c *MockClient) ServiceList(context.Context, types.ServiceListOptions) ([]swarm.Service, error) {
|
||||||
ctx context.Context,
|
return c.ServiceListF()
|
||||||
options types.ServiceListOptions,
|
|
||||||
) ([]swarm.Service, error) {
|
|
||||||
return c.ServiceListF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) TaskList(
|
func (c *MockClient) TaskList(context.Context, types.TaskListOptions) ([]swarm.Task, error) {
|
||||||
ctx context.Context,
|
return c.TaskListF()
|
||||||
options types.TaskListOptions,
|
|
||||||
) ([]swarm.Task, error) {
|
|
||||||
return c.TaskListF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) NodeList(
|
func (c *MockClient) NodeList(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
|
||||||
ctx context.Context,
|
return c.NodeListF()
|
||||||
options types.NodeListOptions,
|
|
||||||
) ([]swarm.Node, error) {
|
|
||||||
return c.NodeListF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) DiskUsage(
|
func (c *MockClient) DiskUsage(context.Context, types.DiskUsageOptions) (types.DiskUsage, error) {
|
||||||
ctx context.Context,
|
return c.DiskUsageF()
|
||||||
options types.DiskUsageOptions,
|
|
||||||
) (types.DiskUsage, error) {
|
|
||||||
return c.DiskUsageF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ClientVersion() string {
|
func (c *MockClient) ClientVersion() string {
|
||||||
|
|
@ -97,28 +75,28 @@ func (c *MockClient) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var baseClient = MockClient{
|
var baseClient = MockClient{
|
||||||
InfoF: func(context.Context) (system.Info, error) {
|
InfoF: func() (system.Info, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
},
|
},
|
||||||
ContainerListF: func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
ContainerListF: func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
return containerList, nil
|
return containerList, nil
|
||||||
},
|
},
|
||||||
ContainerStatsF: func(c context.Context, s string, b bool) (types.ContainerStats, error) {
|
ContainerStatsF: func(s string) (types.ContainerStats, error) {
|
||||||
return containerStats(s), nil
|
return containerStats(s), nil
|
||||||
},
|
},
|
||||||
ContainerInspectF: func(context.Context, string) (types.ContainerJSON, error) {
|
ContainerInspectF: func() (types.ContainerJSON, error) {
|
||||||
return containerInspect(), nil
|
return containerInspect(), nil
|
||||||
},
|
},
|
||||||
ServiceListF: func(context.Context, types.ServiceListOptions) ([]swarm.Service, error) {
|
ServiceListF: func() ([]swarm.Service, error) {
|
||||||
return ServiceList, nil
|
return ServiceList, nil
|
||||||
},
|
},
|
||||||
TaskListF: func(context.Context, types.TaskListOptions) ([]swarm.Task, error) {
|
TaskListF: func() ([]swarm.Task, error) {
|
||||||
return TaskList, nil
|
return TaskList, nil
|
||||||
},
|
},
|
||||||
NodeListF: func(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
|
NodeListF: func() ([]swarm.Node, error) {
|
||||||
return NodeList, nil
|
return NodeList, nil
|
||||||
},
|
},
|
||||||
DiskUsageF: func(context.Context, types.DiskUsageOptions) (types.DiskUsage, error) {
|
DiskUsageF: func() (types.DiskUsage, error) {
|
||||||
return diskUsage, nil
|
return diskUsage, nil
|
||||||
},
|
},
|
||||||
ClientVersionF: func() string {
|
ClientVersionF: func() string {
|
||||||
|
|
@ -445,28 +423,28 @@ func TestDocker_WindowsMemoryContainerStats(t *testing.T) {
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
newClient: func(string, *tls.Config) (Client, error) {
|
newClient: func(string, *tls.Config) (Client, error) {
|
||||||
return &MockClient{
|
return &MockClient{
|
||||||
InfoF: func(ctx context.Context) (system.Info, error) {
|
InfoF: func() (system.Info, error) {
|
||||||
return info, nil
|
return info, nil
|
||||||
},
|
},
|
||||||
ContainerListF: func(ctx context.Context, options typeContainer.ListOptions) ([]types.Container, error) {
|
ContainerListF: func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
return containerList, nil
|
return containerList, nil
|
||||||
},
|
},
|
||||||
ContainerStatsF: func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
ContainerStatsF: func(string) (types.ContainerStats, error) {
|
||||||
return containerStatsWindows(), nil
|
return containerStatsWindows(), nil
|
||||||
},
|
},
|
||||||
ContainerInspectF: func(ctx context.Context, containerID string) (types.ContainerJSON, error) {
|
ContainerInspectF: func() (types.ContainerJSON, error) {
|
||||||
return containerInspect(), nil
|
return containerInspect(), nil
|
||||||
},
|
},
|
||||||
ServiceListF: func(context.Context, types.ServiceListOptions) ([]swarm.Service, error) {
|
ServiceListF: func() ([]swarm.Service, error) {
|
||||||
return ServiceList, nil
|
return ServiceList, nil
|
||||||
},
|
},
|
||||||
TaskListF: func(context.Context, types.TaskListOptions) ([]swarm.Task, error) {
|
TaskListF: func() ([]swarm.Task, error) {
|
||||||
return TaskList, nil
|
return TaskList, nil
|
||||||
},
|
},
|
||||||
NodeListF: func(context.Context, types.NodeListOptions) ([]swarm.Node, error) {
|
NodeListF: func() ([]swarm.Node, error) {
|
||||||
return NodeList, nil
|
return NodeList, nil
|
||||||
},
|
},
|
||||||
DiskUsageF: func(context.Context, types.DiskUsageOptions) (types.DiskUsage, error) {
|
DiskUsageF: func() (types.DiskUsage, error) {
|
||||||
return diskUsage, nil
|
return diskUsage, nil
|
||||||
},
|
},
|
||||||
ClientVersionF: func() string {
|
ClientVersionF: func() string {
|
||||||
|
|
@ -581,9 +559,9 @@ func TestContainerLabels(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
newClientFunc := func(host string, tlsConfig *tls.Config) (Client, error) {
|
newClientFunc := func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
return []types.Container{tt.container}, nil
|
return []types.Container{tt.container}, nil
|
||||||
}
|
}
|
||||||
return &client, nil
|
return &client, nil
|
||||||
|
|
@ -701,12 +679,12 @@ func TestContainerNames(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
newClientFunc := func(host string, tlsConfig *tls.Config) (Client, error) {
|
newClientFunc := func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
return containerList, nil
|
return containerList, nil
|
||||||
}
|
}
|
||||||
client.ContainerStatsF = func(c context.Context, s string, b bool) (types.ContainerStats, error) {
|
client.ContainerStatsF = func(s string) (types.ContainerStats, error) {
|
||||||
return containerStats(s), nil
|
return containerStats(s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -913,10 +891,10 @@ func TestContainerStatus(t *testing.T) {
|
||||||
acc testutil.Accumulator
|
acc testutil.Accumulator
|
||||||
newClientFunc = func(string, *tls.Config) (Client, error) {
|
newClientFunc = func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
return containerList[:1], nil
|
return containerList[:1], nil
|
||||||
}
|
}
|
||||||
client.ContainerInspectF = func(c context.Context, s string) (types.ContainerJSON, error) {
|
client.ContainerInspectF = func() (types.ContainerJSON, error) {
|
||||||
return tt.inspect, nil
|
return tt.inspect, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1196,9 +1174,9 @@ func TestContainerStateFilter(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
newClientFunc := func(host string, tlsConfig *tls.Config) (Client, error) {
|
newClientFunc := func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(ctx context.Context, options typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(options typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
for k, v := range tt.expected {
|
for k, v := range tt.expected {
|
||||||
actual := options.Filters.Get(k)
|
actual := options.Filters.Get(k)
|
||||||
sort.Strings(actual)
|
sort.Strings(actual)
|
||||||
|
|
@ -1232,16 +1210,16 @@ func TestContainerName(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "container stats name is preferred",
|
name: "container stats name is preferred",
|
||||||
clientFunc: func(host string, tlsConfig *tls.Config) (Client, error) {
|
clientFunc: func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
var containers []types.Container
|
var containers []types.Container
|
||||||
containers = append(containers, types.Container{
|
containers = append(containers, types.Container{
|
||||||
Names: []string{"/logspout/foo"},
|
Names: []string{"/logspout/foo"},
|
||||||
})
|
})
|
||||||
return containers, nil
|
return containers, nil
|
||||||
}
|
}
|
||||||
client.ContainerStatsF = func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
client.ContainerStatsF = func(string) (types.ContainerStats, error) {
|
||||||
return types.ContainerStats{
|
return types.ContainerStats{
|
||||||
Body: io.NopCloser(strings.NewReader(`{"name": "logspout"}`)),
|
Body: io.NopCloser(strings.NewReader(`{"name": "logspout"}`)),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -1252,16 +1230,16 @@ func TestContainerName(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "container stats without name uses container list name",
|
name: "container stats without name uses container list name",
|
||||||
clientFunc: func(host string, tlsConfig *tls.Config) (Client, error) {
|
clientFunc: func(string, *tls.Config) (Client, error) {
|
||||||
client := baseClient
|
client := baseClient
|
||||||
client.ContainerListF = func(context.Context, typeContainer.ListOptions) ([]types.Container, error) {
|
client.ContainerListF = func(typeContainer.ListOptions) ([]types.Container, error) {
|
||||||
var containers []types.Container
|
var containers []types.Container
|
||||||
containers = append(containers, types.Container{
|
containers = append(containers, types.Container{
|
||||||
Names: []string{"/logspout"},
|
Names: []string{"/logspout"},
|
||||||
})
|
})
|
||||||
return containers, nil
|
return containers, nil
|
||||||
}
|
}
|
||||||
client.ContainerStatsF = func(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) {
|
client.ContainerStatsF = func(string) (types.ContainerStats, error) {
|
||||||
return types.ContainerStats{
|
return types.ContainerStats{
|
||||||
Body: io.NopCloser(strings.NewReader(`{}`)),
|
Body: io.NopCloser(strings.NewReader(`{}`)),
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
||||||
|
|
@ -11,38 +11,29 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockClient struct {
|
type MockClient struct {
|
||||||
ContainerListF func(ctx context.Context, options container.ListOptions) ([]types.Container, error)
|
ContainerListF func() ([]types.Container, error)
|
||||||
ContainerInspectF func(ctx context.Context, containerID string) (types.ContainerJSON, error)
|
ContainerInspectF func() (types.ContainerJSON, error)
|
||||||
ContainerLogsF func(ctx context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error)
|
ContainerLogsF func() (io.ReadCloser, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerList(
|
func (c *MockClient) ContainerList(context.Context, container.ListOptions) ([]types.Container, error) {
|
||||||
ctx context.Context,
|
return c.ContainerListF()
|
||||||
options container.ListOptions,
|
|
||||||
) ([]types.Container, error) {
|
|
||||||
return c.ContainerListF(ctx, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerInspect(
|
func (c *MockClient) ContainerInspect(context.Context, string) (types.ContainerJSON, error) {
|
||||||
ctx context.Context,
|
return c.ContainerInspectF()
|
||||||
containerID string,
|
|
||||||
) (types.ContainerJSON, error) {
|
|
||||||
return c.ContainerInspectF(ctx, containerID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) ContainerLogs(
|
func (c *MockClient) ContainerLogs(context.Context, string, container.LogsOptions) (io.ReadCloser, error) {
|
||||||
ctx context.Context,
|
return c.ContainerLogsF()
|
||||||
containerID string,
|
|
||||||
options container.LogsOptions,
|
|
||||||
) (io.ReadCloser, error) {
|
|
||||||
return c.ContainerLogsF(ctx, containerID, options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
|
@ -70,7 +61,7 @@ func Test(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "no containers",
|
name: "no containers",
|
||||||
client: &MockClient{
|
client: &MockClient{
|
||||||
ContainerListF: func(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
|
ContainerListF: func() ([]types.Container, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -78,7 +69,7 @@ func Test(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "one container tty",
|
name: "one container tty",
|
||||||
client: &MockClient{
|
client: &MockClient{
|
||||||
ContainerListF: func(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
|
ContainerListF: func() ([]types.Container, error) {
|
||||||
return []types.Container{
|
return []types.Container{
|
||||||
{
|
{
|
||||||
ID: "deadbeef",
|
ID: "deadbeef",
|
||||||
|
|
@ -87,14 +78,14 @@ func Test(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
ContainerInspectF: func(ctx context.Context, containerID string) (types.ContainerJSON, error) {
|
ContainerInspectF: func() (types.ContainerJSON, error) {
|
||||||
return types.ContainerJSON{
|
return types.ContainerJSON{
|
||||||
Config: &container.Config{
|
Config: &container.Config{
|
||||||
Tty: true,
|
Tty: true,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
ContainerLogsF: func(ctx context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error) {
|
ContainerLogsF: func() (io.ReadCloser, error) {
|
||||||
return &Response{Reader: bytes.NewBuffer([]byte("2020-04-28T18:43:16.432691200Z hello\n"))}, nil
|
return &Response{Reader: bytes.NewBuffer([]byte("2020-04-28T18:43:16.432691200Z hello\n"))}, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -119,7 +110,7 @@ func Test(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "one container multiplex",
|
name: "one container multiplex",
|
||||||
client: &MockClient{
|
client: &MockClient{
|
||||||
ContainerListF: func(ctx context.Context, options container.ListOptions) ([]types.Container, error) {
|
ContainerListF: func() ([]types.Container, error) {
|
||||||
return []types.Container{
|
return []types.Container{
|
||||||
{
|
{
|
||||||
ID: "deadbeef",
|
ID: "deadbeef",
|
||||||
|
|
@ -128,14 +119,14 @@ func Test(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
ContainerInspectF: func(ctx context.Context, containerID string) (types.ContainerJSON, error) {
|
ContainerInspectF: func() (types.ContainerJSON, error) {
|
||||||
return types.ContainerJSON{
|
return types.ContainerJSON{
|
||||||
Config: &container.Config{
|
Config: &container.Config{
|
||||||
Tty: false,
|
Tty: false,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
ContainerLogsF: func(ctx context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error) {
|
ContainerLogsF: func() (io.ReadCloser, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
w := stdcopy.NewStdWriter(&buf, stdcopy.Stdout)
|
w := stdcopy.NewStdWriter(&buf, stdcopy.Stdout)
|
||||||
_, err := w.Write([]byte("2020-04-28T18:42:16.432691200Z hello from stdout"))
|
_, err := w.Write([]byte("2020-04-28T18:42:16.432691200Z hello from stdout"))
|
||||||
|
|
|
||||||
|
|
@ -87,11 +87,11 @@ func TestEcsClient_PollSync(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockDo struct {
|
type mockDo struct {
|
||||||
do func(req *http.Request) (*http.Response, error)
|
do func() (*http.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m mockDo) Do(req *http.Request) (*http.Response, error) {
|
func (m mockDo) Do(*http.Request) (*http.Response, error) {
|
||||||
return m.do(req)
|
return m.do()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEcsClient_Task(t *testing.T) {
|
func TestEcsClient_Task(t *testing.T) {
|
||||||
|
|
@ -105,7 +105,7 @@ func TestEcsClient_Task(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "happy",
|
name: "happy",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: io.NopCloser(rc),
|
Body: io.NopCloser(rc),
|
||||||
|
|
@ -117,7 +117,7 @@ func TestEcsClient_Task(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "do err",
|
name: "do err",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return nil, errors.New("err")
|
return nil, errors.New("err")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -126,7 +126,7 @@ func TestEcsClient_Task(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "malformed 500 resp",
|
name: "malformed 500 resp",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusInternalServerError,
|
StatusCode: http.StatusInternalServerError,
|
||||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||||
|
|
@ -138,7 +138,7 @@ func TestEcsClient_Task(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "malformed 200 resp",
|
name: "malformed 200 resp",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||||
|
|
@ -176,7 +176,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "happy",
|
name: "happy",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: io.NopCloser(rc),
|
Body: io.NopCloser(rc),
|
||||||
|
|
@ -188,7 +188,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "do err",
|
name: "do err",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return nil, errors.New("err")
|
return nil, errors.New("err")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -198,7 +198,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "malformed 200 resp",
|
name: "malformed 200 resp",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||||
|
|
@ -211,7 +211,7 @@ func TestEcsClient_ContainerStats(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "malformed 500 resp",
|
name: "malformed 500 resp",
|
||||||
client: mockDo{
|
client: mockDo{
|
||||||
do: func(req *http.Request) (*http.Response, error) {
|
do: func() (*http.Response, error) {
|
||||||
return &http.Response{
|
return &http.Response{
|
||||||
StatusCode: http.StatusInternalServerError,
|
StatusCode: http.StatusInternalServerError,
|
||||||
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
Body: io.NopCloser(bytes.NewReader([]byte("foo"))),
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,6 @@ func Test_mergeTaskStats(t *testing.T) {
|
||||||
mergeTaskStats(parsedMetadata, parsedStats)
|
mergeTaskStats(parsedMetadata, parsedStats)
|
||||||
|
|
||||||
for i := range parsedMetadata.Containers {
|
for i := range parsedMetadata.Containers {
|
||||||
//nolint:testifylint // values are in proper order (expected, actual)
|
|
||||||
require.Equal(t, validStats[parsedMetadata.Containers[i].ID], &parsedMetadata.Containers[i].Stats)
|
require.Equal(t, validStats[parsedMetadata.Containers[i].ID], &parsedMetadata.Containers[i].Stats)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,15 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestUnauthorized validates that 401 (wrong credentials) is managed properly
|
// TestUnauthorized validates that 401 (wrong credentials) is managed properly
|
||||||
func TestUnauthorized(t *testing.T) {
|
func TestUnauthorized(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
|
||||||
oldestFileTimestamp := make(map[string]int64)
|
oldestFileTimestamp := make(map[string]int64)
|
||||||
newestFileTimestamp := make(map[string]int64)
|
newestFileTimestamp := make(map[string]int64)
|
||||||
|
|
||||||
walkFn := func(path string, de *godirwalk.Dirent) error {
|
walkFn := func(path string, _ *godirwalk.Dirent) error {
|
||||||
rel, err := filepath.Rel(basedir, path)
|
rel, err := filepath.Rel(basedir, path)
|
||||||
if err == nil && rel == "." {
|
if err == nil && rel == "." {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -159,7 +159,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
postChildrenFn := func(path string, de *godirwalk.Dirent) error {
|
postChildrenFn := func(path string, _ *godirwalk.Dirent) error {
|
||||||
if glob.MatchString(path) {
|
if glob.MatchString(path) {
|
||||||
gauge := map[string]interface{}{
|
gauge := map[string]interface{}{
|
||||||
"count": childCount[path],
|
"count": childCount[path],
|
||||||
|
|
@ -195,7 +195,7 @@ func (fc *FileCount) count(acc telegraf.Accumulator, basedir string, glob globpa
|
||||||
PostChildrenCallback: postChildrenFn,
|
PostChildrenCallback: postChildrenFn,
|
||||||
Unsorted: true,
|
Unsorted: true,
|
||||||
FollowSymbolicLinks: fc.FollowSymlinks,
|
FollowSymbolicLinks: fc.FollowSymlinks,
|
||||||
ErrorCallback: func(osPathname string, err error) godirwalk.ErrorAction {
|
ErrorCallback: func(_ string, err error) godirwalk.ErrorAction {
|
||||||
if errors.Is(err, fs.ErrPermission) {
|
if errors.Is(err, fs.ErrPermission) {
|
||||||
fc.Log.Debug(err)
|
fc.Log.Debug(err)
|
||||||
return godirwalk.SkipNode
|
return godirwalk.SkipNode
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,14 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFireboard(t *testing.T) {
|
func TestFireboard(t *testing.T) {
|
||||||
// Create a test server with the const response JSON
|
// Create a test server with the const response JSON
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, response)
|
_, err := fmt.Fprintln(w, response)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ func Test_parse(t *testing.T) {
|
||||||
func Test_Gather(t *testing.T) {
|
func Test_Gather(t *testing.T) {
|
||||||
t.Logf("Start HTTP mock (%s) with sampleJSON", fluentdTest.Endpoint)
|
t.Logf("Start HTTP mock (%s) with sampleJSON", fluentdTest.Endpoint)
|
||||||
|
|
||||||
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(w, "%s", string(sampleJSON))
|
_, err := fmt.Fprintf(w, "%s", string(sampleJSON))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ func TestWaitError(t *testing.T) {
|
||||||
|
|
||||||
grpcServer := grpc.NewServer()
|
grpcServer := grpc.NewServer()
|
||||||
gnmiServer := &MockServer{
|
gnmiServer := &MockServer{
|
||||||
SubscribeF: func(server gnmiLib.GNMI_SubscribeServer) error {
|
SubscribeF: func(gnmiLib.GNMI_SubscribeServer) error {
|
||||||
return errors.New("testerror")
|
return errors.New("testerror")
|
||||||
},
|
},
|
||||||
GRPCServer: grpcServer,
|
GRPCServer: grpcServer,
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ func TestHaproxyGeneratesMetricsWithAuthentication(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHaproxyGeneratesMetricsWithoutAuthentication(t *testing.T) {
|
func TestHaproxyGeneratesMetricsWithoutAuthentication(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprint(w, string(csvOutputSample))
|
_, err := fmt.Fprint(w, string(csvOutputSample))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -213,7 +213,7 @@ func TestHaproxyDefaultGetFromLocalhost(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHaproxyKeepFieldNames(t *testing.T) {
|
func TestHaproxyKeepFieldNames(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprint(w, string(csvOutputSample))
|
_, err := fmt.Fprint(w, string(csvOutputSample))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ func TestHTTPContentLengthHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidStatusCode(t *testing.T) {
|
func TestInvalidStatusCode(t *testing.T) {
|
||||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}))
|
}))
|
||||||
defer fakeServer.Close()
|
defer fakeServer.Close()
|
||||||
|
|
@ -158,7 +158,7 @@ func TestInvalidStatusCode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSuccessStatusCodes(t *testing.T) {
|
func TestSuccessStatusCodes(t *testing.T) {
|
||||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusAccepted)
|
w.WriteHeader(http.StatusAccepted)
|
||||||
}))
|
}))
|
||||||
defer fakeServer.Close()
|
defer fakeServer.Close()
|
||||||
|
|
@ -356,7 +356,7 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
|
||||||
},
|
},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Add("access_token", token)
|
values.Add("access_token", token)
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ func getProxyFunc(httpProxy string) func(*http.Request) (*url.URL, error) {
|
||||||
return nil, errors.New("bad proxy: " + err.Error())
|
return nil, errors.New("bad proxy: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return func(r *http.Request) (*url.URL, error) {
|
return func(*http.Request) (*url.URL, error) {
|
||||||
return proxyURL, nil
|
return proxyURL, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,7 +110,7 @@ func (h *HTTPResponse) createHTTPClient() (*http.Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !h.FollowRedirects {
|
if !h.FollowRedirects {
|
||||||
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
|
client.CheckRedirect = func(*http.Request, []*http.Request) error {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ func setUpTestMux() http.Handler {
|
||||||
mux.HandleFunc("/redirect", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/redirect", func(w http.ResponseWriter, req *http.Request) {
|
||||||
http.Redirect(w, req, "/good", http.StatusMovedPermanently)
|
http.Redirect(w, req, "/good", http.StatusMovedPermanently)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/good", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/good", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Server", "MyTestServer")
|
w.Header().Set("Server", "MyTestServer")
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
|
|
@ -112,13 +112,13 @@ func setUpTestMux() http.Handler {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/invalidUTF8", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck // ignore the returned error as the test will fail anyway
|
w.Write([]byte{0xff, 0xfe, 0xfd}) //nolint:errcheck // ignore the returned error as the test will fail anyway
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/noheader", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/noheader", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
fmt.Fprintf(w, "hit the good page!")
|
fmt.Fprintf(w, "hit the good page!")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/jsonresponse", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/jsonresponse", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
fmt.Fprintf(w, "\"service_status\": \"up\", \"healthy\" : \"true\"")
|
fmt.Fprintf(w, "\"service_status\": \"up\", \"healthy\" : \"true\"")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/badredirect", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/badredirect", func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
@ -144,7 +144,7 @@ func setUpTestMux() http.Handler {
|
||||||
}
|
}
|
||||||
fmt.Fprintf(w, "sent a body!")
|
fmt.Fprintf(w, "sent a body!")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/twosecondnap", func(w http.ResponseWriter, req *http.Request) {
|
mux.HandleFunc("/twosecondnap", func(http.ResponseWriter, *http.Request) {
|
||||||
time.Sleep(time.Second * 2)
|
time.Sleep(time.Second * 2)
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/nocontent", func(w http.ResponseWriter, _ *http.Request) {
|
mux.HandleFunc("/nocontent", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
|
|
@ -1109,7 +1109,7 @@ func TestRedirect(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.NotFoundHandler())
|
ts := httptest.NewServer(http.NotFoundHandler())
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Add("Location", "http://example.org")
|
w.Header().Add("Location", "http://example.org")
|
||||||
w.WriteHeader(http.StatusMovedPermanently)
|
w.WriteHeader(http.StatusMovedPermanently)
|
||||||
_, err := w.Write([]byte("test"))
|
_, err := w.Write([]byte("test"))
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ func TestErrorHandling404(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorResponse(t *testing.T) {
|
func TestErrorResponse(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusUnauthorized)
|
w.WriteHeader(http.StatusUnauthorized)
|
||||||
_, err := w.Write([]byte(`{"error": "unable to parse authentication credentials"}`))
|
_, err := w.Write([]byte(`{"error": "unable to parse authentication credentials"}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ func (h *InfluxDBListener) ServeHTTP(res http.ResponseWriter, req *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *InfluxDBListener) handleQuery() http.HandlerFunc {
|
func (h *InfluxDBListener) handleQuery() http.HandlerFunc {
|
||||||
return func(res http.ResponseWriter, req *http.Request) {
|
return func(res http.ResponseWriter, _ *http.Request) {
|
||||||
defer h.queriesServed.Incr(1)
|
defer h.queriesServed.Incr(1)
|
||||||
// Deliver a dummy response to the query endpoint, as some InfluxDB
|
// Deliver a dummy response to the query endpoint, as some InfluxDB
|
||||||
// clients test endpoint availability with a query
|
// clients test endpoint availability with a query
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ func (h *InfluxDBV2Listener) ServeHTTP(res http.ResponseWriter, req *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *InfluxDBV2Listener) handleReady() http.HandlerFunc {
|
func (h *InfluxDBV2Listener) handleReady() http.HandlerFunc {
|
||||||
return func(res http.ResponseWriter, req *http.Request) {
|
return func(res http.ResponseWriter, _ *http.Request) {
|
||||||
defer h.readysServed.Incr(1)
|
defer h.readysServed.Incr(1)
|
||||||
|
|
||||||
// respond to ready requests
|
// respond to ready requests
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func TestIpset(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
i++
|
i++
|
||||||
ips := &Ipset{
|
ips := &Ipset{
|
||||||
lister: func(timeout config.Duration, useSudo bool) (*bytes.Buffer, error) {
|
lister: func(config.Duration, bool) (*bytes.Buffer, error) {
|
||||||
return bytes.NewBufferString(tt.value), nil
|
return bytes.NewBufferString(tt.value), nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +138,7 @@ func TestIpset(t *testing.T) {
|
||||||
func TestIpset_Gather_listerError(t *testing.T) {
|
func TestIpset_Gather_listerError(t *testing.T) {
|
||||||
errFoo := errors.New("error foobar")
|
errFoo := errors.New("error foobar")
|
||||||
ips := &Ipset{
|
ips := &Ipset{
|
||||||
lister: func(timeout config.Duration, useSudo bool) (*bytes.Buffer, error) {
|
lister: func(config.Duration, bool) (*bytes.Buffer, error) {
|
||||||
return new(bytes.Buffer), errFoo
|
return new(bytes.Buffer), errFoo
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ func TestIptables_Gather(t *testing.T) {
|
||||||
ipt := &Iptables{
|
ipt := &Iptables{
|
||||||
Table: tt.table,
|
Table: tt.table,
|
||||||
Chains: tt.chains,
|
Chains: tt.chains,
|
||||||
lister: func(table, chain string) (string, error) {
|
lister: func(string, string) (string, error) {
|
||||||
if len(tt.values) > 0 {
|
if len(tt.values) > 0 {
|
||||||
v := tt.values[0]
|
v := tt.values[0]
|
||||||
tt.values = tt.values[1:]
|
tt.values = tt.values[1:]
|
||||||
|
|
@ -241,7 +241,7 @@ func TestIptables_Gather_listerError(t *testing.T) {
|
||||||
ipt := &Iptables{
|
ipt := &Iptables{
|
||||||
Table: "nat",
|
Table: "nat",
|
||||||
Chains: []string{"foo", "bar"},
|
Chains: []string{"foo", "bar"},
|
||||||
lister: func(table, chain string) (string, error) {
|
lister: func(string, string) (string, error) {
|
||||||
return "", errFoo
|
return "", errFoo
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -830,7 +830,7 @@ func TestIntegrationArtemis(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupServer(resp string) *httptest.Server {
|
func setupServer(resp string) *httptest.Server {
|
||||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintln(w, resp)
|
fmt.Fprintln(w, resp)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func TestFillFields(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupServer(resp string) *httptest.Server {
|
func setupServer(resp string) *httptest.Server {
|
||||||
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintln(w, resp)
|
fmt.Fprintln(w, resp)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestKapacitor(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMissingStats(t *testing.T) {
|
func TestMissingStats(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := w.Write([]byte(`{}`))
|
_, err := w.Write([]byte(`{}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -117,7 +117,7 @@ func TestErrorHandling(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorHandling404(t *testing.T) {
|
func TestErrorHandling404(t *testing.T) {
|
||||||
badServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
badServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}))
|
}))
|
||||||
defer badServer.Close()
|
defer badServer.Close()
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@ func (k *Kubernetes) LoadJSON(url string, v interface{}) error {
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSClientConfig: tlsCfg,
|
TLSClientConfig: tlsCfg,
|
||||||
},
|
},
|
||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
CheckRedirect: func(*http.Request, []*http.Request) error {
|
||||||
return http.ErrUseLastResponse
|
return http.ErrUseLastResponse
|
||||||
},
|
},
|
||||||
Timeout: time.Duration(k.ResponseTimeout),
|
Timeout: time.Duration(k.ResponseTimeout),
|
||||||
|
|
|
||||||
|
|
@ -313,10 +313,6 @@ func TestLibvirt_filterDomains(t *testing.T) {
|
||||||
result := l.filterDomains(domains)
|
result := l.filterDomains(domains)
|
||||||
require.NotEmpty(t, result)
|
require.NotEmpty(t, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("failed on something", func(t *testing.T) {
|
|
||||||
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logstashTest = NewLogstash()
|
var logstashTest = NewLogstash()
|
||||||
|
|
@ -25,7 +26,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Logstash5GatherProcessStats(test *testing.T) {
|
func Test_Logstash5GatherProcessStats(test *testing.T) {
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash5ProcessJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash5ProcessJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -70,7 +71,7 @@ func Test_Logstash5GatherProcessStats(test *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Logstash6GatherProcessStats(test *testing.T) {
|
func Test_Logstash6GatherProcessStats(test *testing.T) {
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash6ProcessJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash6ProcessJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -116,7 +117,7 @@ func Test_Logstash6GatherProcessStats(test *testing.T) {
|
||||||
|
|
||||||
func Test_Logstash5GatherPipelineStats(test *testing.T) {
|
func Test_Logstash5GatherPipelineStats(test *testing.T) {
|
||||||
logstash5accPipelineStats.SetDebug(true)
|
logstash5accPipelineStats.SetDebug(true)
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash5PipelineJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash5PipelineJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -214,7 +215,7 @@ func Test_Logstash5GatherPipelineStats(test *testing.T) {
|
||||||
|
|
||||||
func Test_Logstash6GatherPipelinesStats(test *testing.T) {
|
func Test_Logstash6GatherPipelinesStats(test *testing.T) {
|
||||||
logstash6accPipelinesStats.SetDebug(true)
|
logstash6accPipelinesStats.SetDebug(true)
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash6PipelinesJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash6PipelinesJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -556,7 +557,7 @@ func Test_Logstash6GatherPipelinesStats(test *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Logstash5GatherJVMStats(test *testing.T) {
|
func Test_Logstash5GatherJVMStats(test *testing.T) {
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash5JvmJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash5JvmJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -620,7 +621,7 @@ func Test_Logstash5GatherJVMStats(test *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Logstash6GatherJVMStats(test *testing.T) {
|
func Test_Logstash6GatherJVMStats(test *testing.T) {
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash6JvmJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash6JvmJSON))
|
||||||
require.NoError(test, err)
|
require.NoError(test, err)
|
||||||
|
|
@ -684,7 +685,7 @@ func Test_Logstash6GatherJVMStats(test *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Logstash7GatherPipelinesQueueStats(test *testing.T) {
|
func Test_Logstash7GatherPipelinesQueueStats(test *testing.T) {
|
||||||
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
fakeServer := httptest.NewUnstartedServer(http.HandlerFunc(func(writer http.ResponseWriter, _ *http.Request) {
|
||||||
writer.Header().Set("Content-Type", "application/json")
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
_, err := fmt.Fprintf(writer, "%s", string(logstash7PipelinesJSON))
|
_, err := fmt.Fprintf(writer, "%s", string(logstash7PipelinesJSON))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
func TestMailChimpGatherReports(t *testing.T) {
|
func TestMailChimpGatherReports(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(
|
http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, sampleReports)
|
_, err := fmt.Fprintln(w, sampleReports)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -80,7 +80,7 @@ func TestMailChimpGatherReports(t *testing.T) {
|
||||||
func TestMailChimpGatherReport(t *testing.T) {
|
func TestMailChimpGatherReport(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(
|
http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, sampleReport)
|
_, err := fmt.Fprintln(w, sampleReport)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -146,7 +146,7 @@ func TestMailChimpGatherReport(t *testing.T) {
|
||||||
func TestMailChimpGatherError(t *testing.T) {
|
func TestMailChimpGatherError(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(
|
http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, sampleError)
|
_, err := fmt.Fprintln(w, sampleError)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMarklogic(t *testing.T) {
|
func TestMarklogic(t *testing.T) {
|
||||||
// Create a test server with the const response JSON
|
// Create a test server with the const response JSON
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, response)
|
_, err := fmt.Fprintln(w, response)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -285,7 +285,7 @@ func TestMain(m *testing.M) {
|
||||||
generateMetrics()
|
generateMetrics()
|
||||||
|
|
||||||
masterRouter := http.NewServeMux()
|
masterRouter := http.NewServeMux()
|
||||||
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
masterRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(masterMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(masterMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
|
|
@ -293,7 +293,7 @@ func TestMain(m *testing.M) {
|
||||||
masterTestServer = httptest.NewServer(masterRouter)
|
masterTestServer = httptest.NewServer(masterRouter)
|
||||||
|
|
||||||
slaveRouter := http.NewServeMux()
|
slaveRouter := http.NewServeMux()
|
||||||
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, r *http.Request) {
|
slaveRouter.HandleFunc("/metrics/snapshot", func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(slaveMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
json.NewEncoder(w).Encode(slaveMetrics) //nolint:errcheck // ignore the returned error as we cannot do anything about it anyway
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,11 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
mb "github.com/grid-x/modbus"
|
mb "github.com/grid-x/modbus"
|
||||||
"github.com/influxdata/telegraf"
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tbrandon/mbserver"
|
"github.com/tbrandon/mbserver"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRequest(t *testing.T) {
|
func TestRequest(t *testing.T) {
|
||||||
|
|
@ -2300,7 +2301,7 @@ func TestRequestMultipleSlavesOneFail(t *testing.T) {
|
||||||
defer serv.Close()
|
defer serv.Close()
|
||||||
|
|
||||||
serv.RegisterFunctionHandler(3,
|
serv.RegisterFunctionHandler(3,
|
||||||
func(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
func(_ *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
||||||
tcpframe, ok := frame.(*mbserver.TCPFrame)
|
tcpframe, ok := frame.(*mbserver.TCPFrame)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &mbserver.IllegalFunction
|
return nil, &mbserver.IllegalFunction
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,9 @@ func TestRetrySuccessful(t *testing.T) {
|
||||||
require.NoError(t, serv.ListenTCP("localhost:1502"))
|
require.NoError(t, serv.ListenTCP("localhost:1502"))
|
||||||
defer serv.Close()
|
defer serv.Close()
|
||||||
|
|
||||||
// Make read on coil-registers fail for some trials by making the device
|
// Make read on coil-registers fail for some trials by making the device to appear busy
|
||||||
// to appear busy
|
|
||||||
serv.RegisterFunctionHandler(1,
|
serv.RegisterFunctionHandler(1,
|
||||||
func(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
func(*mbserver.Server, mbserver.Framer) ([]byte, *mbserver.Exception) {
|
||||||
data := make([]byte, 2)
|
data := make([]byte, 2)
|
||||||
data[0] = byte(1)
|
data[0] = byte(1)
|
||||||
data[1] = byte(value)
|
data[1] = byte(value)
|
||||||
|
|
@ -221,7 +220,7 @@ func TestRetryFailExhausted(t *testing.T) {
|
||||||
|
|
||||||
// Make the read on coils fail with busy
|
// Make the read on coils fail with busy
|
||||||
serv.RegisterFunctionHandler(1,
|
serv.RegisterFunctionHandler(1,
|
||||||
func(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
func(*mbserver.Server, mbserver.Framer) ([]byte, *mbserver.Exception) {
|
||||||
data := make([]byte, 2)
|
data := make([]byte, 2)
|
||||||
data[0] = byte(1)
|
data[0] = byte(1)
|
||||||
data[1] = byte(0)
|
data[1] = byte(0)
|
||||||
|
|
@ -262,7 +261,7 @@ func TestRetryFailIllegal(t *testing.T) {
|
||||||
// Make the read on coils fail with illegal function preventing retry
|
// Make the read on coils fail with illegal function preventing retry
|
||||||
counter := 0
|
counter := 0
|
||||||
serv.RegisterFunctionHandler(1,
|
serv.RegisterFunctionHandler(1,
|
||||||
func(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
func(*mbserver.Server, mbserver.Framer) ([]byte, *mbserver.Exception) {
|
||||||
counter++
|
counter++
|
||||||
data := make([]byte, 2)
|
data := make([]byte, 2)
|
||||||
data[0] = byte(1)
|
data[0] = byte(1)
|
||||||
|
|
@ -315,7 +314,7 @@ func TestCases(t *testing.T) {
|
||||||
inputs.Add("modbus", func() telegraf.Input { return &Modbus{} })
|
inputs.Add("modbus", func() telegraf.Input { return &Modbus{} })
|
||||||
|
|
||||||
// Define a function to return the register value as data
|
// Define a function to return the register value as data
|
||||||
readFunc := func(s *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
readFunc := func(_ *mbserver.Server, frame mbserver.Framer) ([]byte, *mbserver.Exception) {
|
||||||
data := frame.GetData()
|
data := frame.GetData()
|
||||||
register := binary.BigEndian.Uint16(data[0:2])
|
register := binary.BigEndian.Uint16(data[0:2])
|
||||||
numRegs := binary.BigEndian.Uint16(data[2:4])
|
numRegs := binary.BigEndian.Uint16(data[2:4])
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ import (
|
||||||
|
|
||||||
type FakeClient struct {
|
type FakeClient struct {
|
||||||
ConnectF func() mqtt.Token
|
ConnectF func() mqtt.Token
|
||||||
SubscribeMultipleF func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token
|
SubscribeMultipleF func() mqtt.Token
|
||||||
AddRouteF func(topic string, callback mqtt.MessageHandler)
|
AddRouteF func(callback mqtt.MessageHandler)
|
||||||
DisconnectF func(quiesce uint)
|
DisconnectF func()
|
||||||
|
|
||||||
connectCallCount int
|
connectCallCount int
|
||||||
subscribeCallCount int
|
subscribeCallCount int
|
||||||
|
|
@ -30,19 +30,19 @@ func (c *FakeClient) Connect() mqtt.Token {
|
||||||
return c.ConnectF()
|
return c.ConnectF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeClient) SubscribeMultiple(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
func (c *FakeClient) SubscribeMultiple(map[string]byte, mqtt.MessageHandler) mqtt.Token {
|
||||||
c.subscribeCallCount++
|
c.subscribeCallCount++
|
||||||
return c.SubscribeMultipleF(filters, callback)
|
return c.SubscribeMultipleF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeClient) AddRoute(topic string, callback mqtt.MessageHandler) {
|
func (c *FakeClient) AddRoute(_ string, callback mqtt.MessageHandler) {
|
||||||
c.addRouteCallCount++
|
c.addRouteCallCount++
|
||||||
c.AddRouteF(topic, callback)
|
c.AddRouteF(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *FakeClient) Disconnect(quiesce uint) {
|
func (c *FakeClient) Disconnect(uint) {
|
||||||
c.disconnectCallCount++
|
c.disconnectCallCount++
|
||||||
c.DisconnectF(quiesce)
|
c.DisconnectF()
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakeParser struct {
|
type FakeParser struct {
|
||||||
|
|
@ -95,17 +95,17 @@ func (t *FakeToken) Done() <-chan struct{} {
|
||||||
func TestLifecycleSanity(t *testing.T) {
|
func TestLifecycleSanity(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
plugin := New(func(o *mqtt.ClientOptions) Client {
|
plugin := New(func(*mqtt.ClientOptions) Client {
|
||||||
return &FakeClient{
|
return &FakeClient{
|
||||||
ConnectF: func() mqtt.Token {
|
ConnectF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
AddRouteF: func(topic string, callback mqtt.MessageHandler) {
|
AddRouteF: func(mqtt.MessageHandler) {
|
||||||
},
|
},
|
||||||
SubscribeMultipleF: func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
SubscribeMultipleF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
DisconnectF: func(quiesce uint) {
|
DisconnectF: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -455,17 +455,17 @@ func TestTopicTag(t *testing.T) {
|
||||||
ConnectF: func() mqtt.Token {
|
ConnectF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
AddRouteF: func(topic string, callback mqtt.MessageHandler) {
|
AddRouteF: func(callback mqtt.MessageHandler) {
|
||||||
handler = callback
|
handler = callback
|
||||||
},
|
},
|
||||||
SubscribeMultipleF: func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
SubscribeMultipleF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
DisconnectF: func(quiesce uint) {
|
DisconnectF: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin := New(func(o *mqtt.ClientOptions) Client {
|
plugin := New(func(*mqtt.ClientOptions) Client {
|
||||||
return client
|
return client
|
||||||
})
|
})
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
|
|
@ -505,15 +505,15 @@ func TestAddRouteCalledForEachTopic(t *testing.T) {
|
||||||
ConnectF: func() mqtt.Token {
|
ConnectF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
AddRouteF: func(topic string, callback mqtt.MessageHandler) {
|
AddRouteF: func(mqtt.MessageHandler) {
|
||||||
},
|
},
|
||||||
SubscribeMultipleF: func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
SubscribeMultipleF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
DisconnectF: func(quiesce uint) {
|
DisconnectF: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
plugin := New(func(o *mqtt.ClientOptions) Client {
|
plugin := New(func(*mqtt.ClientOptions) Client {
|
||||||
return client
|
return client
|
||||||
})
|
})
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
|
|
@ -536,15 +536,15 @@ func TestSubscribeCalledIfNoSession(t *testing.T) {
|
||||||
ConnectF: func() mqtt.Token {
|
ConnectF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
AddRouteF: func(topic string, callback mqtt.MessageHandler) {
|
AddRouteF: func(mqtt.MessageHandler) {
|
||||||
},
|
},
|
||||||
SubscribeMultipleF: func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
SubscribeMultipleF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
DisconnectF: func(quiesce uint) {
|
DisconnectF: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
plugin := New(func(o *mqtt.ClientOptions) Client {
|
plugin := New(func(*mqtt.ClientOptions) Client {
|
||||||
return client
|
return client
|
||||||
})
|
})
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
|
|
@ -567,15 +567,15 @@ func TestSubscribeNotCalledIfSession(t *testing.T) {
|
||||||
ConnectF: func() mqtt.Token {
|
ConnectF: func() mqtt.Token {
|
||||||
return &FakeToken{sessionPresent: true}
|
return &FakeToken{sessionPresent: true}
|
||||||
},
|
},
|
||||||
AddRouteF: func(topic string, callback mqtt.MessageHandler) {
|
AddRouteF: func(mqtt.MessageHandler) {
|
||||||
},
|
},
|
||||||
SubscribeMultipleF: func(filters map[string]byte, callback mqtt.MessageHandler) mqtt.Token {
|
SubscribeMultipleF: func() mqtt.Token {
|
||||||
return &FakeToken{}
|
return &FakeToken{}
|
||||||
},
|
},
|
||||||
DisconnectF: func(quiesce uint) {
|
DisconnectF: func() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
plugin := New(func(o *mqtt.ClientOptions) Client {
|
plugin := New(func(*mqtt.ClientOptions) Client {
|
||||||
return client
|
return client
|
||||||
})
|
})
|
||||||
plugin.Log = testutil.Logger{}
|
plugin.Log = testutil.Logger{}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGather(t *testing.T) {
|
func TestGather(t *testing.T) {
|
||||||
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
h := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
_, err := w.Write([]byte("data"))
|
_, err := w.Write([]byte("data"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -407,7 +407,7 @@ func TestSendRequest(t *testing.T) {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
h := http.HandlerFunc(func(
|
h := http.HandlerFunc(func(
|
||||||
w http.ResponseWriter, r *http.Request) {
|
w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(test.statusCode)
|
w.WriteHeader(test.statusCode)
|
||||||
_, err := w.Write([]byte("data"))
|
_, err := w.Write([]byte("data"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -1458,7 +1458,7 @@ func TestGatherStreamServerZonesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnavailableEndpoints(t *testing.T) {
|
func TestUnavailableEndpoints(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
@ -1476,7 +1476,7 @@ func TestUnavailableEndpoints(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerError(t *testing.T) {
|
func TestServerError(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
@ -1494,7 +1494,7 @@ func TestServerError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMalformedJSON(t *testing.T) {
|
func TestMalformedJSON(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
_, err := fmt.Fprintln(w, "this is not JSON")
|
_, err := fmt.Fprintln(w, "this is not JSON")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -1514,7 +1514,7 @@ func TestMalformedJSON(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnknownContentType(t *testing.T) {
|
func TestUnknownContentType(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/plain")
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNSQStatsV1(t *testing.T) {
|
func TestNSQStatsV1(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, responseV1)
|
_, err := fmt.Fprintln(w, responseV1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -270,7 +270,7 @@ var responseV1 = `
|
||||||
|
|
||||||
// TestNSQStatsPreV1 is for backwards compatibility with nsq versions < 1.0
|
// TestNSQStatsPreV1 is for backwards compatibility with nsq versions < 1.0
|
||||||
func TestNSQStatsPreV1(t *testing.T) {
|
func TestNSQStatsPreV1(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, responsePreV1)
|
_, err := fmt.Fprintln(w, responsePreV1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,10 @@ func (o *ReadClient) Connect() error {
|
||||||
return fmt.Errorf("initializing node IDs failed: %w", err)
|
return fmt.Errorf("initializing node IDs failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
readValueIds := make([]*ua.ReadValueID, 0, len(o.NodeIDs))
|
readValueIDs := make([]*ua.ReadValueID, 0, len(o.NodeIDs))
|
||||||
if o.Workarounds.UseUnregisteredReads {
|
if o.Workarounds.UseUnregisteredReads {
|
||||||
for _, nid := range o.NodeIDs {
|
for _, nid := range o.NodeIDs {
|
||||||
readValueIds = append(readValueIds, &ua.ReadValueID{NodeID: nid})
|
readValueIDs = append(readValueIDs, &ua.ReadValueID{NodeID: nid})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
regResp, err := o.Client.RegisterNodes(o.ctx, &ua.RegisterNodesRequest{
|
regResp, err := o.Client.RegisterNodes(o.ctx, &ua.RegisterNodesRequest{
|
||||||
|
|
@ -79,14 +79,14 @@ func (o *ReadClient) Connect() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range regResp.RegisteredNodeIDs {
|
for _, v := range regResp.RegisteredNodeIDs {
|
||||||
readValueIds = append(readValueIds, &ua.ReadValueID{NodeID: v})
|
readValueIDs = append(readValueIDs, &ua.ReadValueID{NodeID: v})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
o.req = &ua.ReadRequest{
|
o.req = &ua.ReadRequest{
|
||||||
MaxAge: 2000,
|
MaxAge: 2000,
|
||||||
TimestampsToReturn: ua.TimestampsToReturnBoth,
|
TimestampsToReturn: ua.TimestampsToReturnBoth,
|
||||||
NodesToRead: readValueIds,
|
NodesToRead: readValueIDs,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := o.read(); err != nil {
|
if err := o.read(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,7 @@ type fakeP4RuntimeClient struct {
|
||||||
) (*p4v1.WriteResponse, error)
|
) (*p4v1.WriteResponse, error)
|
||||||
|
|
||||||
readFn func(
|
readFn func(
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.ReadRequest,
|
in *p4v1.ReadRequest,
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (p4v1.P4Runtime_ReadClient, error)
|
) (p4v1.P4Runtime_ReadClient, error)
|
||||||
|
|
||||||
setForwardingPipelineConfigFn func(
|
setForwardingPipelineConfigFn func(
|
||||||
|
|
@ -26,11 +24,7 @@ type fakeP4RuntimeClient struct {
|
||||||
opts ...grpc.CallOption,
|
opts ...grpc.CallOption,
|
||||||
) (*p4v1.SetForwardingPipelineConfigResponse, error)
|
) (*p4v1.SetForwardingPipelineConfigResponse, error)
|
||||||
|
|
||||||
getForwardingPipelineConfigFn func(
|
getForwardingPipelineConfigFn func() (*p4v1.GetForwardingPipelineConfigResponse, error)
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error)
|
|
||||||
|
|
||||||
streamChannelFn func(
|
streamChannelFn func(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
|
@ -59,14 +53,14 @@ func (c *fakeP4RuntimeClient) Write(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeP4RuntimeClient) Read(
|
func (c *fakeP4RuntimeClient) Read(
|
||||||
ctx context.Context,
|
_ context.Context,
|
||||||
in *p4v1.ReadRequest,
|
in *p4v1.ReadRequest,
|
||||||
opts ...grpc.CallOption,
|
_ ...grpc.CallOption,
|
||||||
) (p4v1.P4Runtime_ReadClient, error) {
|
) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
if c.readFn == nil {
|
if c.readFn == nil {
|
||||||
panic("No mock defined for Read RPC")
|
panic("No mock defined for Read RPC")
|
||||||
}
|
}
|
||||||
return c.readFn(ctx, in, opts...)
|
return c.readFn(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeP4RuntimeClient) SetForwardingPipelineConfig(
|
func (c *fakeP4RuntimeClient) SetForwardingPipelineConfig(
|
||||||
|
|
@ -81,14 +75,14 @@ func (c *fakeP4RuntimeClient) SetForwardingPipelineConfig(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeP4RuntimeClient) GetForwardingPipelineConfig(
|
func (c *fakeP4RuntimeClient) GetForwardingPipelineConfig(
|
||||||
ctx context.Context,
|
context.Context,
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
*p4v1.GetForwardingPipelineConfigRequest,
|
||||||
opts ...grpc.CallOption,
|
...grpc.CallOption,
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
if c.getForwardingPipelineConfigFn == nil {
|
if c.getForwardingPipelineConfigFn == nil {
|
||||||
panic("No mock defined for GetForwardingPipelineConfig RPC")
|
panic("No mock defined for GetForwardingPipelineConfig RPC")
|
||||||
}
|
}
|
||||||
return c.getForwardingPipelineConfigFn(ctx, in, opts...)
|
return c.getForwardingPipelineConfigFn()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeP4RuntimeClient) StreamChannel(
|
func (c *fakeP4RuntimeClient) StreamChannel(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package p4runtime
|
package p4runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
@ -93,11 +92,7 @@ func TestErrorGetP4Info(t *testing.T) {
|
||||||
|
|
||||||
for _, response := range responses {
|
for _, response := range responses {
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return response.getForwardingPipelineConfigResponse, response.getForwardingPipelineConfigResponseError
|
return response.getForwardingPipelineConfigResponse, response.getForwardingPipelineConfigResponseError
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -235,14 +230,10 @@ func TestOneCounterRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
readFn: func(ctx context.Context, in *p4v1.ReadRequest, opts ...grpc.CallOption) (p4v1.P4Runtime_ReadClient, error) {
|
readFn: func(*p4v1.ReadRequest) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
return p4RtReadClient, nil
|
return p4RtReadClient, nil
|
||||||
},
|
},
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: tt.forwardingPipelineConfig,
|
Config: tt.forwardingPipelineConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -327,14 +318,10 @@ func TestMultipleEntitiesSingleCounterRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
readFn: func(ctx context.Context, in *p4v1.ReadRequest, opts ...grpc.CallOption) (p4v1.P4Runtime_ReadClient, error) {
|
readFn: func(*p4v1.ReadRequest) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
return p4RtReadClient, nil
|
return p4RtReadClient, nil
|
||||||
},
|
},
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: forwardingPipelineConfig,
|
Config: forwardingPipelineConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -407,7 +394,7 @@ func TestSingleEntitiesMultipleCounterRead(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
readFn: func(ctx context.Context, in *p4v1.ReadRequest, opts ...grpc.CallOption) (p4v1.P4Runtime_ReadClient, error) {
|
readFn: func(in *p4v1.ReadRequest) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
counterID := in.Entities[0].GetCounterEntry().CounterId
|
counterID := in.Entities[0].GetCounterEntry().CounterId
|
||||||
return &fakeP4RuntimeReadClient{
|
return &fakeP4RuntimeReadClient{
|
||||||
recvFn: func() (*p4v1.ReadResponse, error) {
|
recvFn: func() (*p4v1.ReadResponse, error) {
|
||||||
|
|
@ -426,11 +413,7 @@ func TestSingleEntitiesMultipleCounterRead(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: forwardingPipelineConfig,
|
Config: forwardingPipelineConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -462,11 +445,7 @@ func TestNoCountersAvailable(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: forwardingPipelineConfig,
|
Config: forwardingPipelineConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -493,11 +472,7 @@ func TestFilterCounters(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: forwardingPipelineConfig,
|
Config: forwardingPipelineConfig,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -533,14 +508,10 @@ func TestFailReadCounterEntryFromEntry(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
readFn: func(ctx context.Context, in *p4v1.ReadRequest, opts ...grpc.CallOption) (p4v1.P4Runtime_ReadClient, error) {
|
readFn: func(*p4v1.ReadRequest) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
return p4RtReadClient, nil
|
return p4RtReadClient, nil
|
||||||
},
|
},
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: &p4v1.ForwardingPipelineConfig{
|
Config: &p4v1.ForwardingPipelineConfig{
|
||||||
P4Info: &p4ConfigV1.P4Info{
|
P4Info: &p4ConfigV1.P4Info{
|
||||||
|
|
@ -580,14 +551,10 @@ func TestFailReadCounterEntryFromEntry(t *testing.T) {
|
||||||
|
|
||||||
func TestFailReadAllEntries(t *testing.T) {
|
func TestFailReadAllEntries(t *testing.T) {
|
||||||
p4RtClient := &fakeP4RuntimeClient{
|
p4RtClient := &fakeP4RuntimeClient{
|
||||||
readFn: func(ctx context.Context, in *p4v1.ReadRequest, opts ...grpc.CallOption) (p4v1.P4Runtime_ReadClient, error) {
|
readFn: func(*p4v1.ReadRequest) (p4v1.P4Runtime_ReadClient, error) {
|
||||||
return nil, errors.New("connection error")
|
return nil, errors.New("connection error")
|
||||||
},
|
},
|
||||||
getForwardingPipelineConfigFn: func(
|
getForwardingPipelineConfigFn: func() (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
||||||
ctx context.Context,
|
|
||||||
in *p4v1.GetForwardingPipelineConfigRequest,
|
|
||||||
opts ...grpc.CallOption,
|
|
||||||
) (*p4v1.GetForwardingPipelineConfigResponse, error) {
|
|
||||||
return &p4v1.GetForwardingPipelineConfigResponse{
|
return &p4v1.GetForwardingPipelineConfigResponse{
|
||||||
Config: &p4v1.ForwardingPipelineConfig{
|
Config: &p4v1.ForwardingPipelineConfig{
|
||||||
P4Info: &p4ConfigV1.P4Info{
|
P4Info: &p4ConfigV1.P4Info{
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ func TestChildServeCleansUp(t *testing.T) {
|
||||||
rc := nopWriteCloser{bytes.NewBuffer(input)}
|
rc := nopWriteCloser{bytes.NewBuffer(input)}
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
c := newChild(rc, http.HandlerFunc(func(
|
c := newChild(rc, http.HandlerFunc(func(
|
||||||
w http.ResponseWriter,
|
_ http.ResponseWriter,
|
||||||
r *http.Request,
|
r *http.Request,
|
||||||
) {
|
) {
|
||||||
// block on reading body of request
|
// block on reading body of request
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ func TestPhpFpmGeneratesMetrics_From_Http(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPhpFpmGeneratesJSONMetrics_From_Http(t *testing.T) {
|
func TestPhpFpmGeneratesJSONMetrics_From_Http(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Content-Type", "text/json")
|
w.Header().Set("Content-Type", "text/json")
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(outputSampleJSON)))
|
w.Header().Set("Content-Length", strconv.Itoa(len(outputSampleJSON)))
|
||||||
_, err := fmt.Fprint(w, string(outputSampleJSON))
|
_, err := fmt.Fprint(w, string(outputSampleJSON))
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,7 @@ func TestArguments(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mockHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockHostPinger(string, float64, ...string) (string, error) {
|
||||||
return linuxPingOutput, nil
|
return linuxPingOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,7 +283,7 @@ PING www.google.com (216.58.218.164) 56(84) bytes of data.
|
||||||
rtt min/avg/max/mdev = 35.225/44.033/51.806/5.325 ms
|
rtt min/avg/max/mdev = 35.225/44.033/51.806/5.325 ms
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockLossyHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockLossyHostPinger(string, float64, ...string) (string, error) {
|
||||||
return lossyPingOutput, nil
|
return lossyPingOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -319,7 +319,7 @@ Request timeout for icmp_seq 0
|
||||||
2 packets transmitted, 0 packets received, 100.0% packet loss
|
2 packets transmitted, 0 packets received, 100.0% packet loss
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockErrorHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockErrorHostPinger(string, float64, ...string) (string, error) {
|
||||||
// This error will not trigger correct error paths
|
// This error will not trigger correct error paths
|
||||||
return errorPingOutput, nil
|
return errorPingOutput, nil
|
||||||
}
|
}
|
||||||
|
|
@ -344,7 +344,7 @@ func TestBadPingGather(t *testing.T) {
|
||||||
acc.AssertContainsTaggedFields(t, "ping", fields, tags)
|
acc.AssertContainsTaggedFields(t, "ping", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mockFatalHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockFatalHostPinger(string, float64, ...string) (string, error) {
|
||||||
return fatalPingOutput, errors.New("so very bad")
|
return fatalPingOutput, errors.New("so very bad")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,7 +388,7 @@ func TestErrorWithHostNamePingGather(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
p := Ping{
|
p := Ping{
|
||||||
Urls: []string{"www.amazon.com"},
|
Urls: []string{"www.amazon.com"},
|
||||||
pingHost: func(binary string, timeout float64, args ...string) (string, error) {
|
pingHost: func(string, float64, ...string) (string, error) {
|
||||||
return param.out, errors.New("so very bad")
|
return param.out, errors.New("so very bad")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -403,7 +403,7 @@ func TestPingBinary(t *testing.T) {
|
||||||
p := Ping{
|
p := Ping{
|
||||||
Urls: []string{"www.google.com"},
|
Urls: []string{"www.google.com"},
|
||||||
Binary: "ping6",
|
Binary: "ping6",
|
||||||
pingHost: func(binary string, timeout float64, args ...string) (string, error) {
|
pingHost: func(binary string, _ float64, _ ...string) (string, error) {
|
||||||
require.Equal(t, "ping6", binary)
|
require.Equal(t, "ping6", binary)
|
||||||
return "", nil
|
return "", nil
|
||||||
},
|
},
|
||||||
|
|
@ -419,7 +419,7 @@ func TestPingGatherNative(t *testing.T) {
|
||||||
P *Ping
|
P *Ping
|
||||||
}
|
}
|
||||||
|
|
||||||
fakePingFunc := func(destination string) (*pingStats, error) {
|
fakePingFunc := func(string) (*pingStats, error) {
|
||||||
s := &pingStats{
|
s := &pingStats{
|
||||||
Statistics: ping.Statistics{
|
Statistics: ping.Statistics{
|
||||||
PacketsSent: 5,
|
PacketsSent: 5,
|
||||||
|
|
@ -487,7 +487,7 @@ func TestNoPacketsSent(t *testing.T) {
|
||||||
Method: "native",
|
Method: "native",
|
||||||
Count: 5,
|
Count: 5,
|
||||||
Percentiles: []int{50, 95, 99},
|
Percentiles: []int{50, 95, 99},
|
||||||
nativePingFunc: func(destination string) (*pingStats, error) {
|
nativePingFunc: func(string) (*pingStats, error) {
|
||||||
s := &pingStats{
|
s := &pingStats{
|
||||||
Statistics: ping.Statistics{
|
Statistics: ping.Statistics{
|
||||||
PacketsSent: 0,
|
PacketsSent: 0,
|
||||||
|
|
@ -516,7 +516,7 @@ func TestDNSLookupError(t *testing.T) {
|
||||||
Urls: []string{"localhost"},
|
Urls: []string{"localhost"},
|
||||||
Method: "native",
|
Method: "native",
|
||||||
IPv6: false,
|
IPv6: false,
|
||||||
nativePingFunc: func(destination string) (*pingStats, error) {
|
nativePingFunc: func(string) (*pingStats, error) {
|
||||||
return nil, errors.New("unknown")
|
return nil, errors.New("unknown")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ func TestHost(t *testing.T) {
|
||||||
require.Equal(t, 52, stats.max, "Max 52")
|
require.Equal(t, 52, stats.max, "Max 52")
|
||||||
}
|
}
|
||||||
|
|
||||||
func mockHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockHostPinger(string, float64, ...string) (string, error) {
|
||||||
return winENPingOutput, nil
|
return winENPingOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,7 +103,7 @@ Statystyka badania ping dla 195.187.242.157:
|
||||||
(100% straty),
|
(100% straty),
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockErrorHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockErrorHostPinger(string, float64, ...string) (string, error) {
|
||||||
return errorPingOutput, errors.New("No packets received")
|
return errorPingOutput, errors.New("No packets received")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ Szacunkowy czas błądzenia pakietów w millisekundach:
|
||||||
Minimum = 114 ms, Maksimum = 119 ms, Czas średni = 115 ms
|
Minimum = 114 ms, Maksimum = 119 ms, Czas średni = 115 ms
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockLossyHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockLossyHostPinger(string, float64, ...string) (string, error) {
|
||||||
return lossyPingOutput, nil
|
return lossyPingOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -227,7 +227,7 @@ Options:
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockFatalHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockFatalHostPinger(string, float64, ...string) (string, error) {
|
||||||
return fatalPingOutput, errors.New("So very bad")
|
return fatalPingOutput, errors.New("So very bad")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -272,7 +272,7 @@ Ping statistics for 8.8.8.8:
|
||||||
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
|
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockUnreachableHostPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockUnreachableHostPinger(string, float64, ...string) (string, error) {
|
||||||
return UnreachablePingOutput, errors.New("So very bad")
|
return UnreachablePingOutput, errors.New("So very bad")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -323,7 +323,7 @@ Ping statistics for 8.8.8.8:
|
||||||
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
|
Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
|
||||||
`
|
`
|
||||||
|
|
||||||
func mockTTLExpiredPinger(_ string, _ float64, _ ...string) (string, error) {
|
func mockTTLExpiredPinger(string, float64, ...string) (string, error) {
|
||||||
return TTLExpiredPingOutput, errors.New("So very bad")
|
return TTLExpiredPingOutput, errors.New("So very bad")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,7 +367,7 @@ func TestPingBinary(t *testing.T) {
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
Urls: []string{"www.google.com"},
|
Urls: []string{"www.google.com"},
|
||||||
Binary: "ping6",
|
Binary: "ping6",
|
||||||
pingHost: func(binary string, timeout float64, args ...string) (string, error) {
|
pingHost: func(binary string, _ float64, _ ...string) (string, error) {
|
||||||
require.Equal(t, "ping6", binary)
|
require.Equal(t, "ping6", binary)
|
||||||
return "", nil
|
return "", nil
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,16 +15,15 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/filter"
|
|
||||||
"github.com/influxdata/telegraf/models"
|
|
||||||
"k8s.io/client-go/tools/cache"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/client-go/tools/cache"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
|
"github.com/influxdata/telegraf/models"
|
||||||
httpconfig "github.com/influxdata/telegraf/plugins/common/http"
|
httpconfig "github.com/influxdata/telegraf/plugins/common/http"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
parser "github.com/influxdata/telegraf/plugins/parsers/prometheus"
|
parser "github.com/influxdata/telegraf/plugins/parsers/prometheus"
|
||||||
|
|
@ -401,7 +400,7 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) (map[s
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
TLSClientConfig: tlsCfg,
|
TLSClientConfig: tlsCfg,
|
||||||
DisableKeepAlives: true,
|
DisableKeepAlives: true,
|
||||||
Dial: func(network, addr string) (net.Conn, error) {
|
Dial: func(string, string) (net.Conn, error) {
|
||||||
c, err := net.Dial("unix", u.URL.Path)
|
c, err := net.Dial("unix", u.URL.Path)
|
||||||
return c, err
|
return c, err
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ const sampleGaugeTextFormat = `
|
||||||
go_goroutines 15 1490802350000`
|
go_goroutines 15 1490802350000`
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetrics(t *testing.T) {
|
func TestPrometheusGeneratesMetrics(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -137,7 +137,7 @@ func TestPrometheusCustomHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsWithHostNameTag(t *testing.T) {
|
func TestPrometheusGeneratesMetricsWithHostNameTag(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -171,7 +171,7 @@ func TestPrometheusWithTimestamp(t *testing.T) {
|
||||||
prommetric := `# HELP test_counter A sample test counter.
|
prommetric := `# HELP test_counter A sample test counter.
|
||||||
# TYPE test_counter counter
|
# TYPE test_counter counter
|
||||||
test_counter{label="test"} 1 1685443805885`
|
test_counter{label="test"} 1 1685443805885`
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, prommetric)
|
_, err := fmt.Fprintln(w, prommetric)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -207,7 +207,7 @@ func TestPrometheusGeneratesMetricsAlthoughFirstDNSFailsIntegration(t *testing.T
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -233,7 +233,7 @@ func TestPrometheusGeneratesMetricsAlthoughFirstDNSFailsIntegration(t *testing.T
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsSlowEndpoint(t *testing.T) {
|
func TestPrometheusGeneratesMetricsSlowEndpoint(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
time.Sleep(4 * time.Second)
|
time.Sleep(4 * time.Second)
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -263,7 +263,7 @@ func TestPrometheusGeneratesMetricsSlowEndpoint(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeout(t *testing.T) {
|
func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeout(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
time.Sleep(6 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -290,7 +290,7 @@ func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsSlowEndpointNewConfigParameter(t *testing.T) {
|
func TestPrometheusGeneratesMetricsSlowEndpointNewConfigParameter(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
time.Sleep(4 * time.Second)
|
time.Sleep(4 * time.Second)
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -320,7 +320,7 @@ func TestPrometheusGeneratesMetricsSlowEndpointNewConfigParameter(t *testing.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeoutNewConfigParameter(t *testing.T) {
|
func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeoutNewConfigParameter(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
time.Sleep(6 * time.Second)
|
time.Sleep(6 * time.Second)
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -343,7 +343,7 @@ func TestPrometheusGeneratesMetricsSlowEndpointHitTheTimeoutNewConfigParameter(t
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusContentLengthLimit(t *testing.T) {
|
func TestPrometheusContentLengthLimit(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -363,7 +363,7 @@ func TestPrometheusContentLengthLimit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesSummaryMetricsV2(t *testing.T) {
|
func TestPrometheusGeneratesSummaryMetricsV2(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleSummaryTextFormat)
|
_, err := fmt.Fprintln(w, sampleSummaryTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -397,7 +397,7 @@ go_gc_duration_seconds{quantile="1"} NaN
|
||||||
go_gc_duration_seconds_sum 42.0
|
go_gc_duration_seconds_sum 42.0
|
||||||
go_gc_duration_seconds_count 42`
|
go_gc_duration_seconds_count 42`
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, data)
|
_, err := fmt.Fprintln(w, data)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -466,7 +466,7 @@ go_gc_duration_seconds_count 42`
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesGaugeMetricsV2(t *testing.T) {
|
func TestPrometheusGeneratesGaugeMetricsV2(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleGaugeTextFormat)
|
_, err := fmt.Fprintln(w, sampleGaugeTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
@ -492,7 +492,7 @@ func TestPrometheusGeneratesGaugeMetricsV2(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrometheusGeneratesMetricsWithIgnoreTimestamp(t *testing.T) {
|
func TestPrometheusGeneratesMetricsWithIgnoreTimestamp(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, sampleTextFormat)
|
_, err := fmt.Fprintln(w, sampleTextFormat)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,14 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRiak(t *testing.T) {
|
func TestRiak(t *testing.T) {
|
||||||
// Create a test server with the const response JSON
|
// Create a test server with the const response JSON
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, response)
|
_, err := fmt.Fprintln(w, response)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,10 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/testutil"
|
|
||||||
"github.com/robinson/gos7"
|
"github.com/robinson/gos7"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSampleConfig(t *testing.T) {
|
func TestSampleConfig(t *testing.T) {
|
||||||
|
|
@ -273,7 +274,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return false },
|
convert: func([]byte) interface{} { return false },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -308,7 +309,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return byte(0) },
|
convert: func([]byte) interface{} { return byte(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -343,7 +344,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return string([]byte{0}) },
|
convert: func([]byte) interface{} { return string([]byte{0}) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -378,7 +379,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return "" },
|
convert: func([]byte) interface{} { return "" },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -413,7 +414,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return uint16(0) },
|
convert: func([]byte) interface{} { return uint16(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -448,7 +449,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return int16(0) },
|
convert: func([]byte) interface{} { return int16(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -483,7 +484,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return uint32(0) },
|
convert: func([]byte) interface{} { return uint32(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -518,7 +519,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return int32(0) },
|
convert: func([]byte) interface{} { return int32(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -553,7 +554,7 @@ func TestFieldMappings(t *testing.T) {
|
||||||
{
|
{
|
||||||
measurement: "test",
|
measurement: "test",
|
||||||
field: "foo",
|
field: "foo",
|
||||||
convert: func(b []byte) interface{} { return float32(0) },
|
convert: func([]byte) interface{} { return float32(0) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,14 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf/plugins/inputs/salesforce"
|
"github.com/influxdata/telegraf/plugins/inputs/salesforce"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_Gather(t *testing.T) {
|
func Test_Gather(t *testing.T) {
|
||||||
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
fakeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Add("Content-Type", "application/json")
|
w.Header().Add("Content-Type", "application/json")
|
||||||
_, _ = w.Write([]byte(testJSON))
|
_, _ = w.Write([]byte(testJSON))
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ var (
|
||||||
// 0xab program_fail_count
|
// 0xab program_fail_count
|
||||||
nvmeIDSeparatePattern = regexp.MustCompile(`^([A-Za-z0-9_]+)(.+)`)
|
nvmeIDSeparatePattern = regexp.MustCompile(`^([A-Za-z0-9_]+)(.+)`)
|
||||||
|
|
||||||
deviceFieldIds = map[string]string{
|
deviceFieldIDs = map[string]string{
|
||||||
"1": "read_error_rate",
|
"1": "read_error_rate",
|
||||||
"5": "reallocated_sectors_count",
|
"5": "reallocated_sectors_count",
|
||||||
"7": "seek_error_rate",
|
"7": "seek_error_rate",
|
||||||
|
|
@ -842,9 +842,9 @@ func (m *Smart) gatherDisk(acc telegraf.Accumulator, device string, wg *sync.Wai
|
||||||
acc.AddFields("smart_attribute", fields, tags)
|
acc.AddFields("smart_attribute", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the attribute matches on the one in deviceFieldIds
|
// If the attribute matches on the one in deviceFieldIDs
|
||||||
// save the raw value to a field.
|
// save the raw value to a field.
|
||||||
if field, ok := deviceFieldIds[attr[1]]; ok {
|
if field, ok := deviceFieldIDs[attr[1]]; ok {
|
||||||
if val, err := parseRawValue(attr[8]); err == nil {
|
if val, err := parseRawValue(attr[8]); err == nil {
|
||||||
deviceFields[field] = val
|
deviceFields[field] = val
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ func TestGatherAttributes(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, time.Second*30, time.Duration(s.Timeout))
|
require.Equal(t, time.Second*30, time.Duration(s.Timeout))
|
||||||
|
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(_ config.Duration, _ bool, _ string, args ...string) ([]byte, error) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if args[0] == "--info" && args[7] == "/dev/ada0" {
|
if args[0] == "--info" && args[7] == "/dev/ada0" {
|
||||||
return []byte(mockInfoAttributeData), nil
|
return []byte(mockInfoAttributeData), nil
|
||||||
|
|
@ -86,7 +86,7 @@ func TestGatherInParallelMode(t *testing.T) {
|
||||||
s.EnableExtensions = append(s.EnableExtensions, "auto-on")
|
s.EnableExtensions = append(s.EnableExtensions, "auto-on")
|
||||||
s.Devices = []string{"/dev/nvme0"}
|
s.Devices = []string{"/dev/nvme0"}
|
||||||
|
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(_ config.Duration, _ bool, _ string, args ...string) ([]byte, error) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if args[0] == "--info" && args[7] == "/dev/ada0" {
|
if args[0] == "--info" && args[7] == "/dev/ada0" {
|
||||||
return []byte(mockInfoAttributeData), nil
|
return []byte(mockInfoAttributeData), nil
|
||||||
|
|
@ -150,7 +150,7 @@ func TestGatherNoAttributes(t *testing.T) {
|
||||||
|
|
||||||
require.Equal(t, time.Second*30, time.Duration(s.Timeout))
|
require.Equal(t, time.Second*30, time.Duration(s.Timeout))
|
||||||
|
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(_ config.Duration, _ bool, _ string, args ...string) ([]byte, error) {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
if args[0] == "--scan" && len(args) == 1 {
|
if args[0] == "--scan" && len(args) == 1 {
|
||||||
return []byte(mockScanData), nil
|
return []byte(mockScanData), nil
|
||||||
|
|
@ -201,7 +201,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGatherSATAInfo(t *testing.T) {
|
func TestGatherSATAInfo(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(hgstSATAInfoData), nil
|
return []byte(hgstSATAInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -218,7 +218,7 @@ func TestGatherSATAInfo(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherSATAInfo65(t *testing.T) {
|
func TestGatherSATAInfo65(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(hgstSATAInfoData65), nil
|
return []byte(hgstSATAInfoData65), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,7 +234,7 @@ func TestGatherSATAInfo65(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherHgstSAS(t *testing.T) {
|
func TestGatherHgstSAS(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(hgstSASInfoData), nil
|
return []byte(hgstSASInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,7 +250,7 @@ func TestGatherHgstSAS(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherHtSAS(t *testing.T) {
|
func TestGatherHtSAS(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(htSASInfoData), nil
|
return []byte(htSASInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ func TestGatherHtSAS(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherLongFormEnduranceAttrib(t *testing.T) {
|
func TestGatherLongFormEnduranceAttrib(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(mockHGST), nil
|
return []byte(mockHGST), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -283,7 +283,7 @@ func TestGatherLongFormEnduranceAttrib(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherSSD(t *testing.T) {
|
func TestGatherSSD(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(ssdInfoData), nil
|
return []byte(ssdInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -299,7 +299,7 @@ func TestGatherSSD(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherSSDRaid(t *testing.T) {
|
func TestGatherSSDRaid(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(ssdRaidInfoData), nil
|
return []byte(ssdRaidInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,7 +315,7 @@ func TestGatherSSDRaid(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherDeviceTypeTag(t *testing.T) {
|
func TestGatherDeviceTypeTag(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(_ config.Duration, _ bool, _ string, args ...string) ([]byte, error) {
|
||||||
switch args[0] {
|
switch args[0] {
|
||||||
case "--scan":
|
case "--scan":
|
||||||
return nil, errors.New("scan command should not be run, since devices are provided in config")
|
return nil, errors.New("scan command should not be run, since devices are provided in config")
|
||||||
|
|
@ -348,7 +348,7 @@ func TestGatherDeviceTypeTag(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherNVMe(t *testing.T) {
|
func TestGatherNVMe(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(smartctlNVMeInfoData), nil
|
return []byte(smartctlNVMeInfoData), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,7 +365,7 @@ func TestGatherNVMe(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherNVMeWindows(t *testing.T) {
|
func TestGatherNVMeWindows(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(smartctlNVMeInfoDataWindows), nil
|
return []byte(smartctlNVMeInfoDataWindows), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -383,7 +383,7 @@ func TestGatherNVMeWindows(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherIntelNVMeMetrics(t *testing.T) {
|
func TestGatherIntelNVMeMetrics(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(nvmeIntelInfoDataMetricsFormat), nil
|
return []byte(nvmeIntelInfoDataMetricsFormat), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,7 +406,7 @@ func TestGatherIntelNVMeMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherIntelNVMeDeprecatedFormatMetrics(t *testing.T) {
|
func TestGatherIntelNVMeDeprecatedFormatMetrics(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(nvmeIntelInfoDataDeprecatedMetricsFormat), nil
|
return []byte(nvmeIntelInfoDataDeprecatedMetricsFormat), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -461,7 +461,7 @@ func Test_difference(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_integerOverflow(t *testing.T) {
|
func Test_integerOverflow(t *testing.T) {
|
||||||
runCmd = func(timeout config.Duration, sudo bool, command string, args ...string) ([]byte, error) {
|
runCmd = func(config.Duration, bool, string, ...string) ([]byte, error) {
|
||||||
return []byte(smartctlNVMeInfoDataWithOverflow), nil
|
return []byte(smartctlNVMeInfoDataWithOverflow), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func TestSocketstat_Gather(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
require.EqualError(t, err, "exec: \"ss\": executable file not found in $PATH")
|
require.EqualError(t, err, "exec: \"ss\": executable file not found in $PATH")
|
||||||
}
|
}
|
||||||
ss.lister = func(cmdName string, proto string, timeout config.Duration) (*bytes.Buffer, error) {
|
ss.lister = func(string, string, config.Duration) (*bytes.Buffer, error) {
|
||||||
return bytes.NewBuffer(octets), nil
|
return bytes.NewBuffer(octets), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ func TestSocketstat_Gather_listerError(t *testing.T) {
|
||||||
ss := &Socketstat{
|
ss := &Socketstat{
|
||||||
SocketProto: []string{"foobar"},
|
SocketProto: []string{"foobar"},
|
||||||
}
|
}
|
||||||
ss.lister = func(cmdName string, proto string, timeout config.Duration) (*bytes.Buffer, error) {
|
ss.lister = func(string, string, config.Duration) (*bytes.Buffer, error) {
|
||||||
return new(bytes.Buffer), errFoo
|
return new(bytes.Buffer), errFoo
|
||||||
}
|
}
|
||||||
acc := new(testutil.Accumulator)
|
acc := new(testutil.Accumulator)
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ type Call struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockStackdriverClient struct {
|
type MockStackdriverClient struct {
|
||||||
ListMetricDescriptorsF func(ctx context.Context, req *monitoringpb.ListMetricDescriptorsRequest) (<-chan *metricpb.MetricDescriptor, error)
|
ListMetricDescriptorsF func() (<-chan *metricpb.MetricDescriptor, error)
|
||||||
ListTimeSeriesF func(ctx context.Context, req *monitoringpb.ListTimeSeriesRequest) (<-chan *monitoringpb.TimeSeries, error)
|
ListTimeSeriesF func() (<-chan *monitoringpb.TimeSeries, error)
|
||||||
CloseF func() error
|
CloseF func() error
|
||||||
|
|
||||||
calls []*Call
|
calls []*Call
|
||||||
|
|
@ -40,7 +40,7 @@ func (m *MockStackdriverClient) ListMetricDescriptors(
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.calls = append(m.calls, call)
|
m.calls = append(m.calls, call)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
return m.ListMetricDescriptorsF(ctx, req)
|
return m.ListMetricDescriptorsF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockStackdriverClient) ListTimeSeries(
|
func (m *MockStackdriverClient) ListTimeSeries(
|
||||||
|
|
@ -51,7 +51,7 @@ func (m *MockStackdriverClient) ListTimeSeries(
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.calls = append(m.calls, call)
|
m.calls = append(m.calls, call)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
return m.ListTimeSeriesF(ctx, req)
|
return m.ListTimeSeriesF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockStackdriverClient) Close() error {
|
func (m *MockStackdriverClient) Close() error {
|
||||||
|
|
@ -719,13 +719,13 @@ func TestGather(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
listMetricDescriptorsF := func(ctx context.Context, req *monitoringpb.ListMetricDescriptorsRequest) (<-chan *metricpb.MetricDescriptor, error) {
|
listMetricDescriptorsF := func() (<-chan *metricpb.MetricDescriptor, error) {
|
||||||
ch := make(chan *metricpb.MetricDescriptor, 1)
|
ch := make(chan *metricpb.MetricDescriptor, 1)
|
||||||
ch <- tt.descriptor
|
ch <- tt.descriptor
|
||||||
close(ch)
|
close(ch)
|
||||||
return ch, nil
|
return ch, nil
|
||||||
}
|
}
|
||||||
listTimeSeriesF := func(ctx context.Context, req *monitoringpb.ListTimeSeriesRequest) (<-chan *monitoringpb.TimeSeries, error) {
|
listTimeSeriesF := func() (<-chan *monitoringpb.TimeSeries, error) {
|
||||||
ch := make(chan *monitoringpb.TimeSeries, 1)
|
ch := make(chan *monitoringpb.TimeSeries, 1)
|
||||||
ch <- tt.timeseries
|
ch <- tt.timeseries
|
||||||
close(ch)
|
close(ch)
|
||||||
|
|
@ -841,13 +841,13 @@ func TestGatherAlign(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
client := &MockStackdriverClient{
|
client := &MockStackdriverClient{
|
||||||
ListMetricDescriptorsF: func(ctx context.Context, req *monitoringpb.ListMetricDescriptorsRequest) (<-chan *metricpb.MetricDescriptor, error) {
|
ListMetricDescriptorsF: func() (<-chan *metricpb.MetricDescriptor, error) {
|
||||||
ch := make(chan *metricpb.MetricDescriptor, 1)
|
ch := make(chan *metricpb.MetricDescriptor, 1)
|
||||||
ch <- tt.descriptor
|
ch <- tt.descriptor
|
||||||
close(ch)
|
close(ch)
|
||||||
return ch, nil
|
return ch, nil
|
||||||
},
|
},
|
||||||
ListTimeSeriesF: func(ctx context.Context, req *monitoringpb.ListTimeSeriesRequest) (<-chan *monitoringpb.TimeSeries, error) {
|
ListTimeSeriesF: func() (<-chan *monitoringpb.TimeSeries, error) {
|
||||||
ch := make(chan *monitoringpb.TimeSeries, 1)
|
ch := make(chan *monitoringpb.TimeSeries, 1)
|
||||||
ch <- tt.timeseries[listCall]
|
ch <- tt.timeseries[listCall]
|
||||||
close(ch)
|
close(ch)
|
||||||
|
|
@ -1172,13 +1172,13 @@ func TestListMetricDescriptorFilter(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
client := &MockStackdriverClient{
|
client := &MockStackdriverClient{
|
||||||
ListMetricDescriptorsF: func(ctx context.Context, req *monitoringpb.ListMetricDescriptorsRequest) (<-chan *metricpb.MetricDescriptor, error) {
|
ListMetricDescriptorsF: func() (<-chan *metricpb.MetricDescriptor, error) {
|
||||||
ch := make(chan *metricpb.MetricDescriptor, 1)
|
ch := make(chan *metricpb.MetricDescriptor, 1)
|
||||||
ch <- tt.descriptor
|
ch <- tt.descriptor
|
||||||
close(ch)
|
close(ch)
|
||||||
return ch, nil
|
return ch, nil
|
||||||
},
|
},
|
||||||
ListTimeSeriesF: func(ctx context.Context, req *monitoringpb.ListTimeSeriesRequest) (<-chan *monitoringpb.TimeSeries, error) {
|
ListTimeSeriesF: func() (<-chan *monitoringpb.TimeSeries, error) {
|
||||||
ch := make(chan *monitoringpb.TimeSeries, 1)
|
ch := make(chan *monitoringpb.TimeSeries, 1)
|
||||||
ch <- createTimeSeries(
|
ch <- createTimeSeries(
|
||||||
&monitoringpb.Point{
|
&monitoringpb.Point{
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ func TestTengineTags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTengineGeneratesMetrics(t *testing.T) {
|
func TestTengineGeneratesMetrics(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := fmt.Fprintln(w, tengineSampleResponse)
|
_, err := fmt.Fprintln(w, tengineSampleResponse)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ var tomcatStatus8 = `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
</status>`
|
</status>`
|
||||||
|
|
||||||
func TestHTTPTomcat8(t *testing.T) {
|
func TestHTTPTomcat8(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, tomcatStatus8)
|
_, err := fmt.Fprintln(w, tomcatStatus8)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -124,7 +124,7 @@ var tomcatStatus6 = `<?xml version="1.0" encoding="utf-8"?>
|
||||||
</status>`
|
</status>`
|
||||||
|
|
||||||
func TestHTTPTomcat6(t *testing.T) {
|
func TestHTTPTomcat6(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := fmt.Fprintln(w, tomcatStatus6)
|
_, err := fmt.Fprintln(w, tomcatStatus6)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UnboundControl(output string) func(unbound Unbound) (*bytes.Buffer, error) {
|
func UnboundControl(output string) func(Unbound) (*bytes.Buffer, error) {
|
||||||
return func(unbound Unbound) (*bytes.Buffer, error) {
|
return func(Unbound) (*bytes.Buffer, error) {
|
||||||
return bytes.NewBuffer([]byte(output)), nil
|
return bytes.NewBuffer([]byte(output)), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestGatherRemoteIntegration(t *testing.T) {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
if test.unset {
|
if test.unset {
|
||||||
cfg.Certificates = nil
|
cfg.Certificates = nil
|
||||||
cfg.GetCertificate = func(i *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
cfg.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -336,7 +336,7 @@ func TestGatherUDPCertIntegration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGatherTCPCert(t *testing.T) {
|
func TestGatherTCPCert(t *testing.T) {
|
||||||
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func TestFixedValue(t *testing.T) {
|
||||||
func TestAuthenticationFailed(t *testing.T) {
|
func TestAuthenticationFailed(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(
|
http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err := fmt.Fprintln(w, "bad request")
|
_, err := fmt.Fprintln(w, "bad request")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockClient struct {
|
type MockClient struct {
|
||||||
PublishF func(key string, body []byte) error
|
PublishF func() error
|
||||||
CloseF func() error
|
CloseF func() error
|
||||||
|
|
||||||
PublishCallCount int
|
PublishCallCount int
|
||||||
CloseCallCount int
|
CloseCallCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) Publish(key string, body []byte) error {
|
func (c *MockClient) Publish(string, []byte) error {
|
||||||
c.PublishCallCount++
|
c.PublishCallCount++
|
||||||
return c.PublishF(key, body)
|
return c.PublishF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) Close() error {
|
func (c *MockClient) Close() error {
|
||||||
|
|
@ -30,7 +30,7 @@ func (c *MockClient) Close() error {
|
||||||
|
|
||||||
func NewMockClient() Client {
|
func NewMockClient() Client {
|
||||||
return &MockClient{
|
return &MockClient{
|
||||||
PublishF: func(key string, body []byte) error {
|
PublishF: func() error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
CloseF: func() error {
|
CloseF: func() error {
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func TestAggregate(t *testing.T) {
|
||||||
},
|
},
|
||||||
addTime: time.Unix(0, 0),
|
addTime: time.Unix(0, 0),
|
||||||
pushTime: time.Unix(0, 0),
|
pushTime: time.Unix(0, 0),
|
||||||
check: func(t *testing.T, plugin *AzureMonitor, metrics []telegraf.Metric) {
|
check: func(t *testing.T, _ *AzureMonitor, metrics []telegraf.Metric) {
|
||||||
require.Empty(t, metrics)
|
require.Empty(t, metrics)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -96,7 +96,7 @@ func TestAggregate(t *testing.T) {
|
||||||
},
|
},
|
||||||
addTime: time.Unix(0, 0),
|
addTime: time.Unix(0, 0),
|
||||||
pushTime: time.Unix(3600, 0),
|
pushTime: time.Unix(3600, 0),
|
||||||
check: func(t *testing.T, plugin *AzureMonitor, metrics []telegraf.Metric) {
|
check: func(t *testing.T, _ *AzureMonitor, metrics []telegraf.Metric) {
|
||||||
expected := []telegraf.Metric{
|
expected := []telegraf.Metric{
|
||||||
testutil.MustMetric(
|
testutil.MustMetric(
|
||||||
"cpu-value",
|
"cpu-value",
|
||||||
|
|
@ -136,7 +136,7 @@ func TestAggregate(t *testing.T) {
|
||||||
},
|
},
|
||||||
addTime: time.Unix(0, 0),
|
addTime: time.Unix(0, 0),
|
||||||
pushTime: time.Unix(3600, 0),
|
pushTime: time.Unix(3600, 0),
|
||||||
check: func(t *testing.T, plugin *AzureMonitor, metrics []telegraf.Metric) {
|
check: func(t *testing.T, _ *AzureMonitor, metrics []telegraf.Metric) {
|
||||||
expected := []telegraf.Metric{
|
expected := []telegraf.Metric{
|
||||||
testutil.MustMetric(
|
testutil.MustMetric(
|
||||||
"cpu-value",
|
"cpu-value",
|
||||||
|
|
@ -190,7 +190,7 @@ func TestAggregate(t *testing.T) {
|
||||||
},
|
},
|
||||||
addTime: time.Unix(0, 0),
|
addTime: time.Unix(0, 0),
|
||||||
pushTime: time.Unix(3600, 0),
|
pushTime: time.Unix(3600, 0),
|
||||||
check: func(t *testing.T, plugin *AzureMonitor, metrics []telegraf.Metric) {
|
check: func(t *testing.T, _ *AzureMonitor, metrics []telegraf.Metric) {
|
||||||
expected := []telegraf.Metric{
|
expected := []telegraf.Metric{
|
||||||
testutil.MustMetric(
|
testutil.MustMetric(
|
||||||
"cpu-value",
|
"cpu-value",
|
||||||
|
|
@ -292,7 +292,7 @@ func TestWrite(t *testing.T) {
|
||||||
time.Unix(0, 0),
|
time.Unix(0, 0),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
handler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
handler: func(t *testing.T, _ http.ResponseWriter, _ *http.Request) {
|
||||||
t.Fatal("should not call")
|
t.Fatal("should not call")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
stubResult struct {
|
stubResult struct {
|
||||||
metricIds []string
|
metricIDs []string
|
||||||
|
|
||||||
sendError bool
|
sendError bool
|
||||||
err chan error
|
err chan error
|
||||||
|
|
@ -123,7 +123,7 @@ func (t *stubTopic) Publish(ctx context.Context, msg *pubsub.Message) publishRes
|
||||||
|
|
||||||
ids := t.parseIDs(msg)
|
ids := t.parseIDs(msg)
|
||||||
r := &stubResult{
|
r := &stubResult{
|
||||||
metricIds: ids,
|
metricIDs: ids,
|
||||||
err: make(chan error, 1),
|
err: make(chan error, 1),
|
||||||
done: make(chan struct{}, 1),
|
done: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
|
|
@ -172,7 +172,7 @@ func (t *stubTopic) sendBundle() func(items interface{}) {
|
||||||
|
|
||||||
for _, msg := range bundled {
|
for _, msg := range bundled {
|
||||||
r := msg.stubResult
|
r := msg.stubResult
|
||||||
for _, id := range r.metricIds {
|
for _, id := range r.metricIDs {
|
||||||
t.published[id] = msg.Message
|
t.published[id] = msg.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,7 +224,7 @@ func (r *stubResult) Get(ctx context.Context) (string, error) {
|
||||||
case err := <-r.err:
|
case err := <-r.err:
|
||||||
return "", err
|
return "", err
|
||||||
case <-r.done:
|
case <-r.done:
|
||||||
return "id-" + r.metricIds[0], nil
|
return "id-" + r.metricIDs[0], nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func (c *CloudWatchLogs) Connect() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if c.CredentialConfig.EndpointURL != "" && c.CredentialConfig.Region != "" {
|
if c.CredentialConfig.EndpointURL != "" && c.CredentialConfig.Region != "" {
|
||||||
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
customResolver := aws.EndpointResolverWithOptionsFunc(func(string, string, ...interface{}) (aws.Endpoint, error) {
|
||||||
return aws.Endpoint{
|
return aws.Endpoint{
|
||||||
PartitionID: "aws",
|
PartitionID: "aws",
|
||||||
URL: c.CredentialConfig.EndpointURL,
|
URL: c.CredentialConfig.EndpointURL,
|
||||||
|
|
|
||||||
|
|
@ -258,7 +258,7 @@ func TestInit(t *testing.T) {
|
||||||
|
|
||||||
func TestConnect(t *testing.T) {
|
func TestConnect(t *testing.T) {
|
||||||
//mock cloudwatch logs endpoint that is used only in plugin.Connect
|
//mock cloudwatch logs endpoint that is used only in plugin.Connect
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
fmt.Fprintln(w,
|
fmt.Fprintln(w,
|
||||||
`{
|
`{
|
||||||
"logGroups": [
|
"logGroups": [
|
||||||
|
|
@ -298,7 +298,7 @@ func TestConnect(t *testing.T) {
|
||||||
|
|
||||||
func TestWrite(t *testing.T) {
|
func TestWrite(t *testing.T) {
|
||||||
//mock cloudwatch logs endpoint that is used only in plugin.Connect
|
//mock cloudwatch logs endpoint that is used only in plugin.Connect
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
fmt.Fprintln(w,
|
fmt.Fprintln(w,
|
||||||
`{
|
`{
|
||||||
"logGroups": [
|
"logGroups": [
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ func fakeDatadog() *Datadog {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUriOverride(t *testing.T) {
|
func TestUriOverride(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
||||||
}))
|
}))
|
||||||
|
|
@ -50,7 +50,7 @@ func TestUriOverride(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompressionOverride(t *testing.T) {
|
func TestCompressionOverride(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
json.NewEncoder(w).Encode(`{"status":"ok"}`) //nolint:errcheck // Ignore the returned error as the test will fail anyway
|
||||||
}))
|
}))
|
||||||
|
|
@ -67,7 +67,7 @@ func TestCompressionOverride(t *testing.T) {
|
||||||
|
|
||||||
func TestBadStatusCode(t *testing.T) {
|
func TestBadStatusCode(t *testing.T) {
|
||||||
errorString := `{"errors": ["Something bad happened to the server.", "Your query made the server very sad."]}`
|
errorString := `{"errors": ["Something bad happened to the server.", "Your query made the server very sad."]}`
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
fmt.Fprint(w, errorString)
|
fmt.Fprint(w, errorString)
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNilMetrics(t *testing.T) {
|
func TestNilMetrics(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -48,7 +48,7 @@ func TestNilMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyMetricsSlice(t *testing.T) {
|
func TestEmptyMetricsSlice(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -72,7 +72,7 @@ func TestEmptyMetricsSlice(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMockURL(t *testing.T) {
|
func TestMockURL(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
err := json.NewEncoder(w).Encode(`{"linesOk":10,"linesInvalid":0,"error":null}`)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -529,7 +529,7 @@ func (l loggerStub) Warnf(_ string, _ ...interface{}) {
|
||||||
|
|
||||||
func TestSendUnsupportedMetric(t *testing.T) {
|
func TestSendUnsupportedMetric(t *testing.T) {
|
||||||
warnfCalledTimes = 0
|
warnfCalledTimes = 0
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {
|
||||||
t.Fatal("should not export because the only metric is an invalid type")
|
t.Fatal("should not export because the only metric is an invalid type")
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ func TestInitAndWriteIntegration(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// The handler function will pass received messages via the channel
|
// The handler function will pass received messages via the channel
|
||||||
handler := func(ctx context.Context, event *eventhub.Event) error {
|
handler := func(_ context.Context, event *eventhub.Event) error {
|
||||||
exit <- string(event.Data)
|
exit <- string(event.Data)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ func TestHTTPClientConfig(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -265,7 +265,7 @@ func TestStatusCode(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(tt.statusCode)
|
w.WriteHeader(tt.statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -486,7 +486,7 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Add("access_token", token)
|
values.Add("access_token", token)
|
||||||
|
|
@ -514,7 +514,7 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Add("access_token", token)
|
values.Add("access_token", token)
|
||||||
|
|
@ -617,7 +617,7 @@ func TestOAuthAuthorizationCodeGrant(t *testing.T) {
|
||||||
URL: u.String() + "/write",
|
URL: u.String() + "/write",
|
||||||
CredentialsFile: tmpFile.Name(),
|
CredentialsFile: tmpFile.Name(),
|
||||||
},
|
},
|
||||||
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
authHeader := fmt.Sprintf(`{"id_token":%q}`, token)
|
authHeader := fmt.Sprintf(`{"id_token":%q}`, token)
|
||||||
_, err = w.Write([]byte(authHeader))
|
_, err = w.Write([]byte(authHeader))
|
||||||
|
|
@ -705,7 +705,7 @@ func TestBatchedUnbatched(t *testing.T) {
|
||||||
|
|
||||||
for name, serializer := range s {
|
for name, serializer := range s {
|
||||||
var requests int
|
var requests int
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
requests++
|
requests++
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ func TestHTTP_CreateDatabase(t *testing.T) {
|
||||||
URL: u,
|
URL: u,
|
||||||
Database: `a \\ b`,
|
Database: `a \\ b`,
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
// Yes, 200 OK is the correct response...
|
// Yes, 200 OK is the correct response...
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err = w.Write([]byte(`{"results": [{"error": "invalid name", "statement_id": 0}]}`))
|
_, err = w.Write([]byte(`{"results": [{"error": "invalid name", "statement_id": 0}]}`))
|
||||||
|
|
@ -197,7 +197,7 @@ func TestHTTP_CreateDatabase(t *testing.T) {
|
||||||
URL: u,
|
URL: u,
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
},
|
},
|
||||||
errFunc: func(t *testing.T, err error) {
|
errFunc: func(t *testing.T, err error) {
|
||||||
|
|
@ -215,7 +215,7 @@ func TestHTTP_CreateDatabase(t *testing.T) {
|
||||||
URL: u,
|
URL: u,
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -225,7 +225,7 @@ func TestHTTP_CreateDatabase(t *testing.T) {
|
||||||
URL: u,
|
URL: u,
|
||||||
Database: `database`,
|
Database: `database`,
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err = w.Write([]byte(`invalid response`))
|
_, err = w.Write([]byte(`invalid response`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -400,7 +400,7 @@ func TestHTTP_Write(t *testing.T) {
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err = w.Write([]byte(`{"error": "write failed: hinted handoff queue not empty"}`))
|
_, err = w.Write([]byte(`{"error": "write failed: hinted handoff queue not empty"}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -416,7 +416,7 @@ func TestHTTP_Write(t *testing.T) {
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err = w.Write([]byte(`{"error": "partial write: field type conflict:"}`))
|
_, err = w.Write([]byte(`{"error": "partial write: field type conflict:"}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -432,7 +432,7 @@ func TestHTTP_Write(t *testing.T) {
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
_, err = w.Write([]byte(`{"error": "unable to parse 'cpu value': invalid field format"}`))
|
_, err = w.Write([]byte(`{"error": "unable to parse 'cpu value': invalid field format"}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -448,7 +448,7 @@ func TestHTTP_Write(t *testing.T) {
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(_ *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadGateway)
|
w.WriteHeader(http.StatusBadGateway)
|
||||||
},
|
},
|
||||||
errFunc: func(t *testing.T, err error) {
|
errFunc: func(t *testing.T, err error) {
|
||||||
|
|
@ -466,7 +466,7 @@ func TestHTTP_Write(t *testing.T) {
|
||||||
Database: "telegraf",
|
Database: "telegraf",
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
},
|
},
|
||||||
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
_, err = w.Write([]byte(`{"error": "unknown error"}`))
|
_, err = w.Write([]byte(`{"error": "unknown error"}`))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
@ -664,7 +664,7 @@ func TestHTTP_UnixSocket(t *testing.T) {
|
||||||
_, err = w.Write(successResponse)
|
_, err = w.Write(successResponse)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
},
|
},
|
||||||
writeHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
writeHandlerFunc: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
_, err = w.Write(successResponse)
|
_, err = w.Write(successResponse)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,20 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/metric"
|
"github.com/influxdata/telegraf/metric"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/outputs/influxdb"
|
"github.com/influxdata/telegraf/plugins/outputs/influxdb"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MockClient struct {
|
type MockClient struct {
|
||||||
URLF func() string
|
URLF func() string
|
||||||
WriteF func(context.Context, []telegraf.Metric) error
|
WriteF func() error
|
||||||
CreateDatabaseF func(ctx context.Context, database string) error
|
CreateDatabaseF func() error
|
||||||
DatabaseF func() string
|
DatabaseF func() string
|
||||||
CloseF func()
|
CloseF func()
|
||||||
|
|
||||||
|
|
@ -29,12 +30,12 @@ func (c *MockClient) URL() string {
|
||||||
return c.URLF()
|
return c.URLF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) Write(ctx context.Context, metrics []telegraf.Metric) error {
|
func (c *MockClient) Write(context.Context, []telegraf.Metric) error {
|
||||||
return c.WriteF(ctx, metrics)
|
return c.WriteF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) CreateDatabase(ctx context.Context, database string) error {
|
func (c *MockClient) CreateDatabase(context.Context, string) error {
|
||||||
return c.CreateDatabaseF(ctx, database)
|
return c.CreateDatabaseF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MockClient) Database() string {
|
func (c *MockClient) Database() string {
|
||||||
|
|
@ -76,7 +77,7 @@ func TestDefaultURL(t *testing.T) {
|
||||||
DatabaseF: func() string {
|
DatabaseF: func() string {
|
||||||
return "telegraf"
|
return "telegraf"
|
||||||
},
|
},
|
||||||
CreateDatabaseF: func(ctx context.Context, database string) error {
|
CreateDatabaseF: func() error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -139,7 +140,7 @@ func TestConnectHTTPConfig(t *testing.T) {
|
||||||
DatabaseF: func() string {
|
DatabaseF: func() string {
|
||||||
return "telegraf"
|
return "telegraf"
|
||||||
},
|
},
|
||||||
CreateDatabaseF: func(ctx context.Context, database string) error {
|
CreateDatabaseF: func() error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -171,15 +172,15 @@ func TestConnectHTTPConfig(t *testing.T) {
|
||||||
func TestWriteRecreateDatabaseIfDatabaseNotFound(t *testing.T) {
|
func TestWriteRecreateDatabaseIfDatabaseNotFound(t *testing.T) {
|
||||||
output := influxdb.InfluxDB{
|
output := influxdb.InfluxDB{
|
||||||
URLs: []string{"http://localhost:8086"},
|
URLs: []string{"http://localhost:8086"},
|
||||||
CreateHTTPClientF: func(config *influxdb.HTTPConfig) (influxdb.Client, error) {
|
CreateHTTPClientF: func(*influxdb.HTTPConfig) (influxdb.Client, error) {
|
||||||
return &MockClient{
|
return &MockClient{
|
||||||
DatabaseF: func() string {
|
DatabaseF: func() string {
|
||||||
return "telegraf"
|
return "telegraf"
|
||||||
},
|
},
|
||||||
CreateDatabaseF: func(ctx context.Context, database string) error {
|
CreateDatabaseF: func() error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
WriteF: func(ctx context.Context, metrics []telegraf.Metric) error {
|
WriteF: func() error {
|
||||||
return &influxdb.DatabaseNotFoundError{
|
return &influxdb.DatabaseNotFoundError{
|
||||||
APIError: influxdb.APIError{
|
APIError: influxdb.APIError{
|
||||||
StatusCode: http.StatusNotFound,
|
StatusCode: http.StatusNotFound,
|
||||||
|
|
|
||||||
|
|
@ -59,11 +59,11 @@ func (c *MockConn) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockDialer struct {
|
type MockDialer struct {
|
||||||
DialContextF func(network, address string) (influxdb.Conn, error)
|
DialContextF func() (influxdb.Conn, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MockDialer) DialContext(_ context.Context, network string, address string) (influxdb.Conn, error) {
|
func (d *MockDialer) DialContext(context.Context, string, string) (influxdb.Conn, error) {
|
||||||
return d.DialContextF(network, address)
|
return d.DialContextF()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUDP_NewUDPClientNoURL(t *testing.T) {
|
func TestUDP_NewUDPClientNoURL(t *testing.T) {
|
||||||
|
|
@ -90,7 +90,7 @@ func TestUDP_Simple(t *testing.T) {
|
||||||
config := influxdb.UDPConfig{
|
config := influxdb.UDPConfig{
|
||||||
URL: getURL(),
|
URL: getURL(),
|
||||||
Dialer: &MockDialer{
|
Dialer: &MockDialer{
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func() (influxdb.Conn, error) {
|
||||||
conn := &MockConn{
|
conn := &MockConn{
|
||||||
WriteF: func(b []byte) (n int, err error) {
|
WriteF: func(b []byte) (n int, err error) {
|
||||||
buffer.Write(b)
|
buffer.Write(b)
|
||||||
|
|
@ -121,7 +121,7 @@ func TestUDP_DialError(t *testing.T) {
|
||||||
config := influxdb.UDPConfig{
|
config := influxdb.UDPConfig{
|
||||||
URL: u,
|
URL: u,
|
||||||
Dialer: &MockDialer{
|
Dialer: &MockDialer{
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func() (influxdb.Conn, error) {
|
||||||
return nil, errors.New(`unsupported scheme [invalid://localhost:9999]: "invalid"`)
|
return nil, errors.New(`unsupported scheme [invalid://localhost:9999]: "invalid"`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -140,9 +140,9 @@ func TestUDP_WriteError(t *testing.T) {
|
||||||
config := influxdb.UDPConfig{
|
config := influxdb.UDPConfig{
|
||||||
URL: getURL(),
|
URL: getURL(),
|
||||||
Dialer: &MockDialer{
|
Dialer: &MockDialer{
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func() (influxdb.Conn, error) {
|
||||||
conn := &MockConn{
|
conn := &MockConn{
|
||||||
WriteF: func(b []byte) (n int, err error) {
|
WriteF: func(_ []byte) (n int, err error) {
|
||||||
return 0, errors.New("write udp 127.0.0.1:52190->127.0.0.1:9999: write: connection refused")
|
return 0, errors.New("write udp 127.0.0.1:52190->127.0.0.1:9999: write: connection refused")
|
||||||
},
|
},
|
||||||
CloseF: func() error {
|
CloseF: func() error {
|
||||||
|
|
@ -176,7 +176,7 @@ func TestUDP_ErrorLogging(t *testing.T) {
|
||||||
MaxPayloadSize: 1,
|
MaxPayloadSize: 1,
|
||||||
URL: getURL(),
|
URL: getURL(),
|
||||||
Dialer: &MockDialer{
|
Dialer: &MockDialer{
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func() (influxdb.Conn, error) {
|
||||||
conn := &MockConn{}
|
conn := &MockConn{}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
},
|
},
|
||||||
|
|
@ -191,7 +191,7 @@ func TestUDP_ErrorLogging(t *testing.T) {
|
||||||
config: influxdb.UDPConfig{
|
config: influxdb.UDPConfig{
|
||||||
URL: getURL(),
|
URL: getURL(),
|
||||||
Dialer: &MockDialer{
|
Dialer: &MockDialer{
|
||||||
DialContextF: func(network, address string) (influxdb.Conn, error) {
|
DialContextF: func() (influxdb.Conn, error) {
|
||||||
conn := &MockConn{}
|
conn := &MockConn{}
|
||||||
return conn, nil
|
return conn, nil
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ func newTestLibrato(testURL string) *Librato {
|
||||||
func TestUriOverride(t *testing.T) {
|
func TestUriOverride(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(
|
http.HandlerFunc(
|
||||||
func(w http.ResponseWriter, r *http.Request) {
|
func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
@ -43,7 +43,7 @@ func TestUriOverride(t *testing.T) {
|
||||||
|
|
||||||
func TestBadStatusCode(t *testing.T) {
|
func TestBadStatusCode(t *testing.T) {
|
||||||
ts := httptest.NewServer(
|
ts := httptest.NewServer(
|
||||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusServiceUnavailable)
|
w.WriteHeader(http.StatusServiceUnavailable)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,11 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
"github.com/influxdata/telegraf/testutil"
|
"github.com/influxdata/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -52,7 +53,7 @@ func TestParseMetric(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBadStatusCode(t *testing.T) {
|
func TestBadStatusCode(t *testing.T) {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ func TestStatusCode(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(tt.statusCode)
|
w.WriteHeader(tt.statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -368,7 +368,7 @@ func TestOAuthClientCredentialsGrant(t *testing.T) {
|
||||||
TokenURL: u.String() + "/token",
|
TokenURL: u.String() + "/token",
|
||||||
Scopes: []string{"urn:opc:idm:__myscopes__"},
|
Scopes: []string{"urn:opc:idm:__myscopes__"},
|
||||||
},
|
},
|
||||||
tokenHandler: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
|
tokenHandler: func(t *testing.T, w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
values := url.Values{}
|
values := url.Values{}
|
||||||
values.Add("access_token", token)
|
values.Add("access_token", token)
|
||||||
|
|
|
||||||
|
|
@ -98,10 +98,10 @@ func (o *Opensearch) Init() error {
|
||||||
}
|
}
|
||||||
o.pipelineTmpl = pipelineTmpl
|
o.pipelineTmpl = pipelineTmpl
|
||||||
|
|
||||||
o.onSucc = func(ctx context.Context, item opensearchutil.BulkIndexerItem, res opensearchutil.BulkIndexerResponseItem) {
|
o.onSucc = func(_ context.Context, _ opensearchutil.BulkIndexerItem, res opensearchutil.BulkIndexerResponseItem) {
|
||||||
o.Log.Debugf("Indexed to OpenSearch with status- [%d] Result- %s DocumentID- %s ", res.Status, res.Result, res.DocumentID)
|
o.Log.Debugf("Indexed to OpenSearch with status- [%d] Result- %s DocumentID- %s ", res.Status, res.Result, res.DocumentID)
|
||||||
}
|
}
|
||||||
o.onFail = func(ctx context.Context, item opensearchutil.BulkIndexerItem, res opensearchutil.BulkIndexerResponseItem, err error) {
|
o.onFail = func(_ context.Context, _ opensearchutil.BulkIndexerItem, res opensearchutil.BulkIndexerResponseItem, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.Log.Errorf("error while OpenSearch bulkIndexing: %v", err)
|
o.Log.Errorf("error while OpenSearch bulkIndexing: %v", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func BenchmarkHttpSend(b *testing.B) {
|
||||||
metrics = append(metrics, testutil.TestMetric(1.0))
|
metrics = append(metrics, testutil.TestMetric(1.0))
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
fmt.Fprintln(w, "{}")
|
fmt.Fprintln(w, "{}")
|
||||||
}))
|
}))
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ func (p *PrometheusClient) Init() error {
|
||||||
authHandler := internal.BasicAuthHandler(p.BasicUsername, password, "prometheus", onAuthError)
|
authHandler := internal.BasicAuthHandler(p.BasicUsername, password, "prometheus", onAuthError)
|
||||||
rangeHandler := internal.IPRangeHandler(ipRange, onError)
|
rangeHandler := internal.IPRangeHandler(ipRange, onError)
|
||||||
promHandler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError})
|
promHandler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{ErrorHandling: promhttp.ContinueOnError})
|
||||||
landingPageHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
landingPageHandler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
_, err := w.Write([]byte("Telegraf Output Plugin: Prometheus Client "))
|
_, err := w.Write([]byte("Telegraf Output Plugin: Prometheus Client "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Log.Errorf("Error occurred when writing HTTP reply: %v", err)
|
p.Log.Errorf("Error occurred when writing HTTP reply: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -438,7 +438,7 @@ rpc_duration_seconds_count 2693
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write(tt.data)
|
_, err := w.Write(tt.data)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -467,7 +467,7 @@ rpc_duration_seconds_count 2693
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
_, err := w.Write(tt.data)
|
_, err := w.Write(tt.data)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ func TestStatusCode(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts.Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(tt.statusCode)
|
w.WriteHeader(tt.statusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ var WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteCl
|
||||||
}
|
}
|
||||||
|
|
||||||
if credentialConfig.EndpointURL != "" && credentialConfig.Region != "" {
|
if credentialConfig.EndpointURL != "" && credentialConfig.Region != "" {
|
||||||
customResolver := aws.EndpointResolverWithOptionsFunc(func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
customResolver := aws.EndpointResolverWithOptionsFunc(func(string, string, ...interface{}) (aws.Endpoint, error) {
|
||||||
return aws.Endpoint{
|
return aws.Endpoint{
|
||||||
PartitionID: "aws",
|
PartitionID: "aws",
|
||||||
URL: credentialConfig.EndpointURL,
|
URL: credentialConfig.EndpointURL,
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ func (m *mockTimestreamClient) DescribeDatabase(
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnectValidatesConfigParameters(t *testing.T) {
|
func TestConnectValidatesConfigParameters(t *testing.T) {
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return &mockTimestreamClient{}, nil
|
return &mockTimestreamClient{}, nil
|
||||||
}
|
}
|
||||||
// checking base arguments
|
// checking base arguments
|
||||||
|
|
@ -227,7 +227,7 @@ func TestWriteMultiMeasuresSingleTableMode(t *testing.T) {
|
||||||
const recordCount = 100
|
const recordCount = 100
|
||||||
mockClient := &mockTimestreamClient{0}
|
mockClient := &mockTimestreamClient{0}
|
||||||
|
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return mockClient, nil
|
return mockClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,7 +284,7 @@ func TestWriteMultiMeasuresMultiTableMode(t *testing.T) {
|
||||||
const recordCount = 100
|
const recordCount = 100
|
||||||
mockClient := &mockTimestreamClient{0}
|
mockClient := &mockTimestreamClient{0}
|
||||||
|
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return mockClient, nil
|
return mockClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -553,7 +553,7 @@ func (m *mockTimestreamErrorClient) DescribeDatabase(
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestThrottlingErrorIsReturnedToTelegraf(t *testing.T) {
|
func TestThrottlingErrorIsReturnedToTelegraf(t *testing.T) {
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return &mockTimestreamErrorClient{
|
return &mockTimestreamErrorClient{
|
||||||
ErrorToReturnOnWriteRecords: &types.ThrottlingException{Message: aws.String("Throttling Test")},
|
ErrorToReturnOnWriteRecords: &types.ThrottlingException{Message: aws.String("Throttling Test")},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -579,7 +579,7 @@ func TestThrottlingErrorIsReturnedToTelegraf(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRejectedRecordsErrorResultsInMetricsBeingSkipped(t *testing.T) {
|
func TestRejectedRecordsErrorResultsInMetricsBeingSkipped(t *testing.T) {
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return &mockTimestreamErrorClient{
|
return &mockTimestreamErrorClient{
|
||||||
ErrorToReturnOnWriteRecords: &types.RejectedRecordsException{Message: aws.String("RejectedRecords Test")},
|
ErrorToReturnOnWriteRecords: &types.RejectedRecordsException{Message: aws.String("RejectedRecords Test")},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -610,7 +610,7 @@ func TestWriteWhenRequestsGreaterThanMaxWriteGoRoutinesCount(t *testing.T) {
|
||||||
const totalRecords = maxWriteRecordsCalls * maxRecordsInWriteRecordsCall
|
const totalRecords = maxWriteRecordsCalls * maxRecordsInWriteRecordsCall
|
||||||
mockClient := &mockTimestreamClient{0}
|
mockClient := &mockTimestreamClient{0}
|
||||||
|
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return mockClient, nil
|
return mockClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -649,7 +649,7 @@ func TestWriteWhenRequestsLesserThanMaxWriteGoRoutinesCount(t *testing.T) {
|
||||||
const totalRecords = maxWriteRecordsCalls * maxRecordsInWriteRecordsCall
|
const totalRecords = maxWriteRecordsCalls * maxRecordsInWriteRecordsCall
|
||||||
mockClient := &mockTimestreamClient{0}
|
mockClient := &mockTimestreamClient{0}
|
||||||
|
|
||||||
WriteFactory = func(credentialConfig *internalaws.CredentialConfig) (WriteClient, error) {
|
WriteFactory = func(*internalaws.CredentialConfig) (WriteClient, error) {
|
||||||
return mockClient, nil
|
return mockClient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ func LoadTypesDB(path string) (*api.TypesDB, error) {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
parsers.Add("collectd",
|
parsers.Add("collectd",
|
||||||
func(_ string) telegraf.Parser {
|
func(string) telegraf.Parser {
|
||||||
return &Parser{
|
return &Parser{
|
||||||
AuthFile: DefaultAuthFile,
|
AuthFile: DefaultAuthFile,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -233,7 +233,7 @@ func (p *Parser) Init() error {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
parsers.Add("dropwizard",
|
parsers.Add("dropwizard",
|
||||||
func(defaultMetricName string) telegraf.Parser {
|
func(string) telegraf.Parser {
|
||||||
return &Parser{}
|
return &Parser{}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,5 +194,5 @@ func (p *Parser) SetDefaultTags(tags map[string]string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
parsers.Add("graphite", func(_ string) telegraf.Parser { return &Parser{} })
|
parsers.Add("graphite", func(string) telegraf.Parser { return &Parser{} })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue