-
Notifications
You must be signed in to change notification settings - Fork 440
Restore server status collector #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trvrnrth
wants to merge
7
commits into
percona:main
Choose a base branch
from
bugsnag:restore-server-status-collector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a627fc7
Revert "PMM-10292 Remove unused collector (#547)"
trvrnrth 41cbfb6
Allow use of server status collector with new flag
trvrnrth 8019ed4
Exclude server status histogram metrics
trvrnrth 70a3bae
Prevent duplicate collection and always run renaming/label logic
trvrnrth a226795
Fix test expectations
trvrnrth 40a3201
Add --collector.serverstatus to reference
trvrnrth a93062a
Use measureCollectTime for server status collector
trvrnrth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
// mongodb_exporter | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package exporter | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/sirupsen/logrus" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/mongo" | ||
) | ||
|
||
type serverStatusCollector struct { | ||
ctx context.Context | ||
base *baseCollector | ||
|
||
compatibleMode bool | ||
topologyInfo labelsGetter | ||
} | ||
|
||
// newServerStatusCollector creates a collector for statistics on server status. | ||
func newServerStatusCollector(ctx context.Context, client *mongo.Client, logger *logrus.Logger, compatible bool, topology labelsGetter) *serverStatusCollector { | ||
return &serverStatusCollector{ | ||
ctx: ctx, | ||
base: newBaseCollector(client, logger), | ||
compatibleMode: compatible, | ||
topologyInfo: topology, | ||
} | ||
} | ||
|
||
func (d *serverStatusCollector) Describe(ch chan<- *prometheus.Desc) { | ||
d.base.Describe(d.ctx, ch, d.collect) | ||
} | ||
|
||
func (d *serverStatusCollector) Collect(ch chan<- prometheus.Metric) { | ||
d.base.Collect(ch) | ||
} | ||
|
||
func (d *serverStatusCollector) collect(ch chan<- prometheus.Metric) { | ||
defer measureCollectTime(ch, "mongodb", "serverstatus")() | ||
|
||
logger := d.base.logger | ||
client := d.base.client | ||
|
||
cmd := bson.D{ | ||
{ | ||
Key: "serverStatus", Value: "1", | ||
}, | ||
{ | ||
Key: "metrics", Value: bson.M{ | ||
// TODO: PMM-9568 : Add support to handle histogram metrics | ||
"query": bson.M{"multiPlanner": bson.M{"histograms": false}}, | ||
}, | ||
}, | ||
} | ||
res := client.Database("admin").RunCommand(d.ctx, cmd) | ||
|
||
var m bson.M | ||
if err := res.Decode(&m); err != nil { | ||
ch <- prometheus.NewInvalidMetric(prometheus.NewInvalidDesc(err), err) | ||
return | ||
} | ||
|
||
logger.Debug("serverStatus result:") | ||
debugResult(logger, m) | ||
|
||
for _, metric := range makeMetrics("", bson.M{"serverStatus": m}, d.topologyInfo.baseLabels(), d.compatibleMode) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The nesting here facilitates the desired renaming and label management in |
||
ch <- metric | ||
} | ||
} |
This file contains hidden or 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,60 @@ | ||
// mongodb_exporter | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package exporter | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/percona/mongodb_exporter/internal/tu" | ||
) | ||
|
||
func TestServerStatusDataCollector(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
client := tu.DefaultTestClient(ctx, t) | ||
|
||
ti := labelsGetterMock{} | ||
|
||
c := newServerStatusCollector(ctx, client, logrus.New(), false, ti) | ||
|
||
// The last \n at the end of this string is important | ||
expected := strings.NewReader(` | ||
# HELP mongodb_ss_mem_bits serverStatus.mem. | ||
# TYPE mongodb_ss_mem_bits untyped | ||
mongodb_ss_mem_bits 64 | ||
# HELP mongodb_ss_metrics_commands_connPoolSync_failed serverStatus.metrics.commands.connPoolSync. | ||
# TYPE mongodb_ss_metrics_commands_connPoolSync_failed untyped | ||
mongodb_ss_metrics_commands_connPoolSync_failed 0` + "\n") | ||
// Filter metrics for 2 reasons: | ||
// 1. The result is huge | ||
// 2. We need to check against know values. Don't use metrics that return counters like uptime | ||
// or counters like the number of transactions because they won't return a known value to compare | ||
filter := []string{ | ||
"mongodb_ss_mem_bits", | ||
"mongodb_ss_metrics_commands_connPoolSync_failed", | ||
} | ||
err := testutil.CollectAndCompare(c, expected, filter...) | ||
assert.NoError(t, err) | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nesting here facilitates the desired renaming and label management in
makeMetrics
in the same manner as when fetched viagetDiagnosticData
.This is a breaking change when running with
--collector.replicasetstatus
as these metrics were previously prefixed withmongodb_
and will now be prefixed withmongodb_rs_
. This achieves parity with the metrics returned when using--collector.diagnosticdata
and allows for easy switching between the collection methods.