Skip to content

Commit af0a25f

Browse files
fix invalid memory address, added collect.shardingstatus flag (#199)
* fix "panic: runtime error: invalid memory address or nil pointer dereference" * replace spaces with tabs * changelog, version * recommendation: from collect.shardingstatus to suppress.collectshardingstatus * add new flag to test help
1 parent f5e8ebe commit af0a25f

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.11.2]
11+
### Added
12+
- [PMM-6361](https://jira.percona.com/browse/PMM-6361): New flag `--suppress.collectshardingstatus` can be used to disable the collection of Sharding Status. This flag is not set by default.
13+
On a large scale cluster it could help you to disable the mongoS exporters induced load to config tables. [@vrazvan-adobe](https://github.com/vrazvan-adobe)
14+
15+
### Fixed
16+
- [PMM-6361](https://jira.percona.com/browse/PMM-6361): `runtime error: invalid memory address or nil pointer dereference`, source="sharding_status.go:166" .
17+
When chunks collection is very big, the aggregate on it can take longer then default default 1000ms SocketTimeout. [@vrazvan-adobe](https://github.com/vrazvan-adobe)
18+
19+
1020
## [0.11.0]
1121
### Changed
1222
- `go.mongodb.org/mongo-driver` was updated to `v1.3.2`.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.10.0
1+
0.11.2

collector/mongodb_collector.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type MongodbCollectorOpts struct {
4040
CollectTopMetrics bool
4141
CollectIndexUsageStats bool
4242
CollectConnPoolStats bool
43+
SuppressCollectShardingStatus bool
4344
}
4445

4546
func (in *MongodbCollectorOpts) toSessionOps() *shared.MongoSessionOpts {
@@ -226,10 +227,12 @@ func (exporter *MongodbCollector) collectMongos(client *mongo.Client, ch chan<-
226227
serverStatus.Export(ch)
227228
}
228229

229-
log.Debug("Collecting Sharding Status")
230-
shardingStatus := mongos.GetShardingStatus(client)
231-
if shardingStatus != nil {
232-
shardingStatus.Export(ch)
230+
if !exporter.Opts.SuppressCollectShardingStatus {
231+
log.Debug("Collecting Sharding Status")
232+
shardingStatus := mongos.GetShardingStatus(client)
233+
if shardingStatus != nil {
234+
shardingStatus.Export(ch)
235+
}
233236
}
234237

235238
if exporter.Opts.CollectDatabaseMetrics {

collector/mongos/sharding_status.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ func IsClusterBalanced(client *mongo.Client) float64 {
163163
var minChunkCount float64 = -1
164164
var maxChunkCount float64 = 0
165165
shardChunkInfoAll := GetTotalChunksByShard(client)
166-
for _, shard := range *shardChunkInfoAll {
167-
if shard.Chunks > maxChunkCount {
168-
maxChunkCount = shard.Chunks
169-
}
170-
if minChunkCount == -1 || shard.Chunks < minChunkCount {
171-
minChunkCount = shard.Chunks
166+
if shardChunkInfoAll != nil {
167+
for _, shard := range *shardChunkInfoAll {
168+
if shard.Chunks > maxChunkCount {
169+
maxChunkCount = shard.Chunks
170+
}
171+
if minChunkCount == -1 || shard.Chunks < minChunkCount {
172+
minChunkCount = shard.Chunks
173+
}
172174
}
173175
}
174176

mongodb_exporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
collectTopF = kingpin.Flag("collect.topmetrics", "Enable collection of table top metrics").Bool()
4848
collectIndexUsageF = kingpin.Flag("collect.indexusage", "Enable collection of per index usage stats").Bool()
4949
mongodbCollectConnPoolStatsF = kingpin.Flag("collect.connpoolstats", "Collect MongoDB connpoolstats").Bool()
50+
suppressCollectShardingStatusF = kingpin.Flag("suppress.collectshardingstatus", "Suppress the collection of Sharding Status").Default("false").Bool()
5051

5152
uriF = kingpin.Flag("mongodb.uri", "MongoDB URI, format").
5253
PlaceHolder("[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]").
@@ -88,6 +89,7 @@ func main() {
8889
CollectTopMetrics: *collectTopF,
8990
CollectIndexUsageStats: *collectIndexUsageF,
9091
CollectConnPoolStats: *mongodbCollectConnPoolStatsF,
92+
SuppressCollectShardingStatus: *suppressCollectShardingStatusF,
9193
})
9294
prometheus.MustRegister(programCollector, mongodbCollector)
9395

testdata/mongodb_exporter.testFlagHelp.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Flags:
2424
--collect.topmetrics Enable collection of table top metrics
2525
--collect.indexusage Enable collection of per index usage stats
2626
--collect.connpoolstats Collect MongoDB connpoolstats
27+
--suppress.collectshardingstatus
28+
Suppress the collection of Sharding Status
2729
--mongodb.uri=[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]
2830
MongoDB URI, format
2931
--test Check MongoDB connection, print buildInfo()

0 commit comments

Comments
 (0)