Skip to content

Commit

Permalink
PMM-12375 move GetInfoFromService to serviceInfoBroker
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Tymchuk committed Sep 16, 2023
1 parent 06d99a8 commit f1a259a
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 52 deletions.
2 changes: 1 addition & 1 deletion agent/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ loop:
responsePayload = c.connectionChecker.Check(ctx, p, req.ID)

case *agentpb.ServiceInfoRequest:
responsePayload = c.serviceInfoBroker.GetServiceInfo(ctx, p, req.ID)
responsePayload = c.serviceInfoBroker.GetInfoFromService(ctx, p, req.ID)

case *agentpb.StartJobRequest:
var resp agentpb.StartJobResponse
Expand Down
2 changes: 1 addition & 1 deletion agent/client/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type connectionChecker interface {

// serviceInfoBroker is a subset of methods of serviceinfobroker.ServiceInfoBroker used by this package.
type serviceInfoBroker interface {
GetServiceInfo(ctx context.Context, req *agentpb.ServiceInfoRequest, id uint32) *agentpb.ServiceInfoResponse
GetInfoFromService(ctx context.Context, req *agentpb.ServiceInfoRequest, id uint32) *agentpb.ServiceInfoResponse
}

// softwareVersioner is a subset of methods of version.Versioner used by this package.
Expand Down
4 changes: 2 additions & 2 deletions agent/client/mock_service_info_broker_test.go

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

4 changes: 2 additions & 2 deletions agent/serviceinfobroker/service_info_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ func (cc *ServiceInfoBroker) checkExternalConnection(ctx context.Context, uri st
return &res
}

// GetServiceInfo gathers information from a service. It returns context cancelation/timeout or driver errors as is.
func (cc *ServiceInfoBroker) GetServiceInfo(ctx context.Context, msg *agentpb.ServiceInfoRequest, id uint32) *agentpb.ServiceInfoResponse {
// GetInfoFromService gathers information from a service. It returns context cancelation/timeout or driver errors as is.
func (cc *ServiceInfoBroker) GetInfoFromService(ctx context.Context, msg *agentpb.ServiceInfoRequest, id uint32) *agentpb.ServiceInfoResponse {
timeout := msg.Timeout.AsDuration()
if timeout > 0 {
var cancel context.CancelFunc
Expand Down
11 changes: 6 additions & 5 deletions managed/cmd/pmm-managed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type gRPCServerDeps struct {
actions *agents.ActionsService
agentsStateUpdater *agents.StateUpdater
connectionCheck *agents.ConnectionChecker
serviceInfoBroker *agents.ServiceInfoBroker
grafanaClient *grafana.Client
checksService *checks.Service
dbaasClient *dbaas.Client
Expand Down Expand Up @@ -259,7 +260,7 @@ func runGRPCServer(ctx context.Context, deps *gRPCServerDeps) {
servicesSvc := inventory.NewServicesService(deps.db, deps.agentsRegistry, deps.agentsStateUpdater, deps.vmdb, deps.versionCache)
agentsSvc := inventory.NewAgentsService(
deps.db, deps.agentsRegistry, deps.agentsStateUpdater,
deps.vmdb, deps.connectionCheck, deps.agentService)
deps.vmdb, deps.connectionCheck, deps.serviceInfoBroker, deps.agentService)

mgmtBackupsService := managementbackup.NewBackupsService(deps.db, deps.backupService, deps.compatibilityService, deps.schedulerService)
mgmtArtifactsService := managementbackup.NewArtifactsService(deps.db, deps.backupRemovalService, deps.pbmPITRService)
Expand All @@ -273,10 +274,10 @@ func runGRPCServer(ctx context.Context, deps *gRPCServerDeps) {
nodeSvc := management.NewNodeService(deps.db, deps.grafanaClient)
agentSvc := management.NewAgentService(deps.db, deps.agentsRegistry)
serviceSvc := management.NewServiceService(deps.db, deps.agentsRegistry, deps.agentsStateUpdater, deps.vmdb)
mysqlSvc := management.NewMySQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.versionCache)
mongodbSvc := management.NewMongoDBService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.versionCache)
postgresqlSvc := management.NewPostgreSQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck)
proxysqlSvc := management.NewProxySQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck)
mysqlSvc := management.NewMySQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.serviceInfoBroker, deps.versionCache)
mongodbSvc := management.NewMongoDBService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.serviceInfoBroker, deps.versionCache)
postgresqlSvc := management.NewPostgreSQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.serviceInfoBroker)
proxysqlSvc := management.NewProxySQLService(deps.db, deps.agentsStateUpdater, deps.connectionCheck, deps.serviceInfoBroker)

managementpb.RegisterNodeServer(gRPCServer, managementgrpc.NewManagementNodeServer(nodeSvc))
agentv1beta1.RegisterAgentServer(gRPCServer, agentSvc)
Expand Down
12 changes: 7 additions & 5 deletions managed/services/inventory/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,19 @@ type AgentsService struct {
vmdb prometheusService
db *reform.DB
cc connectionChecker
sib serviceInfoBroker
}

// NewAgentsService creates new AgentsService.
func NewAgentsService(db *reform.DB, r agentsRegistry, state agentsStateUpdater, vmdb prometheusService, cc connectionChecker, a agentService) *AgentsService {
func NewAgentsService(db *reform.DB, r agentsRegistry, state agentsStateUpdater, vmdb prometheusService, cc connectionChecker, sib serviceInfoBroker, a agentService) *AgentsService {
return &AgentsService{
r: r,
a: a,
state: state,
vmdb: vmdb,
db: db,
cc: cc,
sib: sib,
}
}

Expand Down Expand Up @@ -271,7 +273,7 @@ func (as *AgentsService) AddMySQLdExporter(ctx context.Context, req *inventorypb
}
}

