Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.
Open
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
43 changes: 43 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# tools
required = [
"github.com/jstemmer/go-junit-report",
"golang.org/x/tools/cmd/goimports",
"github.com/jstemmer/go-junit-report",
]

[prune]
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
all: build

init:
go install ./vendor/github.com/jstemmer/go-junit-report
go install ./vendor/golang.org/x/tools/cmd/goimports \
./vendor/github.com/jstemmer/go-junit-report

build:
go install -v ./...
Expand Down
2 changes: 2 additions & 0 deletions inventory/agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,8 @@ func TestPostgresExporter(t *testing.T) {
},

SkipConnectionCheck: true,
TLS: true,
TLSSkipVerify: false,
})
agentID := PostgresExporter.PostgresExporter.AgentID
defer pmmapitests.RemoveAgents(t, agentID)
Expand Down
138 changes: 138 additions & 0 deletions management/mongodb_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,161 @@
package management

import (
"fmt"
"testing"
"time"

"github.com/AlekSi/pointer"
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
inventoryClient "github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/percona/pmm/api/inventorypb/json/client/services"
"github.com/percona/pmm/api/managementpb/json/client"
"github.com/percona/pmm/api/managementpb/json/client/actions"
mongodb "github.com/percona/pmm/api/managementpb/json/client/mongo_db"
"github.com/percona/pmm/api/managementpb/json/client/node"
"github.com/percona/pmm/api/managementpb/json/client/service"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson"
"google.golang.org/grpc/codes"

pmmapitests "github.com/Percona-Lab/pmm-api-tests"
)

func TestMongoDBExplain(t *testing.T) {
t.Run("MongoDB explain", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "node-name-for-all-fields")
nodeID, pmmAgentID := registerGenericNode(t, node.RegisterBody{
NodeName: nodeName,
NodeType: pointer.ToString(node.RegisterBodyNodeTypeGENERICNODE),
})
defer pmmapitests.RemoveNodes(t, nodeID)
defer removePMMAgentWithSubAgents(t, pmmAgentID)

serviceName := pmmapitests.TestString(t, "service-name-for-all-fields")

params := &mongodb.AddMongoDBParams{
Context: pmmapitests.Context,
Body: mongodb.AddMongoDBBody{
NodeID: nodeID,
PMMAgentID: pmmAgentID,
ServiceName: serviceName,
Address: "10.10.10.10",
Port: 27017,
Username: "username",
Password: "password",
QANMongodbProfiler: true,

SkipConnectionCheck: true,
},
}
addMongoDBOK, err := client.Default.MongoDB.AddMongoDB(params)
require.NoError(t, err)
require.NotNil(t, addMongoDBOK)
require.NotNil(t, addMongoDBOK.Payload.Service)
serviceID := addMongoDBOK.Payload.Service.ServiceID
fmt.Printf("ServiceID: %s\n", serviceID)
defer pmmapitests.RemoveServices(t, serviceID)

// Check that service is created and its fields.
serviceOK, err := inventoryClient.Default.Services.GetService(&services.GetServiceParams{
Body: services.GetServiceBody{
ServiceID: serviceID,
},
Context: pmmapitests.Context,
})
assert.NoError(t, err)
assert.NotNil(t, serviceOK)
assert.Equal(t, services.GetServiceOKBody{
Mongodb: &services.GetServiceOKBodyMongodb{
ServiceID: serviceID,
NodeID: nodeID,
ServiceName: serviceName,
Address: "10.10.10.10",
Port: 27017,
},
}, *serviceOK.Payload)

// --------------------------------------------------------------------------------------
eq := proto.ExampleQuery{
Ns: "test.coll",
Op: "query",
Query: proto.BsonD{
{
Key: "k",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown field Key in struct literal (from typecheck)

Value: proto.BsonD{
{
Key: "$lte",
Value: int32(1),
},
},
},
},
Command: nil,
OriginatingCommand: nil,
UpdateObj: nil,
}
buf, _ := bson.MarshalExtJSON(eq, true, true)
explainActionOK, err := client.Default.Actions.StartMongoDBExplainAction(&actions.StartMongoDBExplainActionParams{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client.Default.Actions.StartMongoDBExplainAction undefined (type *actions.Client has no field or method StartMongoDBExplainAction) (from typecheck)

Context: pmmapitests.Context,
Body: actions.StartMongoDBExplainActionBody{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StartMongoDBExplainActionBody not declared by package actions (from typecheck)

//PMMAgentID: "/agent_id/f235005b-9cca-4b73-bbbd-1251067c3138",
ServiceID: serviceID,
Database: "test",
Query: string(buf),
},
})
require.NoError(t, err)
require.NotEmpty(t, explainActionOK.Payload.ActionID)

time.Sleep(2 * time.Second)

actionOK, err := client.Default.Actions.GetAction(&actions.GetActionParams{
Context: pmmapitests.Context,
Body: actions.GetActionBody{
ActionID: explainActionOK.Payload.ActionID,
},
})
require.NoError(t, err)
require.Empty(t, actionOK.Payload.Error)
// --------------------------------------------------------------------------------------
// Check that exporters are added.
listAgents, err := inventoryClient.Default.Agents.ListAgents(&agents.ListAgentsParams{
Context: pmmapitests.Context,
Body: agents.ListAgentsBody{
ServiceID: serviceID,
},
})
assert.NoError(t, err)
require.NotNil(t, listAgents)
defer removeAllAgentsInList(t, listAgents)

require.Len(t, listAgents.Payload.MongodbExporter, 1)
require.Len(t, listAgents.Payload.QANMongodbProfilerAgent, 1)
assert.Equal(t, agents.ListAgentsOKBody{
MongodbExporter: []*agents.MongodbExporterItems0{
{
AgentID: listAgents.Payload.MongodbExporter[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
Password: "password",
},
},
QANMongodbProfilerAgent: []*agents.QANMongodbProfilerAgentItems0{
{
AgentID: listAgents.Payload.QANMongodbProfilerAgent[0].AgentID,
ServiceID: serviceID,
PMMAgentID: pmmAgentID,
Username: "username",
Password: "password",
},
},
}, *listAgents.Payload)
})
}

func TestAddMongoDB(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
nodeName := pmmapitests.TestString(t, "node-for-basic-name")
Expand Down
Loading