summaryrefslogtreecommitdiff
path: root/src/mongo/db/stats
diff options
context:
space:
mode:
authorAdam Cooper <adam.cooper@mongodb.com>2020-08-14 13:46:35 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-14 21:01:59 +0000
commit24dd72daae9e4cf59ad51910058bc111f20edbff (patch)
treef019be38662bc5a86c68ac1f4a006f479a408647 /src/mongo/db/stats
parent6b1a0403f17b688940eb9d86f41d95bdd943d3f4 (diff)
downloadmongo-24dd72daae9e4cf59ad51910058bc111f20edbff.tar.gz
SERVER-48693 Add network counter for cluster authentication
Diffstat (limited to 'src/mongo/db/stats')
-rw-r--r--src/mongo/db/stats/counters.cpp28
-rw-r--r--src/mongo/db/stats/counters.h7
2 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/stats/counters.cpp b/src/mongo/db/stats/counters.cpp
index 63a0b6eb66d..4180275393b 100644
--- a/src/mongo/db/stats/counters.cpp
+++ b/src/mongo/db/stats/counters.cpp
@@ -244,6 +244,24 @@ Status AuthCounter::incAuthenticateSuccessful(const std::string& mechanism) try
<< " which is not enabled"};
}
+Status AuthCounter::incClusterAuthenticateReceived(const std::string& mechanism) try {
+ _mechanisms.at(mechanism).clusterAuthenticate.received.fetchAndAddRelaxed(1);
+ return Status::OK();
+} catch (const std::out_of_range&) {
+ return {ErrorCodes::BadValue,
+ str::stream() << "Received authentication for mechanism " << mechanism
+ << " which is unknown or not enabled"};
+}
+
+Status AuthCounter::incClusterAuthenticateSuccessful(const std::string& mechanism) try {
+ _mechanisms.at(mechanism).clusterAuthenticate.successful.fetchAndAddRelaxed(1);
+ return Status::OK();
+} catch (const std::out_of_range&) {
+ return {ErrorCodes::BadValue,
+ str::stream() << "Received authentication for mechanism " << mechanism
+ << " which is not enabled"};
+}
+
/**
* authentication: {
* "mechanisms": {
@@ -275,6 +293,16 @@ void AuthCounter::append(BSONObjBuilder* b) {
}
{
+ const auto received = it.second.clusterAuthenticate.received.load();
+ const auto successful = it.second.clusterAuthenticate.successful.load();
+
+ BSONObjBuilder clusterAuthBuilder(mechBuilder.subobjStart(auth::kClusterAuthenticate));
+ clusterAuthBuilder.append("received", received);
+ clusterAuthBuilder.append("successful", successful);
+ clusterAuthBuilder.done();
+ }
+
+ {
const auto received = it.second.authenticate.received.load();
const auto successful = it.second.authenticate.successful.load();
diff --git a/src/mongo/db/stats/counters.h b/src/mongo/db/stats/counters.h
index 9b10cb2a049..a202746be03 100644
--- a/src/mongo/db/stats/counters.h
+++ b/src/mongo/db/stats/counters.h
@@ -226,6 +226,9 @@ public:
Status incAuthenticateReceived(const std::string& mechanism);
Status incAuthenticateSuccessful(const std::string& mechanism);
+ Status incClusterAuthenticateReceived(const std::string& mechanism);
+ Status incClusterAuthenticateSuccessful(const std::string& mechanism);
+
void append(BSONObjBuilder*);
void initializeMechanismMap(const std::vector<std::string>&);
@@ -240,6 +243,10 @@ private:
AtomicWord<long long> received;
AtomicWord<long long> successful;
} authenticate;
+ struct {
+ AtomicWord<long long> received;
+ AtomicWord<long long> successful;
+ } clusterAuthenticate;
};
using MechanismMap = std::map<std::string, MechanismData>;