-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
overload: scale transport socket connect timeout #13800
Changes from 2 commits
abcdb84
f5b8d56
7d28234
5d0d600
76cd8c4
2f169bf
0c1cf92
3376062
927ea02
68e62d4
9d85d8a
29ea543
f52c76e
a5ccd82
18f6022
4ca4b11
ee93040
ddad3e5
9be6e8f
475253b
2f2ed9f
6ad33cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -3,64 +3,13 @@ | |||
#include <string> | ||||
|
||||
#include "envoy/common/pure.h" | ||||
#include "envoy/event/timer.h" | ||||
#include "envoy/thread_local/thread_local.h" | ||||
#include "envoy/event/dispatcher.h" | ||||
#include "envoy/server/overload/thread_local_overload_state.h" | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The refactor to add a directory for overload manager components in the server subdirectory and thread_local_object.h adds a lot of noise to this review. Worth doing it as a separate change instead? Also see comments about forward declaring instead. Example: envoy/include/envoy/network/connection.h Line 19 in db756af
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to do the refactor in a separate PR. I don't have strong opinions about forward declarations vs |
||||
|
||||
#include "common/common/macros.h" | ||||
#include "common/singleton/const_singleton.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; | ||||
}; | ||||
|
||||
/** | ||||
* Well-known overload action names. | ||||
*/ | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
#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, | ||
// The amount of time a connection to a downstream client can spend waiting for the transport to | ||
// report connection establishment before the connection is closed. | ||
// This corresponds to the TRANSPORT_SOCKET_CONNECT_TIMEOUT TimerType in overload.proto. | ||
TransportSocketConnectTimeout, | ||
}; | ||
|
||
/** | ||
* 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,13 @@ | |
|
||
#include "envoy/common/pure.h" | ||
#include "envoy/event/dispatcher.h" | ||
#include "envoy/thread_local/thread_local_object.h" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the dispatcher could be forward declared and dispatcher interface library depedency removed as a dependency if that would make some of these changes easier. |
||
#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>; | ||
|
||
/** | ||
* An individual allocated TLS slot. When the slot is destroyed the stored thread local will | ||
* be freed on each thread. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This line seem very long. Can you rerun format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed manually since the formatter doesn't seem to touch proto comments.