-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* PMM-13141 Added feature compatibility version collector * PMM-13141 Fixed testing mongo version * PMM-13141 Ran format * PMM-13141 Fix for linters * PMM-13141 Fixed tests for different mdb versions * PMM-13141 Fix for linters * PMM-13141 Trigger build * PMM-13141 Fix for linters * PMM-13141 Trigger build * PMM-13141 Removed scrape interval. * PMM-13141 Removed last_scrape label. * PMM-13141 Fix linters. * PMM-13141 fix test. * PMM-13141 fix test. * PMM-13141 fix test. * PMM-13141 fix test. * PMM-13141 fix test. * PMM-13141 fix test. * PMM-13141 fix test. --------- Co-authored-by: Jiří Čtvrtka <[email protected]> Co-authored-by: Nurlan Moldomurov <[email protected]>
- Loading branch information
1 parent
88ce83d
commit 23502f1
Showing
9 changed files
with
228 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// mongodb_exporter | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package exporter | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/sirupsen/logrus" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type featureCompatibilityCollector struct { | ||
ctx context.Context | ||
base *baseCollector | ||
} | ||
|
||
// newProfileCollector creates a collector for being processed queries. | ||
func newFeatureCompatibilityCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger) *featureCompatibilityCollector { | ||
return &featureCompatibilityCollector{ | ||
ctx: ctx, | ||
base: newBaseCollector(client, logger.WithFields(logrus.Fields{"collector": "featureCompatibility"})), | ||
} | ||
} | ||
|
||
func (d *featureCompatibilityCollector) Describe(ch chan<- *prometheus.Desc) { | ||
d.base.Describe(d.ctx, ch, d.collect) | ||
} | ||
|
||
func (d *featureCompatibilityCollector) Collect(ch chan<- prometheus.Metric) { | ||
d.base.Collect(ch) | ||
} | ||
|
||
func (d *featureCompatibilityCollector) collect(ch chan<- prometheus.Metric) { | ||
defer measureCollectTime(ch, "mongodb", "profile")() | ||
|
||
cmd := bson.D{{Key: "getParameter", Value: 1}, {Key: "featureCompatibilityVersion", Value: 1}} | ||
client := d.base.client | ||
if client == nil { | ||
return | ||
} | ||
res := client.Database("admin").RunCommand(d.ctx, cmd) | ||
|
||
m := make(map[string]interface{}) | ||
if err := res.Decode(&m); err != nil { | ||
d.base.logger.Errorf("Failed to decode featureCompatibilityVersion: %v", err) | ||
ch <- prometheus.NewInvalidMetric(prometheus.NewInvalidDesc(err), err) | ||
return | ||
} | ||
|
||
rawValue := walkTo(m, []string{"featureCompatibilityVersion", "version"}) | ||
if rawValue != nil { | ||
versionString := fmt.Sprintf("%v", rawValue) | ||
version, err := strconv.ParseFloat(versionString, 64) | ||
if err != nil { | ||
d.base.logger.Errorf("Failed to parse featureCompatibilityVersion: %v", err) | ||
ch <- prometheus.NewInvalidMetric(prometheus.NewInvalidDesc(err), err) | ||
return | ||
} | ||
|
||
d := prometheus.NewDesc("mongodb_fcv_feature_compatibility_version", "Feature compatibility version", []string{"version"}, map[string]string{}) | ||
ch <- prometheus.MustNewConstMetric(d, prometheus.GaugeValue, version, versionString) | ||
} | ||
} |
Oops, something went wrong.