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 4 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
6 changes: 3 additions & 3 deletions 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.27
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-20220601235657-42d659733aa3
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 Expand Up @@ -128,8 +128,8 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
github.com/stretchr/objx v0.3.0 // indirect
go.mongodb.org/mongo-driver v1.9.0 // indirect
github.com/stretchr/objx v0.4.0 // indirect
go.mongodb.org/mongo-driver v1.9.1 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/mod v0.5.1 // indirect
Expand Down
12 changes: 6 additions & 6 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-20220601235657-42d659733aa3 h1:UYp4XhqiDl89a6qKNBoblzGZy/1MAo7c0rFnxJsQ12w=
github.com/percona/pmm v0.0.0-20220601235657-42d659733aa3/go.mod h1:xgPCsAjF+4K3llSsv5kwqFw3ig/1zPt9kEq9d4WMHMA=
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 Expand Up @@ -551,8 +551,8 @@ github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.3.0 h1:NGXK3lHquSN08v5vWalVI/L8XU9hdzE/G6xsrze47As=
github.com/stretchr/objx v0.3.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand Down Expand Up @@ -580,8 +580,8 @@ github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg=
go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng=
go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
go.mongodb.org/mongo-driver v1.9.0 h1:f3aLGJvQmBl8d9S40IL+jEyBC6hfLPbJjv9t5hEM9ck=
go.mongodb.org/mongo-driver v1.9.0/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
go.mongodb.org/mongo-driver v1.9.1 h1:m078y9v7sBItkt1aaoe2YlvWEXcD263e1a4E1fBrJ1c=
go.mongodb.org/mongo-driver v1.9.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
2 changes: 2 additions & 0 deletions models/agent_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ func CreateNodeExporter(q *reform.Querier,
pushMetrics bool,
disableCollectors []string,
agentPassword *string,
logLevel string,
) (*Agent, error) {
// TODO merge into CreateAgent

Expand All @@ -569,6 +570,7 @@ func CreateNodeExporter(q *reform.Querier,
PushMetrics: pushMetrics,
DisabledCollectors: disableCollectors,
AgentPassword: agentPassword,
LogLevel: pointer.ToStringOrNil(logLevel),
}
if err := row.SetCustomLabels(customLabels); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ func setupFixture1(q *reform.Querier, username, password string) error {
if _, err = createPMMAgentWithID(q, PMMServerAgentID, node.NodeID, nil); err != nil {
return err
}
if _, err = CreateNodeExporter(q, PMMServerAgentID, nil, false, []string{}, nil); err != nil {
if _, err = CreateNodeExporter(q, PMMServerAgentID, nil, false, []string{}, nil, ""); err != nil {
return err
}

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
2 changes: 2 additions & 0 deletions services/agents/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ func nodeExporterConfig(node *models.Node, exporter *models.Agent, agentVersion
args = append(args, "--web.telemetry-path="+*exporter.MetricsPath)
}

args = withLogLevel(args, exporter.LogLevel, agentVersion)

sort.Strings(args)

params := &agentpb.SetStateRequest_AgentProcess{
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
16 changes: 16 additions & 0 deletions services/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
PushMetricsEnabled: agent.PushMetrics,
DisabledCollectors: agent.DisabledCollectors,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.MySQLdExporterType:
Expand Down Expand Up @@ -314,6 +315,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
TlsSkipVerify: agent.TLSSkipVerify,
QueryExamplesDisabled: agent.QueryExamplesDisabled,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.QANMySQLSlowlogAgentType:
Expand All @@ -330,6 +332,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
QueryExamplesDisabled: agent.QueryExamplesDisabled,
MaxSlowlogFileSize: agent.MaxQueryLogSize,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.QANMongoDBProfilerAgentType:
Expand All @@ -344,6 +347,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
Tls: agent.TLS,
TlsSkipVerify: agent.TLSSkipVerify,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
// TODO QueryExamplesDisabled https://jira.percona.com/browse/PMM-4650
}, nil

Expand Down Expand Up @@ -377,6 +381,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
Tls: agent.TLS,
TlsSkipVerify: agent.TLSSkipVerify,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.QANPostgreSQLPgStatMonitorAgentType:
Expand All @@ -392,6 +397,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
TlsSkipVerify: agent.TLSSkipVerify,
QueryExamplesDisabled: agent.QueryExamplesDisabled,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.RDSExporterType:
Expand All @@ -408,6 +414,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
EnhancedMetricsDisabled: agent.RDSEnhancedMetricsDisabled,
PushMetricsEnabled: agent.PushMetrics,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.ExternalExporterType:
Expand Down Expand Up @@ -443,6 +450,7 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
ListenPort: uint32(pointer.GetUint16(agent.ListenPort)),
CustomLabels: labels,
ProcessExecPath: processExecPath,
LogLevel: inventorypb.LogLevel(inventorypb.LogLevel_value[pointer.GetString(agent.LogLevel)]),
}, nil

case models.VMAgentType:
Expand All @@ -457,3 +465,11 @@ func ToAPIAgent(q *reform.Querier, agent *models.Agent) (inventorypb.Agent, erro
panic(fmt.Errorf("unhandled Agent type %s", agent.AgentType))
}
}

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

return variant.String()
}
Loading