Skip to content

Commit

Permalink
[chore] [receiver/mongodb] Remove redundant resource grouping (#33691)
Browse files Browse the repository at this point in the history
The produced metrics are unnecessarily grouped by empty resources. This
change removes the excessive grouping to keep only unique resources
  • Loading branch information
dmitryax authored Jun 21, 2024
1 parent cfd83af commit 0ff636c
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 290 deletions.
16 changes: 6 additions & 10 deletions receiver/mongodbreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func (s *mongodbScraper) collectMetrics(ctx context.Context, errs *scrapererror.
s.mb.RecordMongodbDatabaseCountDataPoint(now, int64(len(dbNames)))
s.collectAdminDatabase(ctx, now, errs)
s.collectTopStats(ctx, now, errs)
s.mb.EmitForResource()

// Collect metrics for each database
for _, dbName := range dbNames {
s.collectDatabase(ctx, now, dbName, errs)
collectionNames, err := s.client.ListCollectionNames(ctx, dbName)
Expand All @@ -110,6 +112,10 @@ func (s *mongodbScraper) collectMetrics(ctx context.Context, errs *scrapererror.
for _, collectionName := range collectionNames {
s.collectIndexStats(ctx, now, dbName, collectionName, errs)
}

rb := s.mb.NewResourceBuilder()
rb.SetDatabase(dbName)
s.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}
}

Expand All @@ -127,10 +133,6 @@ func (s *mongodbScraper) collectDatabase(ctx context.Context, now pcommon.Timest
return
}
s.recordNormalServerStats(now, serverStatus, databaseName, errs)

rb := s.mb.NewResourceBuilder()
rb.SetDatabase(databaseName)
s.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}

func (s *mongodbScraper) collectAdminDatabase(ctx context.Context, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
Expand All @@ -140,7 +142,6 @@ func (s *mongodbScraper) collectAdminDatabase(ctx context.Context, now pcommon.T
return
}
s.recordAdminStats(now, serverStatus, errs)
s.mb.EmitForResource()
}

func (s *mongodbScraper) collectTopStats(ctx context.Context, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
Expand All @@ -150,7 +151,6 @@ func (s *mongodbScraper) collectTopStats(ctx context.Context, now pcommon.Timest
return
}
s.recordOperationTime(now, topStats, errs)
s.mb.EmitForResource()
}

func (s *mongodbScraper) collectIndexStats(ctx context.Context, now pcommon.Timestamp, databaseName string, collectionName string, errs *scrapererror.ScrapeErrors) {
Expand All @@ -163,10 +163,6 @@ func (s *mongodbScraper) collectIndexStats(ctx context.Context, now pcommon.Time
return
}
s.recordIndexStats(now, indexStats, databaseName, collectionName, errs)

rb := s.mb.NewResourceBuilder()
rb.SetDatabase(databaseName)
s.mb.EmitForResource(metadata.WithResource(rb.Emit()))
}

func (s *mongodbScraper) recordDBStats(now pcommon.Timestamp, doc bson.M, dbName string, errs *scrapererror.ScrapeErrors) {
Expand Down
133 changes: 48 additions & 85 deletions receiver/mongodbreceiver/testdata/integration/expected.4_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ resourceMetrics:
timeUnixNano: "1682363210513475000"
isMonotonic: true
unit: '{operations}'
- description: The total number of active sessions.
name: mongodb.session.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "19"
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{sessions}'
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes: []
scopeMetrics:
- metrics:
- description: The total time spent performing operations.
name: mongodb.operation.time
sum:
Expand Down Expand Up @@ -202,6 +186,15 @@ resourceMetrics:
timeUnixNano: "1682363210513475000"
isMonotonic: true
unit: ms
- description: The total number of active sessions.
name: mongodb.session.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "19"
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{sessions}'
scope:
name: otelcol/mongodbreceiver
version: latest
Expand Down Expand Up @@ -293,6 +286,19 @@ resourceMetrics:
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{extents}'
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: system.version
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
- description: The number of indexes.
name: mongodb.index.count
sum:
Expand Down Expand Up @@ -353,29 +359,6 @@ resourceMetrics:
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
value:
stringValue: admin
scopeMetrics:
- metrics:
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: system.version
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
Expand Down Expand Up @@ -464,6 +447,19 @@ resourceMetrics:
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{extents}'
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: system.sessions
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
- description: The number of indexes.
name: mongodb.index.count
sum:
Expand Down Expand Up @@ -524,29 +520,6 @@ resourceMetrics:
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
value:
stringValue: config
scopeMetrics:
- metrics:
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: system.sessions
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
Expand Down Expand Up @@ -783,6 +756,19 @@ resourceMetrics:
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{extents}'
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: orders
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
- description: The number of indexes.
name: mongodb.index.count
sum:
Expand Down Expand Up @@ -843,26 +829,3 @@ resourceMetrics:
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
value:
stringValue: testdb
scopeMetrics:
- metrics:
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: orders
startTimeUnixNano: "1682363190502544000"
timeUnixNano: "1682363210513475000"
unit: '{accesses}'
scope:
name: otelcol/mongodbreceiver
version: latest
61 changes: 22 additions & 39 deletions receiver/mongodbreceiver/testdata/integration/expected.4_4lpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ resourceMetrics:
timeUnixNano: "1682363222253814000"
isMonotonic: true
unit: '{operations}'
- description: The total number of active sessions.
name: mongodb.session.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "15"
startTimeUnixNano: "1682363202250964000"
timeUnixNano: "1682363222253814000"
unit: '{sessions}'
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes: []
scopeMetrics:
- metrics:
- description: The total time spent performing operations.
name: mongodb.operation.time
sum:
Expand Down Expand Up @@ -202,6 +186,15 @@ resourceMetrics:
timeUnixNano: "1682363222253814000"
isMonotonic: true
unit: ms
- description: The total number of active sessions.
name: mongodb.session.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "15"
startTimeUnixNano: "1682363202250964000"
timeUnixNano: "1682363222253814000"
unit: '{sessions}'
scope:
name: otelcol/mongodbreceiver
version: latest
Expand Down Expand Up @@ -701,6 +694,19 @@ resourceMetrics:
startTimeUnixNano: "1682363202250964000"
timeUnixNano: "1682363222253814000"
unit: '{documents}'
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: orders
startTimeUnixNano: "1682363202250964000"
timeUnixNano: "1682363222253814000"
unit: '{accesses}'
- description: The number of indexes.
name: mongodb.index.count
sum:
Expand Down Expand Up @@ -761,26 +767,3 @@ resourceMetrics:
scope:
name: otelcol/mongodbreceiver
version: latest
- resource:
attributes:
- key: database
value:
stringValue: testdb
scopeMetrics:
- metrics:
- description: The number of times an index has been accessed.
name: mongodb.index.access.count
sum:
aggregationTemporality: 2
dataPoints:
- asInt: "0"
attributes:
- key: collection
value:
stringValue: orders
startTimeUnixNano: "1682363202250964000"
timeUnixNano: "1682363222253814000"
unit: '{accesses}'
scope:
name: otelcol/mongodbreceiver
version: latest
Loading

0 comments on commit 0ff636c

Please sign in to comment.