Skip to content

Commit

Permalink
PMM-12522 collect chunks metrics in low resolution (#2987)
Browse files Browse the repository at this point in the history
* PMM-12522 Collect chunks metrics in low resolution.

* PMM-12522 Collect chunks metrics in low resolution.

* PMM-12522 Remove unnecessary line.

* PMM-12522 Fix linter.

* PMM-12522 revert no used linter.
  • Loading branch information
BupycHuk authored May 29, 2024
1 parent 1ea2627 commit 6ca7cc2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 40 deletions.
68 changes: 39 additions & 29 deletions managed/services/agents/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
21 changes: 12 additions & 9 deletions managed/services/victoriametrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions managed/services/victoriametrics/scrape_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 6ca7cc2

Please sign in to comment.