Skip to content

Commit c939630

Browse files
committed
PMM-13602 Improve performance for callstats
1 parent 9603c7f commit c939630

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

exporter/collstats_collector.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ type collstatsCollector struct {
3737
}
3838

3939
// newCollectionStatsCollector creates a collector for statistics about collections.
40-
func newCollectionStatsCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, compatible, discovery bool, topology labelsGetter, collections []string) *collstatsCollector {
40+
func newCollectionStatsCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, discovery bool, topology labelsGetter, collections []string) *collstatsCollector {
4141
return &collstatsCollector{
4242
ctx: ctx,
4343
base: newBaseCollector(client, logger.WithFields(logrus.Fields{"collector": "collstats"})),
4444

45-
compatibleMode: compatible,
45+
compatibleMode: false, //there are no compatible metrics for this collector.
4646
discoveringMode: discovery,
4747
topologyInfo: topology,
4848

@@ -107,8 +107,18 @@ func (d *collstatsCollector) collect(ch chan<- prometheus.Metric) {
107107
},
108108
},
109109
}
110+
project := bson.D{
111+
{
112+
Key: "$project", Value: bson.M{
113+
"storageStats.wiredTiger": 0,
114+
"storageStats.indexDetails": 0,
115+
},
116+
},
117+
}
118+
119+
pipeline := mongo.Pipeline{aggregation, project}
110120

111-
cursor, err := client.Database(database).Collection(collection).Aggregate(d.ctx, mongo.Pipeline{aggregation})
121+
cursor, err := client.Database(database).Collection(collection).Aggregate(d.ctx, pipeline)
112122
if err != nil {
113123
logger.Errorf("cannot get $collstats cursor for collection %s.%s: %s", database, collection, err)
114124

exporter/collstats_collector_test.go

Lines changed: 1 addition & 1 deletion
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, false, ti, collection)
57+
c := newCollectionStatsCollector(ctx, client, logger, false, ti, collection)
5858

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

0 commit comments

Comments
 (0)