Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

PMM-9968 pmm-admin inventory add agent * --log-level #1134

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/minio/minio-go/v7 v7.0.26
github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472
github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16
github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8
github.com/percona/pmm v0.0.0-20220525201549-eda29cad842f
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472 h1:Henk
github.com/percona-platform/dbaas-api v0.0.0-20220110092915-5aacd784d472/go.mod h1:WZZ3Hi+lAWCaGWmsrfkkvRQPkIa8n1OZ0s8Su+vbgus=
github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16 h1:0fx16uGtl4MwrBwm9/VSoNEhjL0cXYxS0quEhLthGcc=
github.com/percona-platform/saas v0.0.0-20220427162947-f9d246ad0f16/go.mod h1:gFUwaFp6Ugu5qsBwiOVJYbDlzgZ77tmXdXGO7tG5xVI=
github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8 h1:P5iuV4GRUIviRg/5/FM6ZOKdiBPdwUPbrHld/epM3hk=
github.com/percona/pmm v0.0.0-20220520150831-23069cdf1bb8/go.mod h1:gr+WLd8clEAe2xMFgsGhpw9ziZc2UCWcfy6d3M6Aq00=
github.com/percona/pmm v0.0.0-20220525201549-eda29cad842f h1:intEr6g51IIzN55MFH37uEte6x+jaObb/a19dYMzMdY=
github.com/percona/pmm v0.0.0-20220525201549-eda29cad842f/go.mod h1:gr+WLd8clEAe2xMFgsGhpw9ziZc2UCWcfy6d3M6Aq00=
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54 h1:aI1emmycDTGWKsBdxFPKZqohfBbK4y2ta9G4+RX7gVg=
github.com/percona/promconfig v0.2.4-0.20211110115058-98687f586f54/go.mod h1:Y2uXi5QNk71+ceJHuI9poank+0S1kjxd3K105fXKVkg=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
Expand Down
9 changes: 9 additions & 0 deletions models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/AlekSi/pointer"
"github.com/google/uuid"
"github.com/percona/pmm/api/inventorypb"
Copy link
Member

Choose a reason for hiding this comment

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

Package "github.com/percona/pmm-managed/models" should not import package "github.com/percona/pmm/api/inventorypb" (blacklisted by "github.com/percona/pmm/api").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So i SpecifyLogLevel use inside:

  • "github.com/percona/pmm-managed/services/inventory"
  • "github.com/percona/pmm-managed/services/management"

Both use "github.com/percona/pmm-managed/services"
So i will move "SpecifyLogLevel" to "github.com/percona/pmm-managed/services"

"github.com/percona/pmm/version"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -935,6 +936,14 @@ func RemoveAgent(q *reform.Querier, id string, mode RemoveMode) (*Agent, error)
return a, nil
}

func SpecifyLogLevel(variant inventorypb.LogLevel) string {
if variant == inventorypb.LogLevel_auto {
return ""
}

return variant.String()
}

