-
Notifications
You must be signed in to change notification settings - Fork 5.3k
outlier ejection: implement consecutive 5xx ejection #261
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,21 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| /** | ||
| * Less typing for common system time type. | ||
| */ | ||
| typedef std::chrono::time_point<std::chrono::system_clock> SystemTime; | ||
|
|
||
| /** | ||
| * Abstraction for getting the current system time. Useful for testing. | ||
| */ | ||
| class SystemTimeSource { | ||
| public: | ||
| virtual ~SystemTimeSource() {} | ||
|
|
||
| /** | ||
| * @return the current system time. | ||
| */ | ||
| virtual SystemTime currentSystemTime() PURE; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/time.h" | ||
| #include "envoy/event/timer.h" | ||
| #include "envoy/runtime/runtime.h" | ||
| #include "envoy/upstream/outlier_detection.h" | ||
| #include "envoy/upstream/upstream.h" | ||
|
|
||
|
|
@@ -23,17 +26,52 @@ class OutlierDetectorHostSinkNullImpl : public OutlierDetectorHostSink { | |
| class OutlierDetectorImplFactory { | ||
| public: | ||
| static OutlierDetectorPtr createForCluster(Cluster& cluster, const Json::Object& cluster_config, | ||
| Event::Dispatcher& dispatcher); | ||
| Event::Dispatcher& dispatcher, | ||
| Runtime::Loader& runtime, Stats::Store& stats); | ||
| }; | ||
|
|
||
| class OutlierDetectorImpl; | ||
|
|
||
| /** | ||
| * Implementation of OutlierDetectorHostSink for the generic detector. | ||
| */ | ||
| class OutlierDetectorHostSinkImpl : public OutlierDetectorHostSink { | ||
| public: | ||
| OutlierDetectorHostSinkImpl(OutlierDetectorImpl& detector, HostPtr host) | ||
| : detector_(detector), host_(host) {} | ||
|
|
||
| void eject(SystemTime ejection_time); | ||
| SystemTime ejectionTime() { return ejection_time_; } | ||
| uint32_t numEjections() { return num_ejections_; } | ||
|
|
||
| // Upstream::OutlierDetectorHostSink | ||
| void putHttpResponseCode(uint64_t) override {} | ||
| void putHttpResponseCode(uint64_t response_code) override; | ||
| void putResponseTime(std::chrono::milliseconds) override {} | ||
|
|
||
| private: | ||
| OutlierDetectorImpl& detector_; | ||
| std::weak_ptr<Host> host_; | ||
| std::atomic<uint32_t> consecutive_5xx_{0}; | ||
| SystemTime ejection_time_; | ||
| uint32_t num_ejections_{}; | ||
| }; | ||
|
|
||
| /** | ||
| * All outlier detection stats. @see stats_macros.h | ||
| */ | ||
| // clang-format off | ||
| #define ALL_OUTLIER_DETECTION_STATS(COUNTER, GAUGE) \ | ||
| COUNTER(ejections_total) \ | ||
| GAUGE (ejections_active) \ | ||
| COUNTER(ejections_overflow) \ | ||
| COUNTER(ejections_consecutive_5xx) | ||
| // clang-format on | ||
|
|
||
| /** | ||
| * Struct definition for all outlier detection stats. @see stats_macros.h | ||
| */ | ||
| struct OutlierDetectionStats { | ||
| ALL_OUTLIER_DETECTION_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT) | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -43,16 +81,43 @@ class OutlierDetectorHostSinkImpl : public OutlierDetectorHostSink { | |
| */ | ||
| class OutlierDetectorImpl : public OutlierDetector { | ||
| public: | ||
| OutlierDetectorImpl(Cluster& cluster, Event::Dispatcher& dispatcher); | ||
| void onConsecutive5xx(HostPtr host); | ||
| Runtime::Loader& runtime() { return runtime_; } | ||
|
|
||
| // Upstream::OutlierDetector | ||
| void addChangedStateCb(ChangeStateCb cb) override { callbacks_.push_back(cb); } | ||
|
|
||
| protected: | ||
| OutlierDetectorImpl(Cluster& cluster, Event::Dispatcher& dispatcher, Runtime::Loader& runtime, | ||
| Stats::Store& stats, SystemTimeSource& time_source); | ||
|
|
||
| private: | ||
| void addHostSink(HostPtr host); | ||
| void armIntervalTimer(); | ||
|
Member
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. nit: call that in a way to easy get that this is associated with host unejection
Member
Author
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 named it like this because eventually it will be used for histogram computation, not just unejection. |
||
| void checkHostForUneject(HostPtr host, OutlierDetectorHostSinkImpl* sink, SystemTime now); | ||
| void ejectHost(HostPtr host); | ||
| static OutlierDetectionStats generateStats(const std::string& name, Stats::Store& store); | ||
| void onConsecutive5xxWorker(HostPtr host); | ||
| void onIntervalTimer(); | ||
| void runCallbacks(HostPtr host); | ||
|
|
||
| Event::Dispatcher& dispatcher_; | ||
| Runtime::Loader& runtime_; | ||
| SystemTimeSource& time_source_; | ||
| OutlierDetectionStats stats_; | ||
| Event::TimerPtr interval_timer_; | ||
|
Member
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. nit: uneject_timer_ may be
Member
Author
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 named it like this because eventually it will be used for histogram computation, not just unejection. |
||
| std::list<ChangeStateCb> callbacks_; | ||
| std::unordered_map<HostPtr, OutlierDetectorHostSinkImpl*> host_sinks_; | ||
| }; | ||
|
|
||
| class ProdOutlierDetectorImpl : public OutlierDetectorImpl, public SystemTimeSource { | ||
| public: | ||
| ProdOutlierDetectorImpl(Cluster& cluster, Event::Dispatcher& dispatcher, Runtime::Loader& runtime, | ||
| Stats::Store& stats) | ||
| : OutlierDetectorImpl(cluster, dispatcher, runtime, stats, *this) {} | ||
|
|
||
| // SystemTimeSource | ||
| SystemTime currentSystemTime() override { return std::chrono::system_clock::now(); } | ||
| }; | ||
|
|
||
| } // Upstream | ||
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.
create jira on docs for outlier detection and runtime params?
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.
https://lyftme.atlassian.net/browse/NETWORK-678