Skip to content
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

PMM-7 Add flag to enable collstats details and disable them by default. #997

Open
wants to merge 1 commit 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
18 changes: 16 additions & 2 deletions exporter/collstats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ type collstatsCollector struct {

compatibleMode bool
discoveringMode bool
enableDetails bool
topologyInfo labelsGetter

collections []string
}

// newCollectionStatsCollector creates a collector for statistics about collections.
func newCollectionStatsCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, discovery bool, topology labelsGetter, collections []string) *collstatsCollector {
func newCollectionStatsCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, discovery bool, topology labelsGetter, collections []string, enableDetails bool) *collstatsCollector {
return &collstatsCollector{
ctx: ctx,
base: newBaseCollector(client, logger.WithFields(logrus.Fields{"collector": "collstats"})),
Expand All @@ -46,7 +47,8 @@ func newCollectionStatsCollector(ctx context.Context, client *mongo.Client, logg
discoveringMode: discovery,
topologyInfo: topology,

collections: collections,
collections: collections,
enableDetails: enableDetails,
}
}

Expand Down Expand Up @@ -110,6 +112,18 @@ func (d *collstatsCollector) collect(ch chan<- prometheus.Metric) {

pipeline := mongo.Pipeline{aggregation}

if !d.enableDetails {
project := bson.D{
{
Key: "$project", Value: bson.M{
"storageStats.wiredTiger": 0,
"storageStats.indexDetails": 0,
},
},
}
pipeline = append(pipeline, project)
}

cursor, err := client.Database(database).Collection(collection).Aggregate(d.ctx, pipeline)
if err != nil {
logger.Errorf("cannot get $collstats cursor for collection %s.%s: %s", database, collection, err)
Expand Down
2 changes: 1 addition & 1 deletion exporter/collstats_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestCollStatsCollector(t *testing.T) {

collection := []string{"testdb.testcol_00", "testdb.testcol_01", "testdb.testcol_02"}
logger := logrus.New()
c := newCollectionStatsCollector(ctx, client, logger, false, ti, collection)
c := newCollectionStatsCollector(ctx, client, logger, false, ti, collection, false)

// The last \n at the end of this string is important
expected := strings.NewReader(`
Expand Down
22 changes: 11 additions & 11 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,13 @@ type Exporter struct {

// Opts holds new exporter options.
type Opts struct {
// Only get stats for the collections matching this list of namespaces.
// Example: db1.col1,db.col1
CollStatsNamespaces []string
CollStatsLimit int
CompatibleMode bool
DirectConnect bool
ConnectTimeoutMS int
DisableDefaultRegistry bool
DiscoveringMode bool
GlobalConnPool bool
ProfileTimeTS int
TimeoutOffset int
CurrentOpSlowTime string

CollectAll bool
EnableDBStats bool
Expand All @@ -72,14 +66,20 @@ type Opts struct {
EnableProfile bool
EnableShards bool
EnableFCV bool // Feature Compatibility Version.
EnablePBMMetrics bool

EnableOverrideDescendingIndex bool

// Enable metrics for Percona Backup for MongoDB (PBM).
EnablePBMMetrics bool
// Only get stats for the collections matching this list of namespaces.
// Example: db1.col1,db.col1
CollStatsNamespaces []string
CollStatsLimit int
CollStatsEnableDetails bool
IndexStatsCollections []string
CurrentOpSlowTime string
ProfileTimeTS int

IndexStatsCollections []string
Logger *logrus.Logger
Logger *logrus.Logger

URI string
NodeName string
Expand Down Expand Up @@ -192,7 +192,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
if (len(e.opts.CollStatsNamespaces) > 0 || e.opts.DiscoveringMode) && e.opts.EnableCollStats && limitsOk && requestOpts.EnableCollStats {
cc := newCollectionStatsCollector(ctx, client, e.opts.Logger,
e.opts.DiscoveringMode,
topologyInfo, e.opts.CollStatsNamespaces)
topologyInfo, e.opts.CollStatsNamespaces, e.opts.CollStatsEnableDetails)
registry.MustRegister(cc)
}

Expand Down
12 changes: 7 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@

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 and indexstats collector if there are more than <n> collections. 0=No limit" default:"0"`

Check failure on line 73 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 and indexstats collector if there are more than <n> collections. 0=No limit" name:"collector.collstats-limit" (tagalign)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
tag is not aligned, should be: default:"0" help:"Disable collstats, dbstats, topmetrics and indexstats collector if there are more than 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"`

Check failure on line 74 in main.go

View workflow job for this annotation

GitHub Actions / Lint Check

tag is not aligned, should be: default:"false" help:"Enable collecting index details and wired tiger metrics from $collStats" name:"collector.collstats-enable-details" (tagalign)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci-lint] reported by reviewdog 🐶
tag is not aligned, should be: default:"false" help:"Enable collecting index details and wired tiger metrics from $collStats" name:"collector.collstats-enable-details" (tagalign)


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

Expand Down Expand Up @@ -192,10 +193,11 @@

EnableOverrideDescendingIndex: opts.EnableOverrideDescendingIndex,

CollStatsLimit: opts.CollStatsLimit,
CollectAll: opts.CollectAll,
ProfileTimeTS: opts.ProfileTimeTS,
CurrentOpSlowTime: opts.CurrentOpSlowTime,
CollStatsLimit: opts.CollStatsLimit,
CollStatsEnableDetails: opts.CollStatsEnableDetails,
CollectAll: opts.CollectAll,
ProfileTimeTS: opts.ProfileTimeTS,
CurrentOpSlowTime: opts.CurrentOpSlowTime,
}

e := exporter.New(exporterOpts)
Expand Down
Loading