Skip to content

Commit

Permalink
PMM-13571: Enable PBM and FCV Collector by default (#3369)
Browse files Browse the repository at this point in the history
* include fcv and pbm collectors in scrape config by default

* increase min version to enable pbm collector

* fix tests

* update scrape config tests

* update scrape config tests

* sync with main branch

* update tests

* update exporter tests
  • Loading branch information
idoqo authored Dec 18, 2024
1 parent 3a65027 commit 52d27b0
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 57 deletions.
3 changes: 2 additions & 1 deletion managed/services/agents/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ var (
v2_41_1 = version.MustParse("2.41.1-0")
v2_42_0 = version.MustParse("2.42.0-0")
v2_43_0 = version.MustParse("2.43.0-0")
v2_43_2 = version.MustParse("2.43.2-0")
)

// mongodbExporterConfig returns desired configuration of mongodb_exporter process.
Expand Down Expand Up @@ -108,7 +109,7 @@ func getArgs(exporter *models.Agent, tdp *models.DelimiterPair, listenAddress st
if !pmmAgentVersion.Less(v2_43_0) { // >= 2.43.0, enable by default
args = append(args, "--collector.fcv")
}
if !pmmAgentVersion.Less(v2_43_0) { // >= 2.43.0, enable pbm collector by default
if !pmmAgentVersion.Less(v2_43_2) { // >= 2.43.2, enable pbm collector by default
args = append(args, "--collector.pbm")
}

Expand Down
4 changes: 2 additions & 2 deletions managed/services/agents/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ func TestMongodbExporterConfig2411(t *testing.T) {
})
}

func TestMongodbExporterConfig2430(t *testing.T) {
pmmAgentVersion := version.MustParse("2.43.0")
func TestMongodbExporterConfig2432(t *testing.T) {
pmmAgentVersion := version.MustParse("2.43.2")
node := &models.Node{
Address: "1.2.3.4",
}
Expand Down
39 changes: 18 additions & 21 deletions managed/services/victoriametrics/scrape_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func jobNameMapping(r rune) rune {
}

func jobName(agent *models.Agent, intervalName string) string {
return fmt.Sprintf("%s%s_%s", agent.AgentType, strings.Map(jobNameMapping, agent.AgentID), intervalName)
return fmt.Sprintf("%s_%s_%s", agent.AgentType, strings.Map(jobNameMapping, agent.AgentID), intervalName)
}

func httpClientConfig(agent *models.Agent) config.HTTPClientConfig {
Expand Down Expand Up @@ -386,34 +386,31 @@ func scrapeConfigsForMongoDBExporter(params *scrapeConfigParams) ([]*config.Scra
if hr != nil {
r = append(r, hr)
}

var defaultCollectors []string
if !params.pmmAgentVersion.Less(version.MustParse("2.43.0-0")) {
defaultCollectors = append(defaultCollectors, "fcv")
}
if !params.pmmAgentVersion.Less(version.MustParse("2.43.2-0")) {
defaultCollectors = append(defaultCollectors, "pbm")
}
if params.agent.MongoDBOptions.EnableAllCollectors {
defaultCollectors := []string{
"dbstats",
"indexstats",
"collstats",
}
defaultCollectors = append(defaultCollectors, "dbstats", "indexstats", "collstats")
if !params.pmmAgentVersion.Less(version.MustParse("2.41.1-0")) {
defaultCollectors = append(defaultCollectors, "shards")
}
if !params.pmmAgentVersion.Less(version.MustParse("2.42.0-0")) {
defaultCollectors = append(defaultCollectors, "currentopmetrics")
}
if !params.pmmAgentVersion.Less(version.MustParse("2.43.0-0")) {
defaultCollectors = append(defaultCollectors, "fcv")
}
if !params.pmmAgentVersion.Less(version.MustParse("2.43.0-0")) {
defaultCollectors = append(defaultCollectors, "pbm")
}

defaultCollectors = collectors.FilterOutCollectors("", defaultCollectors, params.agent.ExporterOptions.DisabledCollectors)
lr, err := scrapeConfigForStandardExporter("lr", params.metricsResolution.LR, params, defaultCollectors)
if err != nil {
return nil, err
}
}
defaultCollectors = collectors.FilterOutCollectors("", defaultCollectors, params.agent.ExporterOptions.DisabledCollectors)
lr, err := scrapeConfigForStandardExporter("lr", params.metricsResolution.LR, params, defaultCollectors)
if err != nil {
return nil, err
}

if lr != nil {
r = append(r, lr)
}
if lr != nil {
r = append(r, lr)
}
return r, nil
}
Expand Down
143 changes: 122 additions & 21 deletions managed/services/victoriametrics/scrape_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "node_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "node_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestScrapeConfig(t *testing.T) {
"vmstat",
}},
}, {
JobName: "node_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "node_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.MR),
ScrapeTimeout: scrapeTimeout(s.MR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestScrapeConfig(t *testing.T) {
"textfile.mr",
}},
}, {
JobName: "node_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "node_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "node_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "node_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestScrapeConfig(t *testing.T) {
"standard.process",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.MR),
ScrapeTimeout: scrapeTimeout(s.MR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestScrapeConfig(t *testing.T) {
"slave_status",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -424,7 +424,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestScrapeConfig(t *testing.T) {
"standard.process",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.MR),
ScrapeTimeout: scrapeTimeout(s.MR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestScrapeConfig(t *testing.T) {
"slave_status",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -575,7 +575,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -606,7 +606,7 @@ func TestScrapeConfig(t *testing.T) {
"standard.process",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.MR),
ScrapeTimeout: scrapeTimeout(s.MR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -641,7 +641,7 @@ func TestScrapeConfig(t *testing.T) {
"slave_status",
}},
}, {
JobName: "mysqld_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "mysqld_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -737,7 +737,7 @@ func TestScrapeConfig(t *testing.T) {

expected := []*config.ScrapeConfig{
{
JobName: "mongodb_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "mongodb_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -767,7 +767,7 @@ func TestScrapeConfig(t *testing.T) {
}},
},
}, {
JobName: "mongodb_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "mongodb_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -813,6 +813,107 @@ func TestScrapeConfig(t *testing.T) {
assertScrapeConfigsEqual(t, expected[i], actual[i])
}
})
t.Run("Without enable-all option on v2.43+", func(t *testing.T) {
node := &models.Node{
NodeID: "cc663f36-18ca-40a1-aea9-c6310bb4738d",
NodeName: "node_name",
Address: "1.2.3.4",
CustomLabels: []byte(`{"_some_node_label": "foo"}`),
}
service := &models.Service{
ServiceID: "014647c3-b2f5-44eb-94f4-d943260a968c",
NodeID: "cc663f36-18ca-40a1-aea9-c6310bb4738d",
Address: pointer.ToString("5.6.7.8"),
CustomLabels: []byte(`{"_some_service_label": "bar"}`),
}
agent := &models.Agent{
AgentID: "75bb30d3-ef4a-4147-97a8-621a996611dd",
AgentType: models.MongoDBExporterType,
CustomLabels: []byte(`{"_some_agent_label": "baz"}`),
ListenPort: pointer.ToUint16(12345),
ExporterOptions: &models.ExporterOptions{},
MongoDBOptions: &models.MongoDBOptions{},
}

expected := []*config.ScrapeConfig{
{
JobName: "mongodb_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Params: map[string][]string{
"collect[]": {"diagnosticdata", "replicasetstatus", "topmetrics"},
},
HTTPClientConfig: config.HTTPClientConfig{
BasicAuth: &config.BasicAuth{
Username: "pmm",
Password: "75bb30d3-ef4a-4147-97a8-621a996611dd",
},
},
ServiceDiscoveryConfig: config.ServiceDiscoveryConfig{
StaticConfigs: []*config.Group{{
Targets: []string{"4.5.6.7:12345"},
Labels: map[string]string{
"_some_agent_label": "baz",
"_some_node_label": "foo",
"_some_service_label": "bar",
"agent_id": "75bb30d3-ef4a-4147-97a8-621a996611dd",
"agent_type": "mongodb_exporter",
"instance": "75bb30d3-ef4a-4147-97a8-621a996611dd",
"node_id": "cc663f36-18ca-40a1-aea9-c6310bb4738d",
"node_name": "node_name",
"service_id": "014647c3-b2f5-44eb-94f4-d943260a968c",
},
}},
},
},
{
JobName: "mongodb_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Params: map[string][]string{
"collect[]": {"fcv", "pbm"},
},
HTTPClientConfig: config.HTTPClientConfig{
BasicAuth: &config.BasicAuth{
Username: "pmm",
Password: "75bb30d3-ef4a-4147-97a8-621a996611dd",
},
},
ServiceDiscoveryConfig: config.ServiceDiscoveryConfig{
StaticConfigs: []*config.Group{{
Targets: []string{"4.5.6.7:12345"},
Labels: map[string]string{
"_some_agent_label": "baz",
"_some_node_label": "foo",
"_some_service_label": "bar",
"agent_id": "75bb30d3-ef4a-4147-97a8-621a996611dd",
"agent_type": "mongodb_exporter",
"instance": "75bb30d3-ef4a-4147-97a8-621a996611dd",
"node_id": "cc663f36-18ca-40a1-aea9-c6310bb4738d",
"node_name": "node_name",
"service_id": "014647c3-b2f5-44eb-94f4-d943260a968c",
},
}},
},
},
}

actual, err := scrapeConfigsForMongoDBExporter(&scrapeConfigParams{
host: "4.5.6.7",
node: node,
service: service,
agent: agent,
pmmAgentVersion: version.MustParse("2.43.2"),
metricsResolution: s,
})
require.NoError(t, err)
require.Len(t, actual, len(expected))
for i := 0; i < len(expected); i++ {
assertScrapeConfigsEqual(t, expected[i], actual[i])
}
})

t.Run("BadCustomLabels", func(t *testing.T) {
node := &models.Node{}
Expand Down Expand Up @@ -860,7 +961,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "postgres_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "postgres_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -893,7 +994,7 @@ func TestScrapeConfig(t *testing.T) {
"standard.go",
}},
}, {
JobName: "postgres_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "postgres_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.MR),
ScrapeTimeout: scrapeTimeout(s.MR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -923,7 +1024,7 @@ func TestScrapeConfig(t *testing.T) {
"custom_query.mr",
}},
}, {
JobName: "postgres_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
JobName: "postgres_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_lr",
ScrapeInterval: config.Duration(s.LR),
ScrapeTimeout: scrapeTimeout(s.LR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -1008,7 +1109,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "proxysql_exporter75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
JobName: "proxysql_exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_hr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/metrics",
Expand Down Expand Up @@ -1197,7 +1298,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "external-exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "external-exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
ServiceDiscoveryConfig: config.ServiceDiscoveryConfig{
Expand Down Expand Up @@ -1247,7 +1348,7 @@ func TestScrapeConfig(t *testing.T) {
}

expected := []*config.ScrapeConfig{{
JobName: "external-exporter75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
JobName: "external-exporter_75bb30d3-ef4a-4147-97a8-621a996611dd_mr",
ScrapeInterval: config.Duration(s.HR),
ScrapeTimeout: scrapeTimeout(s.HR),
MetricsPath: "/some-metric-path",
Expand Down
Loading

0 comments on commit 52d27b0

Please sign in to comment.