From d5aa8f622d64e6bb2f8e23a9b00b84aa623e7e37 Mon Sep 17 00:00:00 2001 From: hzhao-wish Date: Tue, 13 Dec 2022 12:33:40 -0800 Subject: [PATCH] fix nil pointer to support mongo 4.4 (#32) --- collector/metrics.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/collector/metrics.go b/collector/metrics.go index a438769..480d1ce 100644 --- a/collector/metrics.go +++ b/collector/metrics.go @@ -376,11 +376,13 @@ type PreloadStats struct { // Export exposes the preload stats. func (preloadStats *PreloadStats) Export(ch chan<- prometheus.Metric) { - metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num) - metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis) + if preloadStats != nil { + metricsReplPreloadDocsNumTotal.Set(preloadStats.Docs.Num) + metricsReplPreloadDocsTotalMilliseconds.Set(preloadStats.Docs.TotalMillis) - metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num) - metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis) + metricsReplPreloadIndexesNumTotal.Set(preloadStats.Indexes.Num) + metricsReplPreloadIndexesTotalMilliseconds.Set(preloadStats.Indexes.TotalMillis) + } } // StorageStats are the stats associated with the storage. @@ -420,8 +422,8 @@ func (cursorStats *CursorStats) Export(ch chan<- prometheus.Metric) { // TTLStats are the stats with a ttl index type TTLStats struct { - DeletedDocuments float64 `bson:"deletedDocuments"` - Passes float64 `bson:"passes"` + DeletedDocuments float64 `bson:"deletedDocuments"` + Passes float64 `bson:"passes"` } // Export exports the ttl stats. @@ -432,8 +434,8 @@ func (ttlStats *TTLStats) Export(ch chan<- prometheus.Metric) { // QueryStats are the stats with a ttl index type QueryStats struct { - PlanCacheSize float64 `bson:"planCacheTotalSizeEstimateBytes"` - UpdateCount float64 `bson:"updateOneOpStyleBroadcastWithExactIDCount"` + PlanCacheSize float64 `bson:"planCacheTotalSizeEstimateBytes"` + UpdateCount float64 `bson:"updateOneOpStyleBroadcastWithExactIDCount"` } // Export exports the query stats.