if err = as.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = as.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down Expand Up @@ -336,7 +338,7 @@ func (as *AgentsService) AddMongoDBExporter(ctx context.Context, req *inventoryp
}
}

if err = as.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = as.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down Expand Up @@ -530,7 +532,7 @@ func (as *AgentsService) AddPostgresExporter(ctx context.Context, req *inventory
}
}

if err = as.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = as.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down Expand Up @@ -658,7 +660,7 @@ func (as *AgentsService) AddProxySQLExporter(ctx context.Context, req *inventory
}
}

if err = as.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = as.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down
5 changes: 5 additions & 0 deletions managed/services/inventory/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
//go:generate ../../../bin/mockery --name=agentsStateUpdater --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=prometheusService --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=connectionChecker --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=serviceInfoBroker --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=versionCache --case=snake --inpackage --testonly
//go:generate ../../../bin/mockery --name=inventoryMetrics --case=snake --inpackage --testonly

Expand Down Expand Up @@ -62,6 +63,10 @@ type prometheusService interface {
// We use it instead of real type for testing and to avoid dependency cycle.
type connectionChecker interface {
CheckConnectionToService(ctx context.Context, q *reform.Querier, service *models.Service, agent *models.Agent) error
}

// serviceInfoBroker is a subset of methods of serviceinfobroker.ServiceInfoBroker used by this package.
type serviceInfoBroker interface {
GetInfoFromService(ctx context.Context, q *reform.Querier, service *models.Service, agent *models.Agent) error
}

Expand Down
14 changes: 0 additions & 14 deletions managed/services/inventory/mock_connection_checker_test.go

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

46 changes: 46 additions & 0 deletions managed/services/inventory/mock_service_info_broker_test.go

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

4 changes: 4 additions & 0 deletions managed/services/management/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ type jobsService interface { //nolint:unused
// We use it instead of real type for testing and to avoid dependency cycle.
type connectionChecker interface {
CheckConnectionToService(ctx context.Context, q *reform.Querier, service *models.Service, agent *models.Agent) error
}

// serviceInfoBroker is a subset of methods of serviceinfobroker.ServiceInfoBroker used by this package.
type serviceInfoBroker interface {
GetInfoFromService(ctx context.Context, q *reform.Querier, service *models.Service, agent *models.Agent) error
}

Expand Down
14 changes: 0 additions & 14 deletions managed/services/management/mock_connection_checker_test.go

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

6 changes: 4 additions & 2 deletions managed/services/management/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ type MongoDBService struct {
db *reform.DB
state agentsStateUpdater
cc connectionChecker
sib serviceInfoBroker
vc versionCache
}

// NewMongoDBService creates new MongoDB Management Service.
func NewMongoDBService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, vc versionCache) *MongoDBService {
func NewMongoDBService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, sib serviceInfoBroker, vc versionCache) *MongoDBService {
return &MongoDBService{
db: db,
state: state,
cc: cc,
sib: sib,
vc: vc,
}
}
Expand Down Expand Up @@ -105,7 +107,7 @@ func (s *MongoDBService) Add(ctx context.Context, req *managementpb.AddMongoDBRe
}
}

if err = s.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = s.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions managed/services/management/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ type MySQLService struct {
state agentsStateUpdater
cc connectionChecker
vc versionCache
sib serviceInfoBroker
}

// NewMySQLService creates new MySQL Management Service.
func NewMySQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, vc versionCache) *MySQLService {
func NewMySQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, sib serviceInfoBroker, vc versionCache) *MySQLService {
return &MySQLService{
db: db,
state: state,
cc: cc,
sib: sib,
vc: vc,
}
}
Expand Down Expand Up @@ -129,7 +131,7 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
res.TableCount = *row.TableCount
}

if err = s.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = s.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions managed/services/management/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ type PostgreSQLService struct {
db *reform.DB
state agentsStateUpdater
cc connectionChecker
sib serviceInfoBroker
}

// NewPostgreSQLService creates new PostgreSQL Management Service.
func NewPostgreSQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker) *PostgreSQLService {
func NewPostgreSQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, sib serviceInfoBroker) *PostgreSQLService {
return &PostgreSQLService{
db: db,
state: state,
cc: cc,
sib: sib,
}
}

Expand Down Expand Up @@ -103,7 +105,7 @@ func (s *PostgreSQLService) Add(ctx context.Context, req *managementpb.AddPostgr
}
}

if err = s.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = s.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions managed/services/management/proxysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ type ProxySQLService struct {
db *reform.DB
state agentsStateUpdater
cc connectionChecker
sib serviceInfoBroker
}

// NewProxySQLService creates new ProxySQL Management Service.
func NewProxySQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker) *ProxySQLService {
func NewProxySQLService(db *reform.DB, state agentsStateUpdater, cc connectionChecker, sib serviceInfoBroker) *ProxySQLService {
return &ProxySQLService{
db: db,
state: state,
cc: cc,
sib: sib,
}
}

Expand Down Expand Up @@ -100,7 +102,7 @@ func (s *ProxySQLService) Add(ctx context.Context, req *managementpb.AddProxySQL
}
}

if err = s.cc.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
if err = s.sib.GetInfoFromService(ctx, tx.Querier, service, row); err != nil {
return err
}

Expand Down

0 comments on commit f1a259a

Please sign in to comment.