Make server API for load metrics

This commit is contained in:
Bharadwaj V.R 2022-03-02 14:29:43 -08:00 committed by Trevor Clinkenbeard
parent 2d2f7ed2c6
commit 7bad6c5093
2 changed files with 13 additions and 7 deletions

View File

@ -198,7 +198,7 @@ void TCServerInfo::removeTeamsContainingServer(UID removedServer) {
} }
} }
std::pair<int64_t, int64_t> TCServerInfo::spaceInBytes(bool includeInFlight) const { std::pair<int64_t, int64_t> TCServerInfo::spaceBytes(bool includeInFlight) const {
auto& metrics = getServerMetrics(); auto& metrics = getServerMetrics();
ASSERT(metrics.capacity.bytes >= 0); ASSERT(metrics.capacity.bytes >= 0);
ASSERT(metrics.available.bytes >= 0); ASSERT(metrics.available.bytes >= 0);
@ -211,6 +211,10 @@ std::pair<int64_t, int64_t> TCServerInfo::spaceInBytes(bool includeInFlight) con
return std::make_pair(bytesAvailable, metrics.capacity.bytes); // bytesAvailable could be negative return std::make_pair(bytesAvailable, metrics.capacity.bytes); // bytesAvailable could be negative
} }
int64_t TCServerInfo::loadBytes() const {
return getServerMetrics().load.bytes;
}
void TCServerInfo::removeTeam(Reference<TCTeamInfo> team) { void TCServerInfo::removeTeam(Reference<TCTeamInfo> team) {
for (int t = 0; t < teams.size(); t++) { for (int t = 0; t < teams.size(); t++) {
if (teams[t] == team) { if (teams[t] == team) {
@ -370,7 +374,7 @@ int64_t TCTeamInfo::getMinAvailableSpace(bool includeInFlight) const {
int64_t minAvailableSpace = std::numeric_limits<int64_t>::max(); int64_t minAvailableSpace = std::numeric_limits<int64_t>::max();
for (const auto& server : servers) { for (const auto& server : servers) {
if (server->serverMetricsPresent()) { if (server->serverMetricsPresent()) {
const auto [bytesAvailable, bytesCapacity] = server->spaceInBytes(includeInFlight); const auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
minAvailableSpace = std::min(bytesAvailable, minAvailableSpace); minAvailableSpace = std::min(bytesAvailable, minAvailableSpace);
} }
} }
@ -382,7 +386,7 @@ double TCTeamInfo::getMinAvailableSpaceRatio(bool includeInFlight) const {
double minRatio = 1.0; double minRatio = 1.0;
for (const auto& server : servers) { for (const auto& server : servers) {
if (server->serverMetricsPresent()) { if (server->serverMetricsPresent()) {
auto [bytesAvailable, bytesCapacity] = server->spaceInBytes(includeInFlight); auto [bytesAvailable, bytesCapacity] = server->spaceBytes(includeInFlight);
bytesAvailable = std::max((int64_t)0, bytesAvailable); bytesAvailable = std::max((int64_t)0, bytesAvailable);
if (bytesCapacity == 0) if (bytesCapacity == 0)
@ -437,10 +441,11 @@ void TCTeamInfo::addServers(const std::vector<UID>& servers) {
int64_t TCTeamInfo::getLoadAverage() const { int64_t TCTeamInfo::getLoadAverage() const {
int64_t bytesSum = 0; int64_t bytesSum = 0;
int added = 0; int added = 0;
for (int i = 0; i < servers.size(); i++) for (const auto& server : servers) {
if (servers[i]->serverMetricsPresent()) { if (server->serverMetricsPresent()) {
added++; added++;
bytesSum += servers[i]->getServerMetrics().load.bytes; bytesSum += server->loadBytes();
}
} }
if (added < servers.size()) if (added < servers.size())

View File

@ -97,7 +97,8 @@ public:
return (storeType == configStoreType || storeType == KeyValueStoreType::END); return (storeType == configStoreType || storeType == KeyValueStoreType::END);
} }
std::pair<int64_t, int64_t> spaceInBytes(bool includeInFlight = true) const; std::pair<int64_t, int64_t> spaceBytes(bool includeInFlight = true) const;
int64_t loadBytes() const;
bool hasHealthyAvailableSpace(double minAvailableSpaceRatio) const; bool hasHealthyAvailableSpace(double minAvailableSpaceRatio) const;
Future<Void> updateServerMetrics(); Future<Void> updateServerMetrics();