Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inputs.mongodb): update version check for newer versions #11635

Merged
merged 2 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/inputs/mongodb/mongodb_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func poolStatsCommand(version string) (string, error) {
return "", err
}

if major == 5 {
if major >= 5 {
return "connPoolStats", nil
}
return "shardConnPoolStats", nil
Expand Down
75 changes: 68 additions & 7 deletions plugins/inputs/mongodb/mongodb_server_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
//go:build integration
// +build integration

package mongodb

import (
"fmt"
"testing"

"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"

"github.com/influxdata/telegraf/testutil"
)

func TestGetDefaultTags(t *testing.T) {
var ServicePort = "27017"

func createTestServer(t *testing.T) *testutil.Container {
container := testutil.Container{
Image: "mongo",
ExposedPorts: []string{ServicePort},
WaitingFor: wait.ForAll(
wait.NewHTTPStrategy("/").WithPort(nat.Port(ServicePort)),
wait.ForLog("Waiting for connections"),
),
}
err := container.Start()
require.NoError(t, err, "failed to start container")

return &container
}

func TestGetDefaultTagsIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

container := createTestServer(t)
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

m := &MongoDB{
Log: testutil.Logger{},
Servers: []string{
fmt.Sprintf("mongodb://%s:%s", container.Address, container.Ports[ServicePort]),
},
}
err := m.Init()
require.NoError(t, err)

server := m.clients[0]

var tagTests = []struct {
in string
out string
Expand All @@ -26,10 +63,29 @@ func TestGetDefaultTags(t *testing.T) {
}
}

func TestAddDefaultStats(t *testing.T) {
var acc testutil.Accumulator
func TestAddDefaultStatsIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}

err := server.gatherData(&acc, false, true, true, true, []string{"local"})
container := createTestServer(t)
defer func() {
require.NoError(t, container.Terminate(), "terminating container failed")
}()

m := &MongoDB{
Log: testutil.Logger{},
Servers: []string{
fmt.Sprintf("mongodb://%s:%s", container.Address, container.Ports[ServicePort]),
},
}
err := m.Init()
require.NoError(t, err)

server := m.clients[0]

var acc testutil.Accumulator
err = server.gatherData(&acc, false, true, true, true, []string{"local"})
require.NoError(t, err)

// need to call this twice so it can perform the diff
Expand Down Expand Up @@ -63,6 +119,11 @@ func TestPoolStatsVersionCompatibility(t *testing.T) {
version: "5.0.0",
expectedCommand: "connPoolStats",
},
{
name: "mongodb v6",
version: "6.0.0",
expectedCommand: "connPoolStats",
},
{
name: "invalid version",
version: "v4",
Expand Down
53 changes: 0 additions & 53 deletions plugins/inputs/mongodb/mongodb_test.go

This file was deleted.