Skip to content

Commit

Permalink
Cluster output circuit breaker (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
junr03 authored Oct 12, 2016
1 parent 1ed2eba commit 6b4ac35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 19 additions & 2 deletions source/server/http/admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,27 @@ bool AdminImpl::changeLogLevel(const Http::Utility::QueryParams& params) {
return true;
}

void AdminImpl::addCircuitSettings(const std::string& cluster_name, const std::string& priority_str,
Upstream::ResourceManager& resource_manager,
Buffer::Instance& response) {
response.add(fmt::format("{}::{}_priority::max_connections::{}\n", cluster_name, priority_str,
resource_manager.connections().max()));
response.add(fmt::format("{}::{}_priority::max_pending_requests::{}\n", cluster_name,
priority_str, resource_manager.pendingRequests().max()));
response.add(fmt::format("{}::{}_priority::max_requests::{}\n", cluster_name, priority_str,
resource_manager.requests().max()));
response.add(fmt::format("{}::{}_priority::max_retries::{}\n", cluster_name, priority_str,
resource_manager.retries().max()));
}

Http::Code AdminImpl::handlerClusters(const std::string&, Buffer::Instance& response) {
for (auto& cluster : server_.clusterManager().clusters()) {
response.add(fmt::format("=== {} ===\n", cluster.second->name()));
addCircuitSettings(cluster.second->name(), "default",
cluster.second->resourceManager(Upstream::ResourcePriority::Default),
response);
addCircuitSettings(cluster.second->name(), "high",
cluster.second->resourceManager(Upstream::ResourcePriority::High), response);

for (auto& host : cluster.second->hosts()) {
std::map<std::string, uint64_t> all_stats;
for (Stats::Counter& counter : host->counters()) {
Expand All @@ -126,7 +144,6 @@ Http::Code AdminImpl::handlerClusters(const std::string&, Buffer::Instance& resp
fmt::format("{}::{}::zone::{}\n", cluster.second->name(), host->url(), host->zone()));
response.add(
fmt::format("{}::{}::canary::{}\n", cluster.second->name(), host->url(), host->canary()));
response.add("\n");
}
}

Expand Down
5 changes: 4 additions & 1 deletion source/server/http/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "envoy/http/filter.h"
#include "envoy/network/listen_socket.h"
#include "envoy/server/admin.h"
#include "envoy/upstream/resource_manager.h"

#include "common/common/logger.h"
#include "common/http/conn_manager_impl.h"
Expand Down Expand Up @@ -72,6 +73,8 @@ class AdminImpl : public Admin,
* @return TRUE if level change succeeded, FALSE otherwise.
*/
bool changeLogLevel(const Http::Utility::QueryParams& params);
void addCircuitSettings(const std::string& cluster_name, const std::string& priority_str,
Upstream::ResourceManager& resource_manager, Buffer::Instance& response);

/**
* URL handlers.
Expand Down Expand Up @@ -99,7 +102,7 @@ class AdminImpl : public Admin,
};

/**
* A terminal HTTP filter that implements server admin functioanlity.
* A terminal HTTP filter that implements server admin functionality.
*/
class AdminFilter : public Http::StreamDecoderFilter, Logger::Loggable<Logger::Id::admin> {
public:
Expand Down

0 comments on commit 6b4ac35

Please sign in to comment.