Skip to content

Commit

Permalink
split metrics collection
Browse files Browse the repository at this point in the history
  • Loading branch information
idoqo committed May 27, 2024
1 parent 9358e94 commit 4f1f516
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
17 changes: 12 additions & 5 deletions exporter/diagnostic_data_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,22 @@ func (d *diagnosticDataCollector) collect(ch chan<- prometheus.Metric) {
} else if securityMetric != nil {
metrics = append(metrics, securityMetric)
}
}

if d.compatibleMode {
metrics = append(metrics, specialMetrics(d.ctx, client, m, logger)...)
if d.compatibleMode {
metrics = append(metrics, specialMetrics(d.ctx, client, m, nodeType, logger)...)

if cem, err := cacheEvictedTotalMetric(m); err == nil {
metrics = append(metrics, cem)
if cem, err := cacheEvictedTotalMetric(m); err == nil {
metrics = append(metrics, cem)
}
}
}

if d.compatibleMode {
if nodeType == typeArbiter {
if hm := arbiterMetrics(d.ctx, client, logger); hm != nil {
metrics = append(metrics, hm...)
}
}
if nodeType == typeMongos {
metrics = append(metrics, mongosMetrics(d.ctx, client, logger)...)
}
Expand Down
19 changes: 5 additions & 14 deletions exporter/v1_compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func specialMetricDefinitions() []specialMetric {
}
}

func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, l *logrus.Logger) []prometheus.Metric {
func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, nodeType mongoDBNodeType, l *logrus.Logger) []prometheus.Metric {

Check failure on line 785 in exporter/v1_compatibility.go

View workflow job for this annotation

GitHub Actions / Lint Check

calculated cyclomatic complexity for function specialMetrics is 12, max is 10 (cyclop)
metrics := make([]prometheus.Metric, 0)

for _, def := range specialMetricDefinitions() {
Expand All @@ -807,25 +807,16 @@ func specialMetrics(ctx context.Context, client *mongo.Client, m bson.M, l *logr
l.Errorf("cannot retrieve MongoDB buildInfo: %s", err)
}

nodeType, err := getNodeType(ctx, client)
if err != nil {
l.WithFields(logrus.Fields{
"component": "diagnosticDataCollector",
}).Errorf("Cannot get node type: %s", err)
}

if nodeType == typeMongod || nodeType == typeArbiter {
if engine, err := storageEngine(m); err == nil {
if engine, err := storageEngine(m); err != nil {
l.Errorf("cannot retrieve engine type: %s", err)
} else {
metrics = append(metrics, engine)
}
}
metrics = append(metrics, serverVersion(buildInfo))

if nodeType == typeArbiter {
if hm := arbiterMetrics(ctx, client, l); hm != nil {
metrics = append(metrics, hm...)
}
} else {
if nodeType != typeArbiter {

Check failure on line 819 in exporter/v1_compatibility.go

View workflow job for this annotation

GitHub Actions / Lint Check

`if nodeType != typeArbiter` has complex nested blocks (complexity: 5) (nestif)
metrics = append(metrics, myState(ctx, client))
if rm := replSetMetrics(m); rm != nil {
metrics = append(metrics, rm...)
Expand Down

0 comments on commit 4f1f516

Please sign in to comment.