Skip to content

Commit f19a692

Browse files
authored
PMM-7 Add flag to enable collstats details and disable them by default. (#997)
1 parent a3b80e3 commit f19a692

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

exporter/collstats_collector.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ type collstatsCollector struct {
3131

3232
compatibleMode bool
3333
discoveringMode bool
34+
enableDetails bool
3435
topologyInfo labelsGetter
3536

3637
collections []string
3738
}
3839

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

49-
collections: collections,
50+
collections: collections,
51+
enableDetails: enableDetails,
5052
}
5153
}
5254

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

111113
pipeline := mongo.Pipeline{aggregation}
112114

115+
if !d.enableDetails {
116+
project := bson.D{
117+
{
118+
Key: "$project", Value: bson.M{
119+
"storageStats.wiredTiger": 0,
120+
"storageStats.indexDetails": 0,
121+
},
122+
},
123+
}
124+
pipeline = append(pipeline, project)
125+
}
126+
113127
cursor, err := client.Database(database).Collection(collection).Aggregate(d.ctx, pipeline)
114128
if err != nil {
115129
logger.Errorf("cannot get $collstats cursor for collection %s.%s: %s", database, collection, err)

exporter/collstats_collector_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestCollStatsCollector(t *testing.T) {
5454

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

5959
// The last \n at the end of this string is important
6060
expected := strings.NewReader(`

exporter/exporter.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,13 @@ type Exporter struct {
4545

4646
// Opts holds new exporter options.
4747
type Opts struct {
48-
// Only get stats for the collections matching this list of namespaces.
49-
// Example: db1.col1,db.col1
50-
CollStatsNamespaces []string
51-
CollStatsLimit int
5248
CompatibleMode bool
5349
DirectConnect bool
5450
ConnectTimeoutMS int
5551
DisableDefaultRegistry bool
5652
DiscoveringMode bool
5753
GlobalConnPool bool
58-
ProfileTimeTS int
5954
TimeoutOffset int
60-
CurrentOpSlowTime string
6155

6256
CollectAll bool
6357
EnableDBStats bool
@@ -72,14 +66,20 @@ type Opts struct {
7266
EnableProfile bool
7367
EnableShards bool
7468
EnableFCV bool // Feature Compatibility Version.
69+
EnablePBMMetrics bool
7570

7671
EnableOverrideDescendingIndex bool
7772

78-
// Enable metrics for Percona Backup for MongoDB (PBM).
79-
EnablePBMMetrics bool
73+
// Only get stats for the collections matching this list of namespaces.
74+
// Example: db1.col1,db.col1
75+
CollStatsNamespaces []string
76+
CollStatsLimit int
77+
CollStatsEnableDetails bool
78+
IndexStatsCollections []string
79+
CurrentOpSlowTime string
80+
ProfileTimeTS int
8081

81-
IndexStatsCollections []string
82-
Logger *logrus.Logger
82+
Logger *logrus.Logger
8383

8484
URI string
8585
NodeName string
@@ -192,7 +192,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
192192
if (len(e.opts.CollStatsNamespaces) > 0 || e.opts.DiscoveringMode) && e.opts.EnableCollStats && limitsOk && requestOpts.EnableCollStats {
193193
cc := newCollectionStatsCollector(ctx, client, e.opts.Logger,
194194
e.opts.DiscoveringMode,
195-
topologyInfo, e.opts.CollStatsNamespaces)
195+
topologyInfo, e.opts.CollStatsNamespaces, e.opts.CollStatsEnableDetails)
196196
registry.MustRegister(cc)
197197
}
198198

main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ type GlobalFlags struct {
7070

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

73-
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"`
73+
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"`
74+
CollStatsEnableDetails bool `name:"collector.collstats-enable-details" help:"Enable collecting index details and wired tiger metrics from $collStats" default:"false"`
7475

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

@@ -192,10 +193,11 @@ func buildExporter(opts GlobalFlags, uri string, log *logrus.Logger) *exporter.E
192193

193194
EnableOverrideDescendingIndex: opts.EnableOverrideDescendingIndex,
194195

195-
CollStatsLimit: opts.CollStatsLimit,
196-
CollectAll: opts.CollectAll,
197-
ProfileTimeTS: opts.ProfileTimeTS,
198-
CurrentOpSlowTime: opts.CurrentOpSlowTime,
196+
CollStatsLimit: opts.CollStatsLimit,
197+
CollStatsEnableDetails: opts.CollStatsEnableDetails,
198+
CollectAll: opts.CollectAll,
199+
ProfileTimeTS: opts.ProfileTimeTS,
200+
CurrentOpSlowTime: opts.CurrentOpSlowTime,
199201
}
200202

201203
e := exporter.New(exporterOpts)

0 commit comments

Comments
 (0)