Skip to content
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
76 changes: 39 additions & 37 deletions admin/commands/inventory/add_agent_mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,25 @@ func (res *addAgentMongodbExporterResult) String() string {
type AddAgentMongodbExporterCommand struct {
flags.LogLevelFatalFlags

PMMAgentID string `arg:"" help:"The pmm-agent identifier which runs this instance"`
ServiceID string `arg:"" help:"Service identifier"`
Username string `arg:"" optional:"" help:"MongoDB username for scraping metrics"`
Password string `help:"MongoDB password for scraping metrics"`
AgentPassword string `help:"Custom password for /metrics endpoint"`
CustomLabels map[string]string `mapsep:"," help:"Custom user-assigned labels"`
SkipConnectionCheck bool `help:"Skip connection check"`
TLS bool `help:"Use TLS to connect to the database"`
TLSSkipVerify bool `help:"Skip TLS certificate verification"`
TLSCertificateKeyFile string `help:"Path to TLS certificate PEM file"`
TLSCertificateKeyFilePassword string `help:"Password for certificate"`
TLSCaFile string `help:"Path to certificate authority file"`
AuthenticationMechanism string `help:"Authentication mechanism. Default is empty. Use MONGODB-X509 for ssl certificates"`
PushMetrics bool `help:"Enables push metrics model flow, it will be sent to the server by an agent"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
StatsCollections []string `help:"Collections for collstats & indexstats"`
CollectionsLimit int32 `name:"max-collections-limit" placeholder:"number" help:"Disable collstats & indexstats if there are more than <n> collections"`
ConnectionTimeout *time.Duration `placeholder:"DURATION" help:"Connection timeout to use for exporter (e.g. 1s, 1.5s)"`
PMMAgentID string `arg:"" help:"The pmm-agent identifier which runs this instance"`
ServiceID string `arg:"" help:"Service identifier"`
Username string `arg:"" optional:"" help:"MongoDB username for scraping metrics"`
Password string `help:"MongoDB password for scraping metrics"`
AgentPassword string `help:"Custom password for /metrics endpoint"`
CustomLabels map[string]string `mapsep:"," help:"Custom user-assigned labels"`
SkipConnectionCheck bool `help:"Skip connection check"`
TLS bool `help:"Use TLS to connect to the database"`
TLSSkipVerify bool `help:"Skip TLS certificate verification"`
TLSCertificateKeyFile string `help:"Path to TLS certificate PEM file"`
TLSCertificateKeyFilePassword string `help:"Password for certificate"`
TLSCaFile string `help:"Path to certificate authority file"`
AuthenticationMechanism string `help:"Authentication mechanism. Default is empty. Use MONGODB-X509 for ssl certificates"`
PushMetrics bool `help:"Enables push metrics model flow, it will be sent to the server by an agent"`
DisableCollectors []string `help:"Comma-separated list of collector names to exclude from exporter"`
StatsCollections []string `help:"Collections for collstats & indexstats"`
CollectionsLimit int32 `name:"max-collections-limit" placeholder:"number" help:"Disable collstats & indexstats if there are more than <n> collections"`
EnableDiagnosticDataHistograms bool `help:"Enable collecting histogram bucket metrics from getDiagnosticData"`
ConnectionTimeout *time.Duration `placeholder:"DURATION" help:"Connection timeout to use for exporter (e.g. 1s, 1.5s)"`
}

// RunCmd executes the AddAgentMongodbExporterCommand and returns the result.
Expand All @@ -92,25 +93,26 @@ func (cmd *AddAgentMongodbExporterCommand) RunCmd() (commands.Result, error) {
params := &agents.AddAgentParams{
Body: agents.AddAgentBody{
MongodbExporter: &agents.AddAgentParamsBodyMongodbExporter{
PMMAgentID: cmd.PMMAgentID,
ServiceID: cmd.ServiceID,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
CustomLabels: pointer.Get(customLabels),
SkipConnectionCheck: cmd.SkipConnectionCheck,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
CollectionsLimit: cmd.CollectionsLimit,
LogLevel: cmd.LogLevel.EnumValue(),
ConnectionTimeout: commands.DurationString(cmd.ConnectionTimeout),
PMMAgentID: cmd.PMMAgentID,
ServiceID: cmd.ServiceID,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
CustomLabels: pointer.Get(customLabels),
SkipConnectionCheck: cmd.SkipConnectionCheck,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
PushMetrics: cmd.PushMetrics,
DisableCollectors: commands.ParseDisableCollectors(cmd.DisableCollectors),
StatsCollections: commands.ParseDisableCollectors(cmd.StatsCollections),
CollectionsLimit: cmd.CollectionsLimit,
EnableDiagnosticDataHistograms: cmd.EnableDiagnosticDataHistograms,
LogLevel: cmd.LogLevel.EnumValue(),
ConnectionTimeout: commands.DurationString(cmd.ConnectionTimeout),
},
},
Context: commands.Ctx,
Expand Down
55 changes: 32 additions & 23 deletions admin/commands/inventory/change_agent_mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ type ChangeAgentMongodbExporterCommand struct {
TLSCaFile *string `help:"TLS CA certificate file"`

// MongoDB specific options
AuthenticationMechanism *string `help:"Authentication mechanism for MongoDB"`
AuthenticationDatabase *string `help:"Authentication database for MongoDB"`
StatsCollections *string `help:"List of comma-separated collection names to collect"`
CollectionsLimit *int32 `help:"Collections limit"`
AuthenticationMechanism *string `help:"Authentication mechanism for MongoDB"`
AuthenticationDatabase *string `help:"Authentication database for MongoDB"`
StatsCollections *string `help:"List of comma-separated collection names to collect"`
CollectionsLimit *int32 `help:"Collections limit"`
EnableDiagnosticDataHistograms *bool `help:"Enable collecting histogram bucket metrics from getDiagnosticData"`

// Exporter options
DisableCollectors []string `help:"List of collector names to disable"`
Expand Down Expand Up @@ -140,25 +141,26 @@ func (cmd *ChangeAgentMongodbExporterCommand) RunCmd() (commands.Result, error)
}

body := &agents.ChangeAgentParamsBodyMongodbExporter{
Enable: cmd.Enable,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
AuthenticationDatabase: cmd.AuthenticationDatabase,
StatsCollections: statsCollections,
CollectionsLimit: cmd.CollectionsLimit,
DisableCollectors: cmd.DisableCollectors,
ExposeExporter: cmd.ExposeExporter,
EnablePushMetrics: cmd.PushMetrics,
LogLevel: convertLogLevelPtr(cmd.LogLevel),
ConnectionTimeout: commands.DurationString(cmd.ConnectionTimeout),
SkipConnectionCheck: cmd.SkipConnectionCheck,
Enable: cmd.Enable,
Username: cmd.Username,
Password: cmd.Password,
AgentPassword: cmd.AgentPassword,
TLS: cmd.TLS,
TLSSkipVerify: cmd.TLSSkipVerify,
TLSCertificateKey: tlsCertificateKey,
TLSCertificateKeyFilePassword: cmd.TLSCertificateKeyFilePassword,
TLSCa: tlsCa,
AuthenticationMechanism: cmd.AuthenticationMechanism,
AuthenticationDatabase: cmd.AuthenticationDatabase,
StatsCollections: statsCollections,
CollectionsLimit: cmd.CollectionsLimit,
EnableDiagnosticDataHistograms: cmd.EnableDiagnosticDataHistograms,
DisableCollectors: cmd.DisableCollectors,
ExposeExporter: cmd.ExposeExporter,
EnablePushMetrics: cmd.PushMetrics,
LogLevel: convertLogLevelPtr(cmd.LogLevel),
ConnectionTimeout: commands.DurationString(cmd.ConnectionTimeout),
SkipConnectionCheck: cmd.SkipConnectionCheck,
}

if customLabels != nil {
Expand Down Expand Up @@ -232,6 +234,13 @@ func (cmd *ChangeAgentMongodbExporterCommand) RunCmd() (commands.Result, error)
if cmd.CollectionsLimit != nil {
changes = append(changes, fmt.Sprintf("changed collections limit to %d", *cmd.CollectionsLimit))
}
if cmd.EnableDiagnosticDataHistograms != nil {
if *cmd.EnableDiagnosticDataHistograms {
changes = append(changes, "enabled diagnostic data histograms")
} else {
changes = append(changes, "disabled diagnostic data histograms")
}
}
if cmd.DisableCollectors != nil {
changes = append(changes, fmt.Sprintf("updated disabled collectors: %v", cmd.DisableCollectors))
}
Expand Down
31 changes: 18 additions & 13 deletions admin/commands/inventory/change_agent_mongodb_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ func TestMongodbExporterChangeAgent(t *testing.T) {
defer cleanup()

cmd := &ChangeAgentMongodbExporterCommand{
AgentID: "test-agent-id",
Enable: new(true),
Username: new("newuser"),
Password: new("newpass"),
TLS: new(true),
TLSSkipVerify: new(false),
AuthenticationMechanism: new("SCRAM-SHA-256"),
AuthenticationDatabase: new("admin"),
StatsCollections: new("collection1,collection2"),
CollectionsLimit: new(int32(100)),
DisableCollectors: []string{"general_stats", "index_stats"},
ExposeExporter: new(true),
PushMetrics: new(false),
AgentID: "test-agent-id",
Enable: new(true),
Username: new("newuser"),
Password: new("newpass"),
TLS: new(true),
TLSSkipVerify: new(false),
AuthenticationMechanism: new("SCRAM-SHA-256"),
AuthenticationDatabase: new("admin"),
StatsCollections: new("collection1,collection2"),
CollectionsLimit: new(int32(100)),
EnableDiagnosticDataHistograms: new(true),
DisableCollectors: []string{"general_stats", "index_stats"},
ExposeExporter: new(true),
PushMetrics: new(false),
LogLevelFatalChangeFlags: flags.LogLevelFatalChangeFlags{
LogLevel: new(flags.LogLevel("debug")),
},
Expand All @@ -73,6 +74,7 @@ func TestMongodbExporterChangeAgent(t *testing.T) {
"authentication_database": "admin",
"stats_collections": ["collection1", "collection2"],
"collections_limit": 100,
"enable_diagnostic_data_histograms": true,
"disable_collectors": ["general_stats", "index_stats"],
"expose_exporter": true,
"enable_push_metrics": false,
Expand Down Expand Up @@ -157,6 +159,7 @@ func TestMongodbExporterChangeAgent(t *testing.T) {
"--authentication-database=testdb",
"--stats-collections=col1,col2",
"--collections-limit=50",
"--enable-diagnostic-data-histograms",
"--disable-collectors=general_stats,index_stats",
"--expose-exporter",
"--push-metrics",
Expand Down Expand Up @@ -188,6 +191,7 @@ func TestMongodbExporterChangeAgent(t *testing.T) {
"authentication_database": "testdb",
"stats_collections": ["col1", "col2"],
"collections_limit": 50,
"enable_diagnostic_data_histograms": true,
"disable_collectors": ["general_stats", "index_stats"],
"expose_exporter": true,
"enable_push_metrics": true,
Expand Down Expand Up @@ -232,6 +236,7 @@ Configuration changes applied:
- changed authentication database to testdb
- updated stats collections: col1,col2
- changed collections limit to 50
- enabled diagnostic data histograms
- updated disabled collectors: [general_stats index_stats]
- enabled expose exporter
- enabled push metrics
Expand Down
Loading
Loading