Skip to content

Commit

Permalink
PMM-11341 Add check for auto discovery limit value.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Nov 1, 2023
1 parent b5e94c2 commit e1435a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions admin/commands/inventory/add_agent_postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/percona/pmm/admin/commands"
"github.com/percona/pmm/api/inventorypb/json/client"
"github.com/percona/pmm/api/inventorypb/json/client/agents"
"github.com/pkg/errors"
)

var addAgentPostgresExporterResultT = commands.ParseTemplate(`
Expand Down Expand Up @@ -89,6 +90,10 @@ func (cmd *AddAgentPostgresExporterCommand) RunCmd() (commands.Result, error) {
}
}

if cmd.AutoDiscoveryLimit < 0 {
return nil, errors.Errorf("auto discovery limit cannot be lower than 0")
}

params := &agents.AddPostgresExporterParams{
Body: agents.AddPostgresExporterBody{
PMMAgentID: cmd.PMMAgentID,
Expand Down
5 changes: 5 additions & 0 deletions admin/commands/management/add_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"strings"

"github.com/AlekSi/pointer"
"github.com/pkg/errors"

"github.com/percona/pmm/admin/agentlocal"
"github.com/percona/pmm/admin/commands"
Expand Down Expand Up @@ -170,6 +171,10 @@ func (cmd *AddPostgreSQLCommand) RunCmd() (commands.Result, error) {
}
}

if cmd.AutoDiscoveryLimit < 0 {
return nil, errors.Errorf("auto discovery limit cannot be lower than 0")
}

params := &postgresql.AddPostgreSQLParams{
Body: postgresql.AddPostgreSQLBody{
NodeID: cmd.NodeID,
Expand Down
5 changes: 5 additions & 0 deletions managed/services/inventory/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/AlekSi/pointer"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gopkg.in/reform.v1"
Expand Down Expand Up @@ -500,6 +501,10 @@ func (as *AgentsService) ChangeQANMySQLSlowlogAgent(ctx context.Context, req *in

// AddPostgresExporter inserts postgres_exporter Agent with given parameters.
func (as *AgentsService) AddPostgresExporter(ctx context.Context, req *inventorypb.AddPostgresExporterRequest) (*inventorypb.PostgresExporter, error) {
if req.AutoDiscoveryLimit < 0 {
return nil, errors.New("auto discovery limit cannot be lower than 0")
}

var res *inventorypb.PostgresExporter
e := as.db.InTransaction(func(tx *reform.TX) error {
params := &models.CreateAgentParams{
Expand Down
5 changes: 5 additions & 0 deletions managed/services/management/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"

"github.com/AlekSi/pointer"
"github.com/pkg/errors"
"gopkg.in/reform.v1"

"github.com/percona/pmm/api/inventorypb"
Expand Down Expand Up @@ -47,6 +48,10 @@ func NewPostgreSQLService(db *reform.DB, state agentsStateUpdater, cc connection

// Add adds "PostgreSQL Service", "PostgreSQL Exporter Agent" and "QAN PostgreSQL PerfSchema Agent".
func (s *PostgreSQLService) Add(ctx context.Context, req *managementpb.AddPostgreSQLRequest) (*managementpb.AddPostgreSQLResponse, error) {
if req.AutoDiscoveryLimit < 0 {
return nil, errors.New("auto discovery limit cannot be lower than 0")
}

res := &managementpb.AddPostgreSQLResponse{}

if e := s.db.InTransaction(func(tx *reform.TX) error {
Expand Down

0 comments on commit e1435a3

Please sign in to comment.