-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
null_overload_manager.h
73 lines (61 loc) · 2.59 KB
/
null_overload_manager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "envoy/server/overload/overload_manager.h"
#include "envoy/thread_local/thread_local.h"
#include "source/common/event/scaled_range_timer_manager_impl.h"
namespace Envoy {
namespace Server {
/** Implementation of OverloadManager that is never overloaded. Using this instead of the real
* OverloadManager keeps the admin interface accessible even when the proxy is overloaded.
*/
class NullOverloadManager : public OverloadManager {
public:
struct OverloadState : public ThreadLocalOverloadState {
OverloadState(Event::Dispatcher& dispatcher, bool permissive)
: dispatcher_(dispatcher), permissive_(permissive) {}
const OverloadActionState& getState(const std::string&) override { return inactive_; }
bool tryAllocateResource(OverloadProactiveResourceName, int64_t) override {
return permissive_;
}
bool tryDeallocateResource(OverloadProactiveResourceName, int64_t) override {
return permissive_;
}
bool isResourceMonitorEnabled(OverloadProactiveResourceName) override { return false; }
ProactiveResourceMonitorOptRef
getProactiveResourceMonitorForTest(OverloadProactiveResourceName) override {
return makeOptRefFromPtr<ProactiveResourceMonitor>(nullptr);
}
Event::Dispatcher& dispatcher_;
const bool permissive_;
const OverloadActionState inactive_ = OverloadActionState::inactive();
};
NullOverloadManager(ThreadLocal::SlotAllocator& slot_allocator, bool permissive)
: tls_(slot_allocator.allocateSlot()), permissive_(permissive) {}
void start() override {
tls_->set([this](Event::Dispatcher& dispatcher) -> ThreadLocal::ThreadLocalObjectSharedPtr {
return std::make_shared<OverloadState>(dispatcher, permissive_);
});
}
ThreadLocalOverloadState& getThreadLocalOverloadState() override {
return tls_->getTyped<OverloadState>();
}
LoadShedPoint* getLoadShedPoint(absl::string_view) override { return nullptr; }
Event::ScaledRangeTimerManagerFactory scaledTimerFactory() override {
if (!permissive_) {
return nullptr;
}
return [](Event::Dispatcher& dispatcher) {
return std::make_unique<Event::ScaledRangeTimerManagerImpl>(dispatcher, nullptr);
};
}
bool registerForAction(const std::string&, Event::Dispatcher&, OverloadActionCb) override {
return true;
}
void stop() override {}
ThreadLocal::SlotPtr tls_;
// The admin code runs in non-permissive mode, rejecting connections and
// ensuring timer code is not called. Envoy mobile uses permissive mode and
// does the opposite.
const bool permissive_;
};
} // namespace Server
} // namespace Envoy