diff --git a/managed/services/agents/mongodb.go b/managed/services/agents/mongodb.go index 971593fb5f..37cac807af 100644 --- a/managed/services/agents/mongodb.go +++ b/managed/services/agents/mongodb.go @@ -40,6 +40,7 @@ var ( newMongoExporterPMMVersion = version.MustParse("2.9.99") v2_24_99 = version.MustParse("2.24.99") v2_25_99 = version.MustParse("2.25.99") + v2_41_1 = version.MustParse("2.41.1-0") ) // mongodbExporterConfig returns desired configuration of mongodb_exporter process. @@ -54,7 +55,14 @@ func mongodbExporterConfig(node *models.Node, service *models.Service, exporter // Starting with PMM 2.25.0, we change the discovering-mode making it to discover all databases. // Until now, discovering mode was not working properly and was enabled only if mongodb.collstats-colls= // was specified in the command line. + // Starting with PMM 2.41.1 we added shards collector. switch { + case !pmmAgentVersion.Less(v2_41_1): // >= 2.41.1 + args = v226Args(exporter, tdp, listenAddress) + + if exporter.MongoDBOptions != nil && exporter.MongoDBOptions.EnableAllCollectors { + args = append(args, "--collector.shards") + } case !pmmAgentVersion.Less(v2_25_99): // >= 2.26 args = v226Args(exporter, tdp, listenAddress) case !pmmAgentVersion.Less(v2_24_99): // >= 2.25 @@ -232,22 +240,18 @@ func defaultCollectors(collectAll bool) map[string]collectorArgs { enabled: true, enableParam: "--collector.replicasetstatus", }, - // disabled until we have better information on the resources usage impact "collstats": { enabled: collectAll, enableParam: "--collector.collstats", }, - // disabled until we have better information on the resources usage impact "dbstats": { enabled: collectAll, enableParam: "--collector.dbstats", }, - // disabled until we have better information on the resources usage impact "indexstats": { enabled: collectAll, enableParam: "--collector.indexstats", }, - // disabled until we have better information on the resources usage impact "topmetrics": { enabled: collectAll, enableParam: "--collector.topmetrics", diff --git a/managed/services/agents/mongodb_test.go b/managed/services/agents/mongodb_test.go index 2f11b0940f..8accc04e9e 100644 --- a/managed/services/agents/mongodb_test.go +++ b/managed/services/agents/mongodb_test.go @@ -231,6 +231,161 @@ func TestMongodbExporterConfig226(t *testing.T) { }) } +func TestMongodbExporterConfig2411(t *testing.T) { + pmmAgentVersion := version.MustParse("2.41.1") + node := &models.Node{ + Address: "1.2.3.4", + } + mongodb := &models.Service{ + Address: pointer.ToString("1.2.3.4"), + Port: pointer.ToUint16(27017), + } + exporter := &models.Agent{ + AgentID: "agent-id", + AgentType: models.MongoDBExporterType, + Username: pointer.ToString("username"), + Password: pointer.ToString("s3cur3 p@$$w0r4."), + AgentPassword: pointer.ToString("agent-password"), + } + actual, err := mongodbExporterConfig(node, mongodb, exporter, redactSecrets, pmmAgentVersion) + expected := &agentpb.SetStateRequest_AgentProcess{ + Type: inventorypb.AgentType_MONGODB_EXPORTER, + TemplateLeftDelim: "{{", + TemplateRightDelim: "}}", + Args: []string{ + "--collector.diagnosticdata", + "--collector.replicasetstatus", + "--compatible-mode", + "--discovering-mode", + "--mongodb.global-conn-pool", + "--web.listen-address=0.0.0.0:{{ .listen_port }}", + "--web.config={{ .TextFiles.webConfigPlaceholder }}", + }, + Env: []string{ + "MONGODB_URI=mongodb://username:s3cur3%20p%40$$w0r4.@1.2.3.4:27017/?connectTimeoutMS=1000&directConnection=true&serverSelectionTimeoutMS=1000", + }, + RedactWords: []string{"s3cur3 p@$$w0r4.", "agent-password"}, + TextFiles: map[string]string{ + "webConfigPlaceholder": "basic_auth_users:\n pmm: agent-password\n", + }, + } + require.NoError(t, err) + requireNoDuplicateFlags(t, actual.Args) + require.Equal(t, expected.Args, actual.Args) + require.Equal(t, expected.Env, actual.Env) + require.Equal(t, expected, actual) + + t.Run("Having collstats limit", func(t *testing.T) { + exporter.MongoDBOptions = &models.MongoDBOptions{ + StatsCollections: []string{"col1", "col2", "col3"}, + CollectionsLimit: 79014, + } + expected.Args = []string{ + "--collector.collstats-limit=79014", + "--collector.diagnosticdata", + "--collector.replicasetstatus", + "--compatible-mode", + "--discovering-mode", + "--mongodb.collstats-colls=col1,col2,col3", + "--mongodb.global-conn-pool", + "--mongodb.indexstats-colls=col1,col2,col3", + "--web.listen-address=0.0.0.0:{{ .listen_port }}", + "--web.config={{ .TextFiles.webConfigPlaceholder }}", + } + actual, err := mongodbExporterConfig(node, mongodb, exporter, exposeSecrets, pmmAgentVersion) + require.NoError(t, err) + require.Equal(t, expected.Args, actual.Args) + }) + + t.Run("Enabling all collectors with non zero limit", func(t *testing.T) { + exporter.MongoDBOptions = &models.MongoDBOptions{ + StatsCollections: []string{"col1", "col2", "col3"}, + CollectionsLimit: 79014, + EnableAllCollectors: true, + } + + expected.Args = []string{ + "--collector.collstats", + "--collector.collstats-limit=79014", + "--collector.dbstats", + "--collector.diagnosticdata", + "--collector.indexstats", + "--collector.replicasetstatus", + "--collector.shards", + "--collector.topmetrics", + "--compatible-mode", + "--discovering-mode", + "--mongodb.collstats-colls=col1,col2,col3", + "--mongodb.global-conn-pool", + "--mongodb.indexstats-colls=col1,col2,col3", + "--web.listen-address=0.0.0.0:{{ .listen_port }}", + "--web.config={{ .TextFiles.webConfigPlaceholder }}", + } + actual, err := mongodbExporterConfig(node, mongodb, exporter, exposeSecrets, pmmAgentVersion) + require.NoError(t, err) + require.Equal(t, expected.Args, actual.Args) + }) + + t.Run("Enabling all collectors", func(t *testing.T) { + exporter.MongoDBOptions = &models.MongoDBOptions{ + EnableAllCollectors: true, + StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, + } + + expected.Args = []string{ + "--collector.collstats", + "--collector.collstats-limit=0", + "--collector.dbstats", + "--collector.diagnosticdata", + "--collector.indexstats", + "--collector.replicasetstatus", + "--collector.shards", + "--collector.topmetrics", + "--compatible-mode", + "--discovering-mode", + // this should be here even if limit=0 because it could be used to filter dbstats + // since dbstats is not depending the number of collections present in the db. + "--mongodb.collstats-colls=db1.col1.one,db2.col2,db3", + "--mongodb.global-conn-pool", + "--mongodb.indexstats-colls=db1.col1.one,db2.col2,db3", + "--web.listen-address=0.0.0.0:{{ .listen_port }}", + "--web.config={{ .TextFiles.webConfigPlaceholder }}", + } + actual, err := mongodbExporterConfig(node, mongodb, exporter, exposeSecrets, pmmAgentVersion) + require.NoError(t, err) + require.Equal(t, expected.Args, actual.Args) + }) + + t.Run("collstats-limit=-1 -> automatically set the limit", func(t *testing.T) { + exporter.MongoDBOptions = &models.MongoDBOptions{ + EnableAllCollectors: true, + StatsCollections: []string{"db1.col1.one", "db2.col2", "db3"}, + CollectionsLimit: -1, + } + + expected.Args = []string{ + "--collector.collstats", + "--collector.collstats-limit=200", // 200 is the default for auto-set + "--collector.dbstats", + "--collector.diagnosticdata", + "--collector.indexstats", + "--collector.replicasetstatus", + "--collector.shards", + "--collector.topmetrics", + "--compatible-mode", + "--discovering-mode", + "--mongodb.collstats-colls=db1.col1.one,db2.col2,db3", + "--mongodb.global-conn-pool", + "--mongodb.indexstats-colls=db1.col1.one,db2.col2,db3", + "--web.listen-address=0.0.0.0:{{ .listen_port }}", + "--web.config={{ .TextFiles.webConfigPlaceholder }}", + } + actual, err := mongodbExporterConfig(node, mongodb, exporter, exposeSecrets, pmmAgentVersion) + require.NoError(t, err) + require.Equal(t, expected.Args, actual.Args) + }) +} + func TestMongodbExporterConfig(t *testing.T) { pmmAgentVersion := version.MustParse("2.0.0") node := &models.Node{ diff --git a/managed/services/victoriametrics/scrape_configs.go b/managed/services/victoriametrics/scrape_configs.go index e47df63673..6c05e6c716 100644 --- a/managed/services/victoriametrics/scrape_configs.go +++ b/managed/services/victoriametrics/scrape_configs.go @@ -398,11 +398,16 @@ func scrapeConfigsForMongoDBExporter(s *models.MetricsResolutions, params *scrap r = append(r, hr) } if params.agent.MongoDBOptions != nil && params.agent.MongoDBOptions.EnableAllCollectors { - lr, err := scrapeConfigForStandardExporter("lr", s.LR, params, []string{ + defaultCollectors := []string{ "dbstats", "indexstats", "collstats", - }) + } + if params.pmmAgentVersion != nil && !params.pmmAgentVersion.Less(version.MustParse("2.41.1-0")) { + defaultCollectors = append(defaultCollectors, "shards") + } + + lr, err := scrapeConfigForStandardExporter("lr", s.LR, params, defaultCollectors) if err != nil { return nil, err } diff --git a/managed/services/victoriametrics/scrape_configs_test.go b/managed/services/victoriametrics/scrape_configs_test.go index 29d08272dc..c8ac503da9 100644 --- a/managed/services/victoriametrics/scrape_configs_test.go +++ b/managed/services/victoriametrics/scrape_configs_test.go @@ -752,7 +752,7 @@ func TestScrapeConfig(t *testing.T) { ScrapeTimeout: scrapeTimeout(s.LR), MetricsPath: "/metrics", Params: map[string][]string{ - "collect[]": {"collstats", "dbstats", "indexstats"}, + "collect[]": {"collstats", "dbstats", "indexstats", "shards"}, }, HTTPClientConfig: config.HTTPClientConfig{ BasicAuth: &config.BasicAuth{ @@ -784,7 +784,7 @@ func TestScrapeConfig(t *testing.T) { node: node, service: service, agent: agent, - pmmAgentVersion: version.MustParse("2.26.0"), + pmmAgentVersion: version.MustParse("2.41.1"), }) require.NoError(t, err) require.Len(t, actual, len(expected))