diff --git a/managed/services/agents/mongodb.go b/managed/services/agents/mongodb.go index 37cac807af..3ff1983593 100644 --- a/managed/services/agents/mongodb.go +++ b/managed/services/agents/mongodb.go @@ -38,8 +38,8 @@ type collectorArgs struct { var ( // New MongoDB Exporter will be released with PMM agent v2.10.0. newMongoExporterPMMVersion = version.MustParse("2.9.99") - v2_24_99 = version.MustParse("2.24.99") - v2_25_99 = version.MustParse("2.25.99") + v2_25_0 = version.MustParse("2.25.0-0") + v2_26_0 = version.MustParse("2.26.0-0") v2_41_1 = version.MustParse("2.41.1-0") ) @@ -55,33 +55,12 @@ 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.26.0, we disabled all collectors by default and added flags to enable them. // 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 - args = v225Args(exporter, tdp, listenAddress) - case !pmmAgentVersion.Less(newMongoExporterPMMVersion): // >= 2.10 - args = []string{ - "--mongodb.global-conn-pool", - "--compatible-mode", - "--web.listen-address=" + listenAddress + ":" + tdp.Left + " .listen_port " + tdp.Right, - } - default: - args = []string{ - "--collect.collection", - "--collect.database", - "--collect.topmetrics", - "--no-collect.connpoolstats", - "--no-collect.indexusage", - "--web.listen-address=" + listenAddress + ":" + tdp.Left + " .listen_port " + tdp.Right, - } + if pmmAgentVersion.Less(v2_26_0) { + args = oldPMMAgentArgs(exporter, tdp, listenAddress, pmmAgentVersion) + } else { + args = v226Args(exporter, tdp, listenAddress, pmmAgentVersion) } args = collectors.FilterOutCollectors("--collect.", args, exporter.DisabledCollectors) @@ -122,7 +101,31 @@ func mongodbExporterConfig(node *models.Node, service *models.Service, exporter return res, nil } -func v226Args(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress string) []string { +func oldPMMAgentArgs(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress string, pmmAgentVersion *version.Parsed) []string { + var args []string + switch { + case !pmmAgentVersion.Less(v2_25_0): // >= 2.25 + args = v225Args(exporter, tdp, listenAddress) + case !pmmAgentVersion.Less(newMongoExporterPMMVersion): // >= 2.10 + args = []string{ + "--mongodb.global-conn-pool", + "--compatible-mode", + "--web.listen-address=" + listenAddress + ":" + tdp.Left + " .listen_port " + tdp.Right, //nolint:goconst + } + default: + args = []string{ + "--collect.collection", + "--collect.database", + "--collect.topmetrics", + "--no-collect.connpoolstats", + "--no-collect.indexusage", + "--web.listen-address=" + listenAddress + ":" + tdp.Left + " .listen_port " + tdp.Right, + } + } + return args +} + +func v226Args(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress string, pmmAgentVersion *version.Parsed) []string { collectAll := false if exporter.MongoDBOptions != nil { collectAll = exporter.MongoDBOptions.EnableAllCollectors @@ -135,6 +138,13 @@ func v226Args(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress s collectors := defaultCollectors(collectAll) + if !pmmAgentVersion.Less(v2_41_1) { // >= 2.41.1 + collectors["shards"] = collectorArgs{ + enabled: collectAll, + enableParam: "--collector.shards", + } + } + for _, collector := range exporter.DisabledCollectors { col, ok := collectors[strings.ToLower(collector)] if !ok { diff --git a/managed/services/victoriametrics/prometheus.go b/managed/services/victoriametrics/prometheus.go index 242c54fa15..245a9c5014 100644 --- a/managed/services/victoriametrics/prometheus.go +++ b/managed/services/victoriametrics/prometheus.go @@ -72,26 +72,29 @@ func AddScrapeConfigs(l *logrus.Entry, cfg *config.Config, q *reform.Querier, // // find Node address where the agent runs var paramsHost string var paramPMMAgentVersion *version.Parsed + var pmmAgent *models.Agent + if agent.PMMAgentID != nil { + // extract node address through pmm-agent + pmmAgent, err = models.FindAgentByID(q, *agent.PMMAgentID) + if err != nil { + return errors.WithStack(err) + } + paramPMMAgentVersion, err = version.Parse(pointer.GetString(pmmAgent.Version)) + if err != nil { + l.Warnf("couldn't parse pmm-agent version for pmm-agent %s: %q", pmmAgent.AgentID, err) + } + } switch { // special case for push metrics mode, // vmagent scrapes it from localhost. case pushMetrics: paramsHost = "127.0.0.1" case agent.PMMAgentID != nil: - // extract node address through pmm-agent - pmmAgent, err := models.FindAgentByID(q, *agent.PMMAgentID) - if err != nil { - return errors.WithStack(err) - } pmmAgentNode := &models.Node{NodeID: pointer.GetString(pmmAgent.RunsOnNodeID)} if err = q.Reload(pmmAgentNode); err != nil { return errors.WithStack(err) } paramsHost = pmmAgentNode.Address - paramPMMAgentVersion, err = version.Parse(pointer.GetString(pmmAgent.Version)) - if err != nil { - l.Warnf("couldn't parse pmm-agent version for pmm-agent %s: %q", pmmAgent.AgentID, err) - } case agent.RunsOnNodeID != nil: externalExporterNode := &models.Node{NodeID: pointer.GetString(agent.RunsOnNodeID)} if err = q.Reload(externalExporterNode); err != nil { diff --git a/managed/services/victoriametrics/scrape_configs.go b/managed/services/victoriametrics/scrape_configs.go index e41968f116..9dc595a871 100644 --- a/managed/services/victoriametrics/scrape_configs.go +++ b/managed/services/victoriametrics/scrape_configs.go @@ -388,7 +388,7 @@ func scrapeConfigsForMySQLdExporter(params *scrapeConfigParams) ([]*config.Scrap func scrapeConfigsForMongoDBExporter(params *scrapeConfigParams) ([]*config.ScrapeConfig, error) { // Old pmm-agents doesn't have support of multiple resolution, // so requesting mongodb_exporter metrics in two resolutions increases CPU and Memory usage. - if params.pmmAgentVersion == nil || params.pmmAgentVersion.Less(version.MustParse("2.25.99")) { + if params.pmmAgentVersion == nil || params.pmmAgentVersion.Less(version.MustParse("2.26.0-0")) { hr, err := scrapeConfigForStandardExporter("hr", params.metricsResolution.HR, params, nil) if err != nil { return nil, err @@ -419,7 +419,7 @@ func scrapeConfigsForMongoDBExporter(params *scrapeConfigParams) ([]*config.Scra "indexstats", "collstats", } - if params.pmmAgentVersion != nil && !params.pmmAgentVersion.Less(version.MustParse("2.41.1-0")) { + if !params.pmmAgentVersion.Less(version.MustParse("2.41.1-0")) { defaultCollectors = append(defaultCollectors, "shards") }