diff options
author | Adam Cooper <adam.cooper@mongodb.com> | 2020-08-17 15:37:42 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-20 22:20:55 +0000 |
commit | ad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb (patch) | |
tree | 434438c6f3a9c5191642eabff503e211fd8b4047 /src/mongo/db/stats | |
parent | 504dee509b57ba039bcfe1130054aabc13839fa9 (diff) | |
download | mongo-ad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb.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.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/stats/counters.h | 7 |
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>; |