Skip to content

Commit

Permalink
fix invalid memory address, added collect.shardingstatus flag (#199)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
vrazvan-adobe authored Sep 3, 2020
1 parent f5e8ebe commit af0a25f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.11.2]
### Added
- [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.
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)

### Fixed
- [PMM-6361](https://jira.percona.com/browse/PMM-6361): `runtime error: invalid memory address or nil pointer dereference`, source="sharding_status.go:166" .
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)


## [0.11.0]
### Changed
- `go.mongodb.org/mongo-driver` was updated to `v1.3.2`.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0
0.11.2
11 changes: 7 additions & 4 deletions collector/mongodb_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type MongodbCollectorOpts struct {
CollectTopMetrics bool
CollectIndexUsageStats bool
CollectConnPoolStats bool
SuppressCollectShardingStatus bool
}

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

log.Debug("Collecting Sharding Status")
shardingStatus := mongos.GetShardingStatus(client)
if shardingStatus != nil {
shardingStatus.Export(ch)
if !exporter.Opts.SuppressCollectShardingStatus {
log.Debug("Collecting Sharding Status")
shardingStatus := mongos.GetShardingStatus(client)
if shardingStatus != nil {
shardingStatus.Export(ch)
}
}

if exporter.Opts.CollectDatabaseMetrics {
Expand Down
14 changes: 8 additions & 6 deletions collector/mongos/sharding_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,14 @@ func IsClusterBalanced(client *mongo.Client) float64 {
var minChunkCount float64 = -1
var maxChunkCount float64 = 0
shardChunkInfoAll := GetTotalChunksByShard(client)
for _, shard := range *shardChunkInfoAll {
if shard.Chunks > maxChunkCount {
maxChunkCount = shard.Chunks
}
if minChunkCount == -1 || shard.Chunks < minChunkCount {
minChunkCount = shard.Chunks
if shardChunkInfoAll != nil {
for _, shard := range *shardChunkInfoAll {
if shard.Chunks > maxChunkCount {
maxChunkCount = shard.Chunks
}
if minChunkCount == -1 || shard.Chunks < minChunkCount {
minChunkCount = shard.Chunks
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ var (
collectTopF = kingpin.Flag("collect.topmetrics", "Enable collection of table top metrics").Bool()
collectIndexUsageF = kingpin.Flag("collect.indexusage", "Enable collection of per index usage stats").Bool()
mongodbCollectConnPoolStatsF = kingpin.Flag("collect.connpoolstats", "Collect MongoDB connpoolstats").Bool()
suppressCollectShardingStatusF = kingpin.Flag("suppress.collectshardingstatus", "Suppress the collection of Sharding Status").Default("false").Bool()

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

Expand Down
2 changes: 2 additions & 0 deletions testdata/mongodb_exporter.testFlagHelp.golden
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Flags:
--collect.topmetrics Enable collection of table top metrics
--collect.indexusage Enable collection of per index usage stats
--collect.connpoolstats Collect MongoDB connpoolstats
--suppress.collectshardingstatus
Suppress the collection of Sharding Status
--mongodb.uri=[mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]
MongoDB URI, format
--test Check MongoDB connection, print buildInfo()
Expand Down

0 comments on commit af0a25f

Please sign in to comment.