Skip to content

Commit d5aa8f6

Browse files
authored
fix nil pointer to support mongo 4.4 (#32)
1 parent 65d9e0b commit d5aa8f6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

collector/metrics.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,13 @@ type PreloadStats struct {
376376

377377
// Export exposes the preload stats.
378378
func (preloadStats *PreloadStats) Export(ch chan<- prometheus.Metric) {
379-
metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num)
380-
metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis)
379+
if preloadStats != nil {
380+
metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num)
381+
metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis)
381382

382-
metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num)
383-
metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis)
383+
metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num)
384+
metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis)
385+
}
384386
}
385387

386388
// StorageStats are the stats associated with the storage.
@@ -420,8 +422,8 @@ func (cursorStats *CursorStats) Export(ch chan<- prometheus.Metric) {
420422

421423
// TTLStats are the stats with a ttl index
422424
type TTLStats struct {
423-
DeletedDocuments float64 `bson:"deletedDocuments"`
424-
Passes float64 `bson:"passes"`
425+
DeletedDocuments float64 `bson:"deletedDocuments"`
426+
Passes float64 `bson:"passes"`
425427
}
426428

427429
// Export exports the ttl stats.
@@ -432,8 +434,8 @@ func (ttlStats *TTLStats) Export(ch chan<- prometheus.Metric) {
432434

433435
// QueryStats are the stats with a ttl index
434436
type QueryStats struct {
435-
PlanCacheSize float64 `bson:"planCacheTotalSizeEstimateBytes"`
436-
UpdateCount float64 `bson:"updateOneOpStyleBroadcastWithExactIDCount"`
437+
PlanCacheSize float64 `bson:"planCacheTotalSizeEstimateBytes"`
438+
UpdateCount float64 `bson:"updateOneOpStyleBroadcastWithExactIDCount"`
437439
}
438440

439441
// Export exports the query stats.

0 commit comments

Comments
 (0)