Skip to content

Commit

Permalink
Add failover policy specific stat counters
Browse files Browse the repository at this point in the history
Summary: Add failover policy specific stats counters, one for incrementing when failover occurs and another for incrementing when all failover destinations have been exhausted. Without these stats, the failover_all and failover_all_failed stats provide aggregated counts across all failover policies.

Reviewed By: andreazevedo

Differential Revision: D6741561

fbshipit-source-id: 4e44a982f7ceae9604fc5563c57007ca2548af03
  • Loading branch information
vrishal authored and facebook-github-bot committed Jan 18, 2018
1 parent 54fa7b4 commit 7cafcdb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
22 changes: 21 additions & 1 deletion mcrouter/routes/FailoverPolicy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Facebook, Inc.
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
Expand Down Expand Up @@ -74,6 +74,16 @@ class FailoverInOrderPolicy {
return Iterator(children_, children_.size());
}

// Returns the stat to increment when failover occurs.
stat_name_t getFailoverStat() const {
return failover_inorder_policy_stat;
}

// Returns the stat when all failover destinations are exhausted.
stat_name_t getFailoverFailedStat() const {
return failover_inorder_policy_failed_stat;
}

private:
const std::vector<RouteHandlePtr>& children_;
};
Expand Down Expand Up @@ -166,6 +176,16 @@ class FailoverLeastFailuresPolicy {
return Iterator(*this, maxTries_);
}

// Returns the stat to increment when failover occurs.
stat_name_t getFailoverStat() const {
return failover_least_failures_policy_stat;
}

// Returns the stat when all failover destinations are exhausted.
stat_name_t getFailoverFailedStat() const {
return failover_least_failures_policy_failed_stat;
}

private:
std::vector<size_t> getLeastFailureRouteIndices() const {
std::vector<size_t> indices;
Expand Down
4 changes: 3 additions & 1 deletion mcrouter/routes/FailoverRoute.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Facebook, Inc.
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
Expand Down Expand Up @@ -211,6 +211,7 @@ class FailoverRoute {
}

proxy.stats().increment(failover_all_stat);
proxy.stats().increment(failoverPolicy_.getFailoverStat());

if (rateLimiter_ && !rateLimiter_->failoverAllowed()) {
proxy.stats().increment(failover_rate_limited_stat);
Expand Down Expand Up @@ -263,6 +264,7 @@ class FailoverRoute {
auto failoverReply = doFailover(cur);
if (isErrorResult(failoverReply.result())) {
proxy.stats().increment(failover_all_failed_stat);
proxy.stats().increment(failoverPolicy_.getFailoverFailedStat());
}

return failoverReply;
Expand Down
6 changes: 6 additions & 0 deletions mcrouter/stat_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ STUIR(failover_all, 0, 1)
STUIR(failover_conditional, 0, 1)
STUIR(failover_all_failed, 0, 1)
STUIR(failover_rate_limited, 0, 1)
STUIR(failover_inorder_policy, 0, 1)
STUIR(failover_inorder_policy_failed, 0, 1)
STUIR(failover_least_failures_policy, 0, 1)
STUIR(failover_least_failures_policy_failed, 0, 1)
STUIR(failover_custom_policy, 0, 1)
STUIR(failover_custom_policy_failed, 0, 1)
#undef GROUP
#define GROUP ods_stats | count_stats
STUI(result_error_count, 0, 1)
Expand Down

0 comments on commit 7cafcdb

Please sign in to comment.