diff --git a/exporter/diagnostic_data_collector.go b/exporter/diagnostic_data_collector.go index 49d19f19..c8f57dd8 100644 --- a/exporter/diagnostic_data_collector.go +++ b/exporter/diagnostic_data_collector.go @@ -112,13 +112,25 @@ func (d *diagnosticDataCollector) collect(ch chan<- prometheus.Metric) { err = errors.Wrapf(errUnexpectedDataType, "%T for data field", m["data"]) logger.Errorf("cannot decode getDiagnosticData: %s", err) } - if c, ok := m["common"].(bson.M); ok { - m = c - } logger.Debug("getDiagnosticData result") debugResult(logger, m) + // MongoDB 8.0 splits the diagnostic data into multiple blocks, so we need to merge them + if d.buildInfo.VersionArray[0] >= 8 { + b := bson.M{} + for _, mv := range m { + block, ok := mv.(bson.M) + if !ok { + continue + } + for k, v := range block { + b[k] = v + } + } + m = b + } + metrics = makeMetrics("", m, d.topologyInfo.baseLabels(), d.compatibleMode) metrics = append(metrics, locksMetrics(logger, m)...) diff --git a/exporter/exporter.go b/exporter/exporter.go index faa3d2b4..23e93992 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -239,7 +239,7 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol // replSetGetStatus is not supported through mongos. if e.opts.EnableReplicasetStatus && nodeType != typeMongos && requestOpts.EnableReplicasetStatus { rsgsc := newReplicationSetStatusCollector(ctx, client, e.opts.Logger, - e.opts.CompatibleMode, topologyInfo, dbBuildInfo) + e.opts.CompatibleMode, topologyInfo) registry.MustRegister(rsgsc) } diff --git a/exporter/exporter_test.go b/exporter/exporter_test.go index ccc788af..4260567c 100644 --- a/exporter/exporter_test.go +++ b/exporter/exporter_test.go @@ -27,12 +27,10 @@ import ( "sync" "testing" + "github.com/percona/mongodb_exporter/internal/tu" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/percona/mongodb_exporter/internal/tu" ) // Use this for testing because labels like cluster ID are not constant in docker containers @@ -187,10 +185,7 @@ func TestMongoS(t *testing.T) { assert.NoError(t, err) e := New(exporterOpts) - - version, err := retrieveMongoDBBuildInfo(ctx, client, exporterOpts.Logger.WithField("component", "test")) - require.NoError(t, err) - rsgsc := newReplicationSetStatusCollector(ctx, client, e.opts.Logger, e.opts.CompatibleMode, new(labelsGetterMock), version) + rsgsc := newReplicationSetStatusCollector(ctx, client, e.opts.Logger, e.opts.CompatibleMode, new(labelsGetterMock)) r := e.makeRegistry(ctx, client, new(labelsGetterMock), *e.opts) diff --git a/exporter/replset_status_collector.go b/exporter/replset_status_collector.go index 5266b768..9e4d75e1 100644 --- a/exporter/replset_status_collector.go +++ b/exporter/replset_status_collector.go @@ -17,8 +17,6 @@ package exporter import ( "context" - "strings" - "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" "go.mongodb.org/mongo-driver/bson" @@ -36,19 +34,16 @@ type replSetGetStatusCollector struct { compatibleMode bool topologyInfo labelsGetter - - version buildInfo } // newReplicationSetStatusCollector creates a collector for statistics on replication set. -func newReplicationSetStatusCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, compatible bool, topology labelsGetter, version buildInfo) *replSetGetStatusCollector { +func newReplicationSetStatusCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, compatible bool, topology labelsGetter) *replSetGetStatusCollector { return &replSetGetStatusCollector{ ctx: ctx, base: newBaseCollector(client, logger.WithFields(logrus.Fields{"collector": "replset_status"})), compatibleMode: compatible, topologyInfo: topology, - version: version, } } @@ -88,19 +83,6 @@ func (d *replSetGetStatusCollector) collect(ch chan<- prometheus.Metric) { for _, metric := range makeMetrics("", m, d.topologyInfo.baseLabels(), d.compatibleMode) { ch <- metric } - - if strings.HasPrefix(d.version.Version, "8.") { - for _, metric := range makeMetrics("rs", m, d.topologyInfo.baseLabels(), d.compatibleMode) { - ch <- metric - } - if d.compatibleMode { - logger.Infof("collecting compatibility metrics for version %s", d.version.Version) - metrics := replSetMetrics(m, logger) - for _, metric := range metrics { - ch <- metric - } - } - } } var _ prometheus.Collector = (*replSetGetStatusCollector)(nil) diff --git a/exporter/replset_status_collector_test.go b/exporter/replset_status_collector_test.go index 789252ad..ce7682f8 100644 --- a/exporter/replset_status_collector_test.go +++ b/exporter/replset_status_collector_test.go @@ -21,12 +21,10 @@ import ( "testing" "time" + "github.com/percona/mongodb_exporter/internal/tu" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/percona/mongodb_exporter/internal/tu" ) func TestReplsetStatusCollector(t *testing.T) { @@ -37,9 +35,7 @@ func TestReplsetStatusCollector(t *testing.T) { ti := labelsGetterMock{} - version, err := retrieveMongoDBBuildInfo(ctx, client, logrus.New().WithField("component", "test")) - require.NoError(t, err) - c := newReplicationSetStatusCollector(ctx, client, logrus.New(), false, ti, version) + c := newReplicationSetStatusCollector(ctx, client, logrus.New(), false, ti) // The last \n at the end of this string is important expected := strings.NewReader(` @@ -57,7 +53,7 @@ func TestReplsetStatusCollector(t *testing.T) { "mongodb_myState", "mongodb_ok", } - err = testutil.CollectAndCompare(c, expected, filter...) + err := testutil.CollectAndCompare(c, expected, filter...) assert.NoError(t, err) } @@ -69,10 +65,7 @@ func TestReplsetStatusCollectorNoSharding(t *testing.T) { ti := labelsGetterMock{} - version, err := retrieveMongoDBBuildInfo(ctx, client, logrus.New().WithField("component", "test")) - require.NoError(t, err) - - c := newReplicationSetStatusCollector(ctx, client, logrus.New(), false, ti, version) + c := newReplicationSetStatusCollector(ctx, client, logrus.New(), false, ti) // Replication set metrics should not be generated for unsharded server count := testutil.CollectAndCount(c)