// updateExternalExporterParams updates RunsOnNodeID and PMMAgentID params
// for external exporter, is needed for push_metrics mode.
func updateExternalExporterParams(q *reform.Querier, row *Agent) error {
Expand Down
6 changes: 5 additions & 1 deletion services/agents/azure_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/version"
"github.com/pkg/errors"

"github.com/percona/pmm-managed/models"
Expand Down Expand Up @@ -53,7 +54,9 @@ resource_groups:
`

// azureDatabaseExporterConfig returns configuration of azure_database_exporter process.
func azureDatabaseExporterConfig(exporter *models.Agent, service *models.Service, redactMode redactMode) (*agentpb.SetStateRequest_AgentProcess, error) {
func azureDatabaseExporterConfig(exporter *models.Agent, service *models.Service, redactMode redactMode,
pmmAgentVersion *version.Parsed,
) (*agentpb.SetStateRequest_AgentProcess, error) {
t, err := template.New("credentials").Parse(azureDatabaseTemplate)
if err != nil {
return nil, err
Expand Down Expand Up @@ -95,6 +98,7 @@ func azureDatabaseExporterConfig(exporter *models.Agent, service *models.Service
"--config.file=" + tdp.Left + " .TextFiles.config " + tdp.Right,
"--web.listen-address=:" + tdp.Left + " .listen_port " + tdp.Right,
}
args = withLogLevel(args, exporter.LogLevel, pmmAgentVersion)

return &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_AZURE_DATABASE_EXPORTER,
Expand Down
5 changes: 4 additions & 1 deletion services/agents/azure_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/version"
"github.com/stretchr/testify/require"

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

func TestAzureExporterConfig(t *testing.T) {
pmmAgentVersion := version.MustParse("2.28.0")

node1 := &models.Node{
NodeID: "/node_id/node1",
NodeType: models.RemoteAzureDatabaseNodeType,
Expand Down Expand Up @@ -66,7 +69,7 @@ func TestAzureExporterConfig(t *testing.T) {
},
}

actual, err := azureDatabaseExporterConfig(agent, service1, redactSecrets)
actual, err := azureDatabaseExporterConfig(agent, service1, redactSecrets, pmmAgentVersion)
require.NoError(t, err)
expected := &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_AZURE_DATABASE_EXPORTER,
Expand Down
32 changes: 31 additions & 1 deletion services/agents/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/version"
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -66,7 +67,9 @@ func mergeLabels(node *models.Node, agent *models.Agent) (model.LabelSet, error)
}

// rdsExporterConfig returns desired configuration of rds_exporter process.
func rdsExporterConfig(pairs map[*models.Node]*models.Agent, redactMode redactMode) (*agentpb.SetStateRequest_AgentProcess, error) {
func rdsExporterConfig(pairs map[*models.Node]*models.Agent, redactMode redactMode,
pmmAgentVersion *version.Parsed,
) (*agentpb.SetStateRequest_AgentProcess, error) {
config := rdsExporterConfigFile{
Instances: make([]rdsInstance, 0, len(pairs)),
}
Expand Down Expand Up @@ -114,6 +117,9 @@ func rdsExporterConfig(pairs map[*models.Node]*models.Agent, redactMode redactMo
"--web.listen-address=:" + tdp.Left + " .listen_port " + tdp.Right,
"--config.file=" + tdp.Left + " .TextFiles.config " + tdp.Right,
}

args = withLogLevel(args, toOneLogLevel(pairs), pmmAgentVersion)

sort.Strings(args)

b, err := yaml.Marshal(config)
Expand All @@ -132,3 +138,27 @@ func rdsExporterConfig(pairs map[*models.Node]*models.Agent, redactMode redactMo
RedactWords: words,
}, nil
}

// toOneLogLevel returns first if all equals.
func toOneLogLevel(pairs map[*models.Node]*models.Agent) *string {
var (
logLevel *string
logLevelFirst bool
)

for _, exporter := range pairs {
if !logLevelFirst {
logLevel = exporter.LogLevel

logLevelFirst = true

continue
}

if pointer.GetString(logLevel) != pointer.GetString(exporter.LogLevel) {
return nil
}
}

return logLevel
}
5 changes: 4 additions & 1 deletion services/agents/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import (
"github.com/AlekSi/pointer"
"github.com/percona/pmm/api/agentpb"
"github.com/percona/pmm/api/inventorypb"
"github.com/percona/pmm/version"
"github.com/stretchr/testify/require"

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

func TestRDSExporterConfig(t *testing.T) {
pmmAgentVersion := version.MustParse("2.28.0")

node1 := &models.Node{
NodeID: "/node_id/node1",
NodeType: models.RemoteRDSNodeType,
Expand Down Expand Up @@ -76,7 +79,7 @@ func TestRDSExporterConfig(t *testing.T) {
node2: agent2,
node1: agent1,
}
actual, err := rdsExporterConfig(pairs, redactSecrets)
actual, err := rdsExporterConfig(pairs, redactSecrets, pmmAgentVersion)
require.NoError(t, err)
expected := &agentpb.SetStateRequest_AgentProcess{
Type: inventorypb.AgentType_RDS_EXPORTER,
Expand Down
4 changes: 2 additions & 2 deletions services/agents/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (u *StateUpdater) sendSetStateRequest(ctx context.Context, agent *pmmAgentI
if err != nil {
return err
}
config, err := azureDatabaseExporterConfig(row, service, redactMode)
config, err := azureDatabaseExporterConfig(row, service, redactMode, pmmAgentVersion)
if err != nil {
return err
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func (u *StateUpdater) sendSetStateRequest(ctx context.Context, agent *pmmAgentI
sort.Strings(rdsExporterIDs)

groupID := u.r.roster.add(agent.id, rdsGroup, rdsExporterIDs)
c, err := rdsExporterConfig(rdsExporters, redactMode)
c, err := rdsExporterConfig(rdsExporters, redactMode, pmmAgentVersion)
if err != nil {
return err
}
Expand Down
11 changes: 11 additions & 0 deletions services/inventory/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (as *AgentsService) AddMySQLdExporter(ctx context.Context, req *inventorypb
TableCountTablestatsGroupLimit: req.TablestatsGroupTableLimit,
PushMetrics: req.PushMetrics,
DisableCollectors: req.DisableCollectors,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
var err error
row, err = models.CreateAgent(tx.Querier, models.MySQLdExporterType, params)
Expand Down Expand Up @@ -293,6 +294,7 @@ func (as *AgentsService) AddMongoDBExporter(ctx context.Context, req *inventoryp
MongoDBOptions: models.MongoDBOptionsFromRequest(req),
PushMetrics: req.PushMetrics,
DisableCollectors: req.DisableCollectors,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.MongoDBExporterType, params)
if err != nil {
Expand Down Expand Up @@ -351,6 +353,7 @@ func (as *AgentsService) AddQANMySQLPerfSchemaAgent(ctx context.Context, req *in
TLSSkipVerify: req.TlsSkipVerify,
MySQLOptions: models.MySQLOptionsFromRequest(req),
QueryExamplesDisabled: req.DisableQueryExamples,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.QANMySQLPerfSchemaAgentType, params)
if err != nil {
Expand Down Expand Up @@ -416,6 +419,7 @@ func (as *AgentsService) AddQANMySQLSlowlogAgent(ctx context.Context, req *inven
MySQLOptions: models.MySQLOptionsFromRequest(req),
QueryExamplesDisabled: req.DisableQueryExamples,
MaxQueryLogSize: maxSlowlogFileSize,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.QANMySQLSlowlogAgentType, params)
if err != nil {
Expand Down Expand Up @@ -475,6 +479,7 @@ func (as *AgentsService) AddPostgresExporter(ctx context.Context, req *inventory
PushMetrics: req.PushMetrics,
DisableCollectors: req.DisableCollectors,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.PostgresExporterType, params)
if err != nil {
Expand Down Expand Up @@ -533,6 +538,7 @@ func (as *AgentsService) AddQANMongoDBProfilerAgent(ctx context.Context, req *in
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
MongoDBOptions: models.MongoDBOptionsFromRequest(req),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
// TODO QueryExamplesDisabled https://jira.percona.com/browse/PMM-4650
}
row, err := models.CreateAgent(tx.Querier, models.QANMongoDBProfilerAgentType, params)
Expand Down Expand Up @@ -593,6 +599,7 @@ func (as *AgentsService) AddProxySQLExporter(ctx context.Context, req *inventory
TLSSkipVerify: req.TlsSkipVerify,
PushMetrics: req.PushMetrics,
DisableCollectors: req.DisableCollectors,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.ProxySQLExporterType, params)
if err != nil {
Expand Down Expand Up @@ -650,6 +657,7 @@ func (as *AgentsService) AddQANPostgreSQLPgStatementsAgent(ctx context.Context,
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.QANPostgreSQLPgStatementsAgentType, params)
if err != nil {
Expand Down Expand Up @@ -708,6 +716,7 @@ func (as *AgentsService) AddQANPostgreSQLPgStatMonitorAgent(ctx context.Context,
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.QANPostgreSQLPgStatMonitorAgentType, params)
if err != nil {
Expand Down Expand Up @@ -764,6 +773,7 @@ func (as *AgentsService) AddRDSExporter(ctx context.Context, req *inventorypb.Ad
RDSBasicMetricsDisabled: req.DisableBasicMetrics,
RDSEnhancedMetricsDisabled: req.DisableEnhancedMetrics,
PushMetrics: req.PushMetrics,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.RDSExporterType, params)
if err != nil {
Expand Down Expand Up @@ -872,6 +882,7 @@ func (as *AgentsService) AddAzureDatabaseExporter(ctx context.Context, req *inve
AzureOptions: models.AzureOptionsFromRequest(req),
CustomLabels: req.CustomLabels,
PushMetrics: req.PushMetrics,
LogLevel: models.SpecifyLogLevel(req.LogLevel),
}
row, err := models.CreateAgent(tx.Querier, models.AzureDatabaseExporterType, params)
if err != nil {
Expand Down
8 changes: 0 additions & 8 deletions services/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ func isPushMode(variant managementpb.MetricsMode) bool {
return variant == managementpb.MetricsMode_PUSH || variant == managementpb.MetricsMode_AUTO
}

func specifyLogLevel(variant inventorypb.LogLevel) string {
if variant == inventorypb.LogLevel_auto {
return ""
}

return variant.String()
}

// Automatically pick metrics mode.
func supportedMetricsMode(q *reform.Querier, metricsMode managementpb.MetricsMode, pmmAgentID string) (managementpb.MetricsMode, error) {
if pmmAgentID == models.PMMServerAgentID && metricsMode == managementpb.MetricsMode_PUSH {
Expand Down
4 changes: 2 additions & 2 deletions services/management/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *MongoDBService) Add(ctx context.Context, req *managementpb.AddMongoDBRe
MongoDBOptions: mongoDBOptions,
PushMetrics: isPushMode(req.MetricsMode),
DisableCollectors: req.DisableCollectors,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand All @@ -120,7 +120,7 @@ func (s *MongoDBService) Add(ctx context.Context, req *managementpb.AddMongoDBRe
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
MongoDBOptions: mongoDBOptions,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
// TODO QueryExamplesDisabled https://jira.percona.com/browse/PMM-4650
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions services/management/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
TableCountTablestatsGroupLimit: tablestatsGroupTableLimit,
PushMetrics: isPushMode(req.MetricsMode),
DisableCollectors: req.DisableCollectors,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand Down Expand Up @@ -145,7 +145,7 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
TLSSkipVerify: req.TlsSkipVerify,
MySQLOptions: models.MySQLOptionsFromRequest(req),
QueryExamplesDisabled: req.DisableQueryExamples,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand All @@ -169,7 +169,7 @@ func (s *MySQLService) Add(ctx context.Context, req *managementpb.AddMySQLReques
MySQLOptions: models.MySQLOptionsFromRequest(req),
QueryExamplesDisabled: req.DisableQueryExamples,
MaxQueryLogSize: maxSlowlogFileSize,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions services/management/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (s *PostgreSQLService) Add(ctx context.Context, req *managementpb.AddPostgr
PushMetrics: isPushMode(req.MetricsMode),
DisableCollectors: req.DisableCollectors,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand All @@ -119,7 +119,7 @@ func (s *PostgreSQLService) Add(ctx context.Context, req *managementpb.AddPostgr
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand All @@ -142,7 +142,7 @@ func (s *PostgreSQLService) Add(ctx context.Context, req *managementpb.AddPostgr
TLS: req.Tls,
TLSSkipVerify: req.TlsSkipVerify,
PostgreSQLOptions: models.PostgreSQLOptionsFromRequest(req),
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion services/management/proxysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *ProxySQLService) Add(ctx context.Context, req *managementpb.AddProxySQL
TLSSkipVerify: req.TlsSkipVerify,
PushMetrics: isPushMode(req.MetricsMode),
DisableCollectors: req.DisableCollectors,
LogLevel: specifyLogLevel(req.LogLevel),
LogLevel: models.SpecifyLogLevel(req.LogLevel),
})
if err != nil {
return err
Expand Down