Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.
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
4 changes: 2 additions & 2 deletions Gopkg.lock

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

3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ func runGRPCServer(ctx context.Context, deps *serviceDependencies) {
mysqlSvc := management.NewMySQLService(deps.db, deps.agentsRegistry)
nodeSvc := management.NewNodeService(deps.db, deps.agentsRegistry)
serviceSvc := management.NewServiceService(deps.db, deps.agentsRegistry)
mongodbSvc := management.NewMongoDBService(deps.db, deps.agentsRegistry)

managementpb.RegisterMySQLServer(gRPCServer, managementgrpc.NewManagementMysqlServer(mysqlSvc))
managementpb.RegisterNodeServer(gRPCServer, managementgrpc.NewManagementNodeServer(nodeSvc))
managementpb.RegisterServiceServer(gRPCServer, managementgrpc.NewManagementServiceServer(serviceSvc))
managementpb.RegisterMongoDBServer(gRPCServer, managementgrpc.NewManagementMongoDBServer(mongodbSvc))

if *debugF {
l.Debug("Reflection and channelz are enabled.")
Expand Down Expand Up @@ -222,6 +224,7 @@ func runJSONServer(ctx context.Context, logs *logs.Logs) {
managementpb.RegisterMySQLHandlerFromEndpoint,
managementpb.RegisterNodeHandlerFromEndpoint,
managementpb.RegisterServiceHandlerFromEndpoint,
managementpb.RegisterMongoDBHandlerFromEndpoint,
} {
if err := r(ctx, proxyMux, *gRPCAddrF, opts); err != nil {
l.Panic(err)
Expand Down
39 changes: 39 additions & 0 deletions services/management/grpc/mongodb_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package grpc

import (
"context"

"github.com/percona/pmm/api/managementpb"

"github.com/percona/pmm-managed/services/management"
)

type mongodbServer struct {
svc *management.MongoDBService
}

// NewManagementMongoDBServer creates Management MongoDB Server.
func NewManagementMongoDBServer(s *management.MongoDBService) managementpb.MongoDBServer {
return &mongodbServer{svc: s}
}

// AddMongoDB adds "MongoDB Service", "MongoDB Exporter Agent" and "QAN MongoDB Profiler".
func (s *mongodbServer) AddMongoDB(ctx context.Context, req *managementpb.AddMongoDBRequest) (*managementpb.AddMongoDBResponse, error) {
return s.svc.Add(ctx, req)
}
4 changes: 2 additions & 2 deletions services/management/grpc/mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewManagementMysqlServer(s *management.MySQLService) managementpb.MySQLServ
return &mysqlServer{svc: s}
}

// Add adds "MySQL Service", "MySQL Exporter Agent" and "QAN MySQL PerfSchema Agent".
func (s *mysqlServer) Add(ctx context.Context, req *managementpb.AddMySQLRequest) (*managementpb.AddMySQLResponse, error) {
// AddMySQL adds "MySQL Service", "MySQL Exporter Agent" and "QAN MySQL PerfSchema Agent".
func (s *mysqlServer) AddMySQL(ctx context.Context, req *managementpb.AddMySQLRequest) (*managementpb.AddMySQLResponse, error) {
return s.svc.Add(ctx, req)
}
119 changes: 119 additions & 0 deletions services/management/mongodb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// pmm-managed
// Copyright (C) 2017 Percona LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package management

import (
"context"

"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/api/managementpb"
"gopkg.in/reform.v1"

"github.com/percona/pmm-managed/models"

// FIXME Refactor, as service shouldn't depend on other service in one abstraction level.
// https://jira.percona.com/browse/PMM-3541
// See also main_test.go
"github.com/percona/pmm-managed/services/inventory"
)

// MongoDBService MongoDB Management Service.
//nolint:unused
type MongoDBService struct {
Comment thread
idexter marked this conversation as resolved.
db *reform.DB
registry registry
}

// NewMongoDBService creates new MySQL Management Service.
func NewMongoDBService(db *reform.DB, registry registry) *MongoDBService {
return &MongoDBService{db, registry}
}

// Add adds "MongoDB Service", "MongoDB Exporter Agent" and "QAN MongoDB Profiler".
func (s *MongoDBService) Add(ctx context.Context, req *managementpb.AddMongoDBRequest) (res *managementpb.AddMongoDBResponse, err error) {
res = &managementpb.AddMongoDBResponse{}

if e := s.db.InTransaction(func(tx *reform.TX) error {
service, err := models.AddNewService(tx.Querier, models.MongoDBServiceType, &models.AddDBMSServiceParams{
ServiceName: req.ServiceName,
NodeID: req.NodeId,
Address: pointer.ToStringOrNil(req.Address),
Port: pointer.ToUint16OrNil(uint16(req.Port)),
})

if err != nil {
return err
}

invService, err := inventory.ToInventoryService(service)
if err != nil {
return err
}

res.Service = invService.(*inventorypb.MongoDBService)

if req.MongodbExporter {
params := &models.AddExporterAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: invService.ID(),
Username: req.Username,
Password: req.Password,
}
row, err := models.AgentAddExporter(tx.Querier, models.MongoDBExporterType, params)
if err != nil {
return err
}

agent, err := inventory.ToInventoryAgent(tx.Querier, row, s.registry)
if err != nil {
return err
}

res.MongodbExporter = agent.(*inventorypb.MongoDBExporter)
}

if req.QanMongodbProfiler {
params := &models.AddExporterAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: invService.ID(),
Username: req.Username,
Password: req.Password,
}

row, err := models.AgentAddExporter(tx.Querier, models.QANMongoDBProfilerAgentType, params)
if err != nil {
return err
}

qAgent, err := inventory.ToInventoryAgent(tx.Querier, row, s.registry)
if err != nil {
return err
}

res.QanMongodbProfiler = qAgent.(*inventorypb.QANMongoDBProfilerAgent)
}

return nil
}); e != nil {
return nil, e
}

s.registry.SendSetStateRequest(ctx, req.PmmAgentId)

return res, nil
}
2 changes: 0 additions & 2 deletions services/management/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
res.Service = invService.(*inventorypb.MySQLService)

if req.MysqldExporter {

params := &models.AddExporterAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: invService.ID(),
Expand All @@ -88,7 +87,6 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
}

if req.QanMysqlPerfschema {

params := &models.AddExporterAgentParams{
PMMAgentID: req.PmmAgentId,
ServiceID: invService.ID(),
Expand Down
Loading