forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: split thread_local_object.h and overload_manager.h (envoyprox…
…y#13999) Move the interfaces declared in these files into separate files to allow the Dispatcher to reference the ThreadLocalOverloadState without creating circular dependencies. Signed-off-by: Alex Konradi <[email protected]>
- Loading branch information
Showing
30 changed files
with
169 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "overload_manager_interface", | ||
hdrs = ["overload_manager.h"], | ||
deps = [ | ||
":thread_local_overload_state", | ||
"//include/envoy/event:dispatcher_interface", | ||
"//include/envoy/thread_local:thread_local_interface", | ||
"//source/common/singleton:const_singleton", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "thread_local_overload_state", | ||
hdrs = ["thread_local_overload_state.h"], | ||
deps = [ | ||
"//include/envoy/event:timer_interface", | ||
"//include/envoy/thread_local:thread_local_object", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
include/envoy/server/overload/thread_local_overload_state.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
#include "envoy/common/pure.h" | ||
#include "envoy/event/timer.h" | ||
#include "envoy/thread_local/thread_local_object.h" | ||
|
||
namespace Envoy { | ||
namespace Server { | ||
|
||
/** | ||
* Tracks the state of an overload action. The state is a number between 0 and 1 that represents the | ||
* level of saturation. The values are categorized in two groups: | ||
* - Saturated (value = 1): indicates that an overload action is active because at least one of its | ||
* triggers has reached saturation. | ||
* - Scaling (0 <= value < 1): indicates that an overload action is not saturated. | ||
*/ | ||
class OverloadActionState { | ||
public: | ||
static constexpr OverloadActionState inactive() { return OverloadActionState(0); } | ||
|
||
static constexpr OverloadActionState saturated() { return OverloadActionState(1.0); } | ||
|
||
explicit constexpr OverloadActionState(float value) | ||
: action_value_(std::min(1.0f, std::max(0.0f, value))) {} | ||
|
||
float value() const { return action_value_; } | ||
bool isSaturated() const { return action_value_ == 1; } | ||
|
||
private: | ||
float action_value_; | ||
}; | ||
|
||
/** | ||
* Callback invoked when an overload action changes state. | ||
*/ | ||
using OverloadActionCb = std::function<void(OverloadActionState)>; | ||
|
||
enum class OverloadTimerType { | ||
// Timers created with this type will never be scaled. This should only be used for testing. | ||
UnscaledRealTimerForTest, | ||
// The amount of time an HTTP connection to a downstream client can remain idle (no streams). This | ||
// corresponds to the HTTP_DOWNSTREAM_CONNECTION_IDLE TimerType in overload.proto. | ||
HttpDownstreamIdleConnectionTimeout, | ||
}; | ||
|
||
/** | ||
* Thread-local copy of the state of each configured overload action. | ||
*/ | ||
class ThreadLocalOverloadState : public ThreadLocal::ThreadLocalObject { | ||
public: | ||
// Get a thread-local reference to the value for the given action key. | ||
virtual const OverloadActionState& getState(const std::string& action) PURE; | ||
|
||
// Get a scaled timer whose minimum corresponds to the configured value for the given timer type. | ||
virtual Event::TimerPtr createScaledTimer(OverloadTimerType timer_type, | ||
Event::TimerCb callback) PURE; | ||
}; | ||
|
||
} // namespace Server | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <functional> | ||
#include <memory> | ||
|
||
#include "common/common/assert.h" | ||
|
||
namespace Envoy { | ||
namespace ThreadLocal { | ||
|
||
/** | ||
* All objects that are stored via the ThreadLocal interface must derive from this type. | ||
*/ | ||
class ThreadLocalObject { | ||
public: | ||
virtual ~ThreadLocalObject() = default; | ||
|
||
/** | ||
* Return the object casted to a concrete type. See getTyped() below for comments on the casts. | ||
*/ | ||
template <class T> T& asType() { | ||
ASSERT(dynamic_cast<T*>(this) != nullptr); | ||
return *static_cast<T*>(this); | ||
} | ||
}; | ||
|
||
using ThreadLocalObjectSharedPtr = std::shared_ptr<ThreadLocalObject>; | ||
|
||
template <class T = ThreadLocalObject> class TypedSlot; | ||
|
||
} // namespace ThreadLocal | ||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.