Skip to content

Disable coll chunk info scrape when CollStatsLimit happens #1122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
registry.MustRegister(rsgsc)
}
if e.opts.EnableShards && nodeType == typeMongos && requestOpts.EnableShards {
sc := newShardsCollector(ctx, client, e.opts.Logger, e.opts.CompatibleMode)
sc := newShardsCollector(ctx, client, e.opts.Logger, e.opts.CompatibleMode, limitsOk)
registry.MustRegister(sc)
}

Expand Down
20 changes: 13 additions & 7 deletions exporter/shards_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ import (
)

type shardsCollector struct {
ctx context.Context
base *baseCollector
compatible bool
ctx context.Context
base *baseCollector
compatible bool
scanEachCollChunkOk bool
}

// newShardsCollector creates collector collecting metrics about chunks for shards Mongo.
func newShardsCollector(ctx context.Context, client *mongo.Client, logger *slog.Logger, compatibleMode bool) *shardsCollector {
func newShardsCollector(ctx context.Context, client *mongo.Client, logger *slog.Logger, compatibleMode bool, scanEachCollChunkOk bool) *shardsCollector {
return &shardsCollector{
ctx: ctx,
base: newBaseCollector(client, logger.With("collector", "shards")),
compatible: compatibleMode,
ctx: ctx,
base: newBaseCollector(client, logger.With("collector", "shards")),
compatible: compatibleMode,
scanEachCollChunkOk: scanEachCollChunkOk,
}
}

Expand Down Expand Up @@ -78,6 +80,10 @@ func (d *shardsCollector) collect(ch chan<- prometheus.Metric) {
ch <- metric
}

if !d.scanEachCollChunkOk {
return
}

databaseNames, err := client.ListDatabaseNames(d.ctx, bson.D{})
if err != nil {
logger.Error("cannot get database names", "error", err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/shards_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestShardsCollector(t *testing.T) {
defer cancel()

client := tu.DefaultTestClientMongoS(ctx, t)
c := newShardsCollector(ctx, client, promslog.New(&promslog.Config{}), false)
c := newShardsCollector(ctx, client, promslog.New(&promslog.Config{}), false, true)

reg := prometheus.NewPedanticRegistry()
if err := reg.Register(c); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

CollectAll bool `name:"collect-all" help:"Enable all collectors. Same as specifying all --collector.<name>"`

CollStatsLimit int `name:"collector.collstats-limit" help:"Disable collstats, dbstats, topmetrics and indexstats collector if there are more than <n> collections. 0=No limit" default:"0"`
CollStatsLimit int `name:"collector.collstats-limit" help:"Disable collstats, dbstats, topmetrics, indexstats collector and coll chunk info if there are more than <n> collections. 0=No limit" default:"0"`

Check failure on line 75 in main.go

View workflow job for this annotation

GitHub Actions / Lint Check

tag is not aligned, should be: default:"0" help:"Disable collstats, dbstats, topmetrics, indexstats collector and coll chunk info if there are more than <n> collections. 0=No limit" name:"collector.collstats-limit" (tagalign)
CollStatsEnableDetails bool `name:"collector.collstats-enable-details" help:"Enable collecting index details and wired tiger metrics from $collStats" default:"false"`

ProfileTimeTS int `name:"collector.profile-time-ts" help:"Set time for scrape slow queries." default:"30"`
Expand Down
Loading