Skip to content

Commit

Permalink
PMM-12712 Another refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriCtvrtka committed Jan 2, 2024
1 parent 5949050 commit e64dd93
Showing 1 changed file with 40 additions and 29 deletions.
69 changes: 40 additions & 29 deletions exporter/sharded_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,8 @@ func (d *shardedCollector) collect(ch chan<- prometheus.Metric) {

chunks := d.getChunksForCollection(row)
for _, c := range chunks {
if _, ok = c["dropped"]; !ok {
continue
}
var dropped bool
if dropped, ok = c["dropped"].(bool); !ok || dropped {
continue
}

labels := make(map[string]string)
labels["database"] = database
labels["collection"] = strings.Replace(rowID, fmt.Sprintf("%s.", database), "", 1)

if _, ok = c["shard"]; !ok {
continue
}
var shard string
if shard, ok = c["shard"].(string); !ok {
continue
}
labels["shard"] = shard

logger.Debug("$sharded metrics for config.chunks")
debugResult(logger, primitive.M{database: c})

if _, ok = c["nChunks"]; !ok {
continue
}
var chunks int32
if chunks, ok = c["nChunks"].(int32); !ok {
labels, chunks, success := d.getInfoForChunk(c, database, rowID)
if !success {
continue
}
for _, metric := range makeMetrics(prefix, primitive.M{"count": chunks}, labels, d.compatible) {
Expand All @@ -114,6 +87,44 @@ func (d *shardedCollector) collect(ch chan<- prometheus.Metric) {
}
}

func (d *shardedCollector) getInfoForChunk(c primitive.M, database, rowID string) (map[string]string, int32, bool) {
var ok bool
if _, ok = c["dropped"]; !ok {
return nil, 0, ok
}
var dropped bool
if dropped, ok = c["dropped"].(bool); !ok || dropped {
return nil, 0, false
}

labels := make(map[string]string)
labels["database"] = database
labels["collection"] = strings.Replace(rowID, fmt.Sprintf("%s.", database), "", 1)

if _, ok = c["shard"]; !ok {
return nil, 0, ok
}
var shard string
if shard, ok = c["shard"].(string); !ok {
return nil, 0, ok
}
labels["shard"] = shard

logger := d.base.logger
logger.Debug("$sharded metrics for config.chunks")
debugResult(logger, primitive.M{database: c})

if _, ok = c["nChunks"]; !ok {
return nil, 0, ok
}
var chunks int32
if chunks, ok = c["nChunks"].(int32); !ok {
return nil, 0, ok
}

return labels, chunks, true
}

func (d *shardedCollector) getCollectionsForDBName(database string) []primitive.M {
client := d.base.client
logger := d.base.logger
Expand Down

0 comments on commit e64dd93

Please sign in to comment.