diff --git a/api/envoy/data/core/v3/health_check_event.proto b/api/envoy/data/core/v3/health_check_event.proto index 2f8c32d92caf8..cd1c1a107d237 100644 --- a/api/envoy/data/core/v3/health_check_event.proto +++ b/api/envoy/data/core/v3/health_check_event.proto @@ -87,6 +87,12 @@ message HealthCheckEjectUnhealthy { // The type of failure that caused this ejection. HealthCheckFailureType failure_type = 1 [(validate.rules).enum = {defined_only: true}]; + + // The HTTP status code of the health check response that triggered the ejection. + // Only set when the health checker type is HTTP and the failure type is ACTIVE. + // A value of 0 indicates that no HTTP status code was recorded (e.g., network-level failures + // or non-HTTP health checkers). + uint32 http_status_code = 2; } message HealthCheckAddHealthy { @@ -111,6 +117,12 @@ message HealthCheckFailure { // Whether this event is the result of the first ever health check on a host. bool first_check = 2; + + // The HTTP status code of the health check response that caused this failure. + // Only set when the health checker type is HTTP and the failure type is ACTIVE. + // A value of 0 indicates that no HTTP status code was recorded (e.g., network-level failures + // or non-HTTP health checkers). + uint32 http_status_code = 3; } message DegradedHealthyHost { diff --git a/changelogs/current.yaml b/changelogs/current.yaml index 4ac0fb323d467..1437d89da4c9b 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -344,6 +344,14 @@ removed_config_or_runtime: and legacy code path. new_features: +- area: health_check + change: | + Added ``http_status_code`` field to :ref:`HealthCheckEjectUnhealthy + ` and :ref:`HealthCheckFailure + ` proto messages. When the health checker + type is HTTP and the failure type is ``ACTIVE``, the field is populated with the HTTP response + status code that caused the failure. For non-HTTP health checkers and network-level failures, + the field defaults to ``0``. Fixes :issue:`40221`. - area: ratelimit change: | Added ``is_negative_hits`` boolean to the ``hits_addend`` diff --git a/envoy/upstream/health_checker.h b/envoy/upstream/health_checker.h index ed6db4abe84a2..5cb4f354fba5c 100644 --- a/envoy/upstream/health_checker.h +++ b/envoy/upstream/health_checker.h @@ -74,10 +74,13 @@ class HealthCheckEventLogger { * @param health_checker_type supplies the type of health checker that generated the event. * @param host supplies the host that generated the event. * @param failure_type supplies the type of health check failure. + * @param http_status_code the HTTP status code of the response that triggered the ejection, + * or 0 if not applicable (e.g., non-HTTP checkers or network-level failures). */ virtual void logEjectUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, - envoy::data::core::v3::HealthCheckFailureType failure_type) PURE; + envoy::data::core::v3::HealthCheckFailureType failure_type, + uint64_t http_status_code) PURE; /** * Log an unhealthy host event. @@ -85,11 +88,13 @@ class HealthCheckEventLogger { * @param host supplies the host that generated the event. * @param failure_type supplies the type of health check failure. * @param first_check whether this is a failure on the first health check for this host. + * @param http_status_code the HTTP status code of the response that caused this failure, + * or 0 if not applicable (e.g., non-HTTP checkers or network-level failures). */ virtual void logUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, envoy::data::core::v3::HealthCheckFailureType failure_type, - bool first_check) PURE; + bool first_check, uint64_t http_status_code) PURE; /** * Log a healthy host addition event. diff --git a/source/common/upstream/health_checker_event_logger.cc b/source/common/upstream/health_checker_event_logger.cc index b6218cb0c07c0..a4834d5c1e9fb 100644 --- a/source/common/upstream/health_checker_event_logger.cc +++ b/source/common/upstream/health_checker_event_logger.cc @@ -13,20 +13,31 @@ namespace Upstream { void HealthCheckEventLoggerImpl::logEjectUnhealthy( envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, - envoy::data::core::v3::HealthCheckFailureType failure_type) { - createHealthCheckEvent(health_checker_type, *host, [&failure_type](auto& event) { - event.mutable_eject_unhealthy_event()->set_failure_type(failure_type); - }); + envoy::data::core::v3::HealthCheckFailureType failure_type, uint64_t http_status_code) { + createHealthCheckEvent(health_checker_type, *host, + [&failure_type, http_status_code](auto& event) { + event.mutable_eject_unhealthy_event()->set_failure_type(failure_type); + if (http_status_code != 0) { + event.mutable_eject_unhealthy_event()->set_http_status_code( + static_cast(http_status_code)); + } + }); } void HealthCheckEventLoggerImpl::logUnhealthy( envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, - envoy::data::core::v3::HealthCheckFailureType failure_type, bool first_check) { - createHealthCheckEvent(health_checker_type, *host, [&first_check, &failure_type](auto& event) { - event.mutable_health_check_failure_event()->set_failure_type(failure_type); - event.mutable_health_check_failure_event()->set_first_check(first_check); - }); + envoy::data::core::v3::HealthCheckFailureType failure_type, bool first_check, + uint64_t http_status_code) { + createHealthCheckEvent( + health_checker_type, *host, [&first_check, &failure_type, http_status_code](auto& event) { + event.mutable_health_check_failure_event()->set_failure_type(failure_type); + event.mutable_health_check_failure_event()->set_first_check(first_check); + if (http_status_code != 0) { + event.mutable_health_check_failure_event()->set_http_status_code( + static_cast(http_status_code)); + } + }); } void HealthCheckEventLoggerImpl::logAddHealthy( diff --git a/source/common/upstream/health_checker_event_logger.h b/source/common/upstream/health_checker_event_logger.h index 3fa6f52139649..1e7f00d81b37b 100644 --- a/source/common/upstream/health_checker_event_logger.h +++ b/source/common/upstream/health_checker_event_logger.h @@ -42,15 +42,16 @@ class HealthCheckEventLoggerImpl : public HealthCheckEventLogger { void logEjectUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, - envoy::data::core::v3::HealthCheckFailureType failure_type) override; + envoy::data::core::v3::HealthCheckFailureType failure_type, + uint64_t http_status_code) override; void logAddHealthy(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, bool first_check) override; void logSuccessfulHealthCheck(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host) override; void logUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host, - envoy::data::core::v3::HealthCheckFailureType failure_type, - bool first_check) override; + envoy::data::core::v3::HealthCheckFailureType failure_type, bool first_check, + uint64_t http_status_code) override; void logDegraded(envoy::data::core::v3::HealthCheckerType health_checker_type, const HostDescriptionConstSharedPtr& host) override; void logNoLongerDegraded(envoy::data::core::v3::HealthCheckerType health_checker_type, diff --git a/source/extensions/health_checkers/common/health_checker_base_impl.cc b/source/extensions/health_checkers/common/health_checker_base_impl.cc index ff3534422998a..df3b950b7a31d 100644 --- a/source/extensions/health_checkers/common/health_checker_base_impl.cc +++ b/source/extensions/health_checkers/common/health_checker_base_impl.cc @@ -367,7 +367,7 @@ bool networkHealthCheckFailureType(envoy::data::core::v3::HealthCheckFailureType } // namespace HealthTransition HealthCheckerImplBase::ActiveHealthCheckSession::setUnhealthy( - envoy::data::core::v3::HealthCheckFailureType type, bool retriable) { + envoy::data::core::v3::HealthCheckFailureType type, bool retriable, uint64_t http_status_code) { // If we are unhealthy, reset the # of healthy to zero. num_healthy_ = 0; @@ -379,7 +379,8 @@ HealthTransition HealthCheckerImplBase::ActiveHealthCheckSession::setUnhealthy( parent_.decHealthy(); changed_state = HealthTransition::Changed; if (parent_.event_logger_) { - parent_.event_logger_->logEjectUnhealthy(parent_.healthCheckerType(), host_, type); + parent_.event_logger_->logEjectUnhealthy(parent_.healthCheckerType(), host_, type, + http_status_code); } } else { changed_state = HealthTransition::ChangePending; @@ -399,7 +400,8 @@ HealthTransition HealthCheckerImplBase::ActiveHealthCheckSession::setUnhealthy( changed_state = clearPendingFlag(changed_state); if ((first_check_ || parent_.always_log_health_check_failures_) && parent_.event_logger_) { - parent_.event_logger_->logUnhealthy(parent_.healthCheckerType(), host_, type, first_check_); + parent_.event_logger_->logUnhealthy(parent_.healthCheckerType(), host_, type, first_check_, + http_status_code); } parent_.stats_.failure_.inc(); @@ -415,8 +417,8 @@ HealthTransition HealthCheckerImplBase::ActiveHealthCheckSession::setUnhealthy( } void HealthCheckerImplBase::ActiveHealthCheckSession::handleFailure( - envoy::data::core::v3::HealthCheckFailureType type, bool retriable) { - HealthTransition changed_state = setUnhealthy(type, retriable); + envoy::data::core::v3::HealthCheckFailureType type, bool retriable, uint64_t http_status_code) { + HealthTransition changed_state = setUnhealthy(type, retriable, http_status_code); // It's possible that the previous call caused this session to be deferred deleted. if (timeout_timer_ != nullptr) { timeout_timer_->disableTimer(); diff --git a/source/extensions/health_checkers/common/health_checker_base_impl.h b/source/extensions/health_checkers/common/health_checker_base_impl.h index 118bd25684010..3fc25bb7181b3 100644 --- a/source/extensions/health_checkers/common/health_checker_base_impl.h +++ b/source/extensions/health_checkers/common/health_checker_base_impl.h @@ -60,7 +60,7 @@ class HealthCheckerImplBase : public HealthChecker, public: ~ActiveHealthCheckSession() override; HealthTransition setUnhealthy(envoy::data::core::v3::HealthCheckFailureType type, - bool retriable); + bool retriable, uint64_t http_status_code = 0); void onDeferredDeleteBase(); void start() { onInitialInterval(); } @@ -68,7 +68,8 @@ class HealthCheckerImplBase : public HealthChecker, ActiveHealthCheckSession(HealthCheckerImplBase& parent, HostSharedPtr host); void handleSuccess(bool degraded = false); - void handleFailure(envoy::data::core::v3::HealthCheckFailureType type, bool retriable = false); + void handleFailure(envoy::data::core::v3::HealthCheckFailureType type, bool retriable = false, + uint64_t http_status_code = 0); HostSharedPtr host_; diff --git a/source/extensions/health_checkers/http/health_checker_impl.cc b/source/extensions/health_checkers/http/health_checker_impl.cc index 8d6c8a281aecd..1c7452a7ef0bc 100644 --- a/source/extensions/health_checkers/http/health_checker_impl.cc +++ b/source/extensions/health_checkers/http/health_checker_impl.cc @@ -419,9 +419,13 @@ HttpHealthCheckerImpl::HttpActiveHealthCheckSession::healthCheckResult() { void HttpHealthCheckerImpl::HttpActiveHealthCheckSession::onResponseComplete() { request_in_flight_ = false; + // Extract the HTTP response code for inclusion in health check events. + const uint64_t response_code = + response_headers_ != nullptr ? Http::Utility::getResponseStatus(*response_headers_) : 0; + // Store the raw HTTP response code on the host for HDS metadata reporting. if (response_headers_ != nullptr) { - host_->setLastHealthCheckHttpStatus(Http::Utility::getResponseStatus(*response_headers_)); + host_->setLastHealthCheckHttpStatus(response_code); } switch (healthCheckResult()) { @@ -432,10 +436,12 @@ void HttpHealthCheckerImpl::HttpActiveHealthCheckSession::onResponseComplete() { handleSuccess(true); break; case HealthCheckResult::Failed: - handleFailure(envoy::data::core::v3::ACTIVE, /*retriable=*/false); + handleFailure(envoy::data::core::v3::ACTIVE, /*retriable=*/false, + /*http_status_code=*/response_code); break; case HealthCheckResult::Retriable: - handleFailure(envoy::data::core::v3::ACTIVE, /*retriable=*/true); + handleFailure(envoy::data::core::v3::ACTIVE, /*retriable=*/true, + /*http_status_code=*/response_code); break; } diff --git a/test/common/upstream/health_checker_impl_test.cc b/test/common/upstream/health_checker_impl_test.cc index 63aad863e1f90..d1f306a0dd982 100644 --- a/test/common/upstream/health_checker_impl_test.cc +++ b/test/common/upstream/health_checker_impl_test.cc @@ -805,7 +805,7 @@ class HttpHealthCheckerImplTest : public Event::TestUsingSimulatedTime, EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Unchanged)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", false, false, false, false, health_checked_cluster); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( Host::HealthFlag::FAILED_ACTIVE_HC)); @@ -845,9 +845,9 @@ class HttpHealthCheckerImplTest : public Event::TestUsingSimulatedTime, EXPECT_CALL(*test_sessions_[index]->timeout_timer_, disableTimer()); EXPECT_CALL(*test_sessions_[index]->interval_timer_, enableTimer(_, _)); if (first_check) { - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, _, _)); } - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); } void expectHealthyTransition(size_t index) { @@ -929,7 +929,7 @@ TEST_F(HttpHealthCheckerImplTest, LastHealthCheckHttpStatusRecorded) { EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); respond(0, "503", false, false, true); EXPECT_EQ(503U, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->lastHealthCheckHttpStatus()); @@ -1386,8 +1386,8 @@ TEST_F(HttpHealthCheckerImplTest, SuccessExpectedResponseCheckHttp2) { TEST_F(HttpHealthCheckerImplTest, FailExpectedResponseCheck) { setupServiceValidationWithNoBufferSizeHC("Everything OK"); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -1412,8 +1412,8 @@ TEST_F(HttpHealthCheckerImplTest, FailExpectedResponseCheck) { TEST_F(HttpHealthCheckerImplTest, FailStatusCheckWithExpectedResponseCheck) { setupServiceValidationWithNoBufferSizeHC("Everything OK"); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -1437,8 +1437,8 @@ TEST_F(HttpHealthCheckerImplTest, FailStatusCheckWithExpectedResponseCheck) { TEST_F(HttpHealthCheckerImplTest, ImmediateFailExpectedResponseCheck) { setupServiceValidationWithNoBufferSizeHC("Everything OK"); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -1598,7 +1598,7 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckSetsCorrectLastHcPassTime) EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)).Times(2); expectStreamCreate(0); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->interval_timer_->invokeCallback(); @@ -2007,12 +2007,12 @@ TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithoutUserAgent) { TEST_F(HttpHealthCheckerImplTest, ServiceDoesNotMatchFail) { setupServiceValidationHC(); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100)) .WillOnce(Return(true)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -2039,12 +2039,12 @@ TEST_F(HttpHealthCheckerImplTest, ServiceDoesNotMatchFail) { TEST_F(HttpHealthCheckerImplTest, ServicePatternDoesNotMatchFail) { setupServiceRegexPatternValidationHC(); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100)) .WillOnce(Return(true)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -2070,12 +2070,12 @@ TEST_F(HttpHealthCheckerImplTest, ServicePatternDoesNotMatchFail) { TEST_F(HttpHealthCheckerImplTest, ServiceNotPresentInResponseFail) { setupServiceValidationHC(); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100)) .WillOnce(Return(true)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -2250,10 +2250,10 @@ TEST_F(HttpHealthCheckerImplTest, HttpFailRemoveHostInCallbackNoClose) { cluster_->prioritySet().getMockHostSet(0)->hosts_ = {}; cluster_->prioritySet().runUpdateCallbacks(0, {}, {host}); })); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)).Times(0); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()).Times(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", false); } @@ -2272,10 +2272,10 @@ TEST_F(HttpHealthCheckerImplTest, HttpFailRemoveHostInCallbackClose) { cluster_->prioritySet().getMockHostSet(0)->hosts_ = {}; cluster_->prioritySet().runUpdateCallbacks(0, {}, {host}); })); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)).Times(0); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()).Times(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", true); } @@ -2289,10 +2289,10 @@ TEST_F(HttpHealthCheckerImplTest, HttpFail) { health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", false); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( Host::HealthFlag::FAILED_ACTIVE_HC)); @@ -2327,6 +2327,175 @@ TEST_F(HttpHealthCheckerImplTest, HttpFail) { cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); } +TEST_F(HttpHealthCheckerImplTest, HttpStatusCodeInHealthCheckEvents) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 503)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 503)); + respond(0, "503", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCode429) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 429)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 429)); + respond(0, "429", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCode500) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 500)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 500)); + respond(0, "500", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCode502) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 502)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 502)); + respond(0, "502", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCode504) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 504)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 504)); + respond(0, "504", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCode403) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, envoy::data::core::v3::ACTIVE, 403)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::ACTIVE, true, 403)); + respond(0, "403", false); + EXPECT_EQ(Host::Health::Unhealthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + +TEST_F(HttpHealthCheckerImplTest, HttpStatusCodeZeroOnTimeout) { + setupNoServiceValidationHC(); + cluster_->prioritySet().getMockHostSet(0)->hosts_ = { + makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; + cluster_->info_->trafficStats()->upstream_cx_total_.inc(); + expectSessionCreate(); + expectStreamCreate(0); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)); + health_checker_->start(); + + EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending)); + EXPECT_CALL(*test_sessions_[0]->client_connection_, + close(Network::ConnectionCloseType::Abort, _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _)); + EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _)) + .WillOnce(Return(45000)); + EXPECT_CALL(*test_sessions_[0]->interval_timer_, + enableTimer(std::chrono::milliseconds(45000), _)); + EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, envoy::data::core::v3::NETWORK_TIMEOUT, true, 0)); + test_sessions_[0]->timeout_timer_->invokeCallback(); + EXPECT_EQ(Host::Health::Healthy, + cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); +} + TEST_F(HttpHealthCheckerImplTest, ImmediateFailure) { setupNoServiceValidationHC(); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { @@ -2337,10 +2506,10 @@ TEST_F(HttpHealthCheckerImplTest, ImmediateFailure) { health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", false, false, true, false, absl::nullopt, false, true); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( Host::HealthFlag::FAILED_ACTIVE_HC)); @@ -2360,10 +2529,10 @@ TEST_F(HttpHealthCheckerImplTest, HttpFailLogError) { health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respond(0, "503", false); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( Host::HealthFlag::FAILED_ACTIVE_HC)); @@ -2378,7 +2547,7 @@ TEST_F(HttpHealthCheckerImplTest, HttpFailLogError) { EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Unchanged)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, false)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, false, _)); respond(0, "503", false); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( Host::HealthFlag::FAILED_ACTIVE_HC)); @@ -2449,7 +2618,7 @@ TEST_F(HttpHealthCheckerImplTest, HttpAlwaysLogSuccess) { TEST_F(HttpHealthCheckerImplTest, Disconnect) { setupNoServiceValidationHC(); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { @@ -2472,7 +2641,7 @@ TEST_F(HttpHealthCheckerImplTest, Disconnect) { EXPECT_CALL(*this, onHostStatus(cluster_->prioritySet().getMockHostSet(0)->hosts_[0], HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->client_connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); @@ -2496,8 +2665,8 @@ TEST_F(HttpHealthCheckerImplTest, Timeout) { close(Network::ConnectionCloseType::Abort, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); test_sessions_[0]->timeout_timer_->invokeCallback(); EXPECT_EQ(Host::Health::Unhealthy, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->coarseHealth()); @@ -2522,7 +2691,7 @@ TEST_F(HttpHealthCheckerImplTest, TimeoutThenSuccess) { test_sessions_[0]->stream_response_callbacks_->decodeHeaders(std::move(response_headers), false); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::ChangePending)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*test_sessions_[0]->client_connection_, close(Network::ConnectionCloseType::Abort, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); @@ -2546,7 +2715,7 @@ TEST_F(HttpHealthCheckerImplTest, TimeoutThenSuccess) { TEST_F(HttpHealthCheckerImplTest, TimeoutThenRemoteClose) { setupNoServiceValidationHC(); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; expectSessionCreate(); @@ -2569,7 +2738,7 @@ TEST_F(HttpHealthCheckerImplTest, TimeoutThenRemoteClose) { test_sessions_[0]->interval_timer_->invokeCallback(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(_, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->client_connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); @@ -2587,7 +2756,7 @@ TEST_F(HttpHealthCheckerImplTest, TimeoutAfterDisconnect) { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; expectSessionCreate(); expectStreamCreate(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _)).Times(2); health_checker_->start(); @@ -2599,7 +2768,7 @@ TEST_F(HttpHealthCheckerImplTest, TimeoutAfterDisconnect) { } EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->timeout_timer_->enableTimer(std::chrono::seconds(10), nullptr); @@ -2770,7 +2939,7 @@ TEST_F(HttpHealthCheckerImplTest, HealthCheckIntervals) { // ignored and health state changes immediately. Since the threshold is ignored, next health // check respects "unhealthy_interval". EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(std::chrono::milliseconds(2000), _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); respond(0, "503", false); @@ -2882,7 +3051,7 @@ TEST_F(HttpHealthCheckerImplTest, HealthCheckIntervals) { // Subsequent failing checks should respect unhealthy_interval. As the unhealthy threshold is // reached, health state should also change. EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(std::chrono::milliseconds(2000), _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->timeout_timer_->invokeCallback(); @@ -3713,12 +3882,12 @@ TEST_F(HttpHealthCheckerImplTest, ServiceNameMatch) { TEST_F(HttpHealthCheckerImplTest, ServiceNameMismatch) { setupServiceNameValidationHC("locations"); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100)) .WillOnce(Return(true)); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); cluster_->prioritySet().getMockHostSet(0)->hosts_ = { makeTestHost(cluster_->info_, "tcp://127.0.0.1:80")}; @@ -4485,7 +4654,7 @@ TEST_F(TcpHealthCheckerImplTest, TimeoutThenRemoteClose) { read_filter_->onData(response, false); EXPECT_CALL(*connection_, close(Network::ConnectionCloseType::Abort)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); timeout_timer_->invokeCallback(); @@ -4499,7 +4668,7 @@ TEST_F(TcpHealthCheckerImplTest, TimeoutThenRemoteClose) { connection_->raiseEvent(Network::ConnectionEvent::Connected); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); @@ -4544,8 +4713,8 @@ TEST_F(TcpHealthCheckerImplTest, Timeout) { read_filter_->onData(response, false); EXPECT_CALL(*connection_, close(Network::ConnectionCloseType::Abort)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); timeout_timer_->invokeCallback(); @@ -4578,7 +4747,7 @@ TEST_F(TcpHealthCheckerImplTest, DoubleTimeout) { read_filter_->onData(response, false); EXPECT_CALL(*connection_, close(Network::ConnectionCloseType::Abort)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); timeout_timer_->invokeCallback(); @@ -4595,7 +4764,7 @@ TEST_F(TcpHealthCheckerImplTest, DoubleTimeout) { connection_->raiseEvent(Network::ConnectionEvent::Connected); EXPECT_CALL(*connection_, close(Network::ConnectionCloseType::Abort)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); timeout_timer_->invokeCallback(); @@ -4675,7 +4844,7 @@ TEST_F(TcpHealthCheckerImplTest, TimeoutWithoutReusingConnection) { connection_->raiseEvent(Network::ConnectionEvent::Connected); // Expected flow when a healthcheck times out. - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); @@ -4722,8 +4891,8 @@ TEST_F(TcpHealthCheckerImplTest, PassiveFailure) { expectClientCreate(); EXPECT_CALL(*connection_, write(_, _)).Times(0); EXPECT_CALL(*timeout_timer_, enableTimer(_, _)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); // Do multiple passive failures. This will not reset the active HC timers. @@ -4849,7 +5018,7 @@ TEST_F(TcpHealthCheckerImplTest, ConnectionLocalFailure) { health_checker_->start(); // Expect the LocalClose to be handled as a health check failure - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); @@ -5610,7 +5779,7 @@ TEST_F(GrpcHealthCheckerImplTest, SuccessStartFailedFailFirst) { // Host was unhealthy from the start, but we expect a state change due to the pending active hc // flag changing. EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::NOT_SERVING); expectHostHealthy(false); EXPECT_FALSE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( @@ -5647,7 +5816,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaRpcRemoveHostInCallback) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)) @@ -5655,7 +5824,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaRpcRemoveHostInCallback) { cluster_->prioritySet().getMockHostSet(0)->hosts_ = {}; cluster_->prioritySet().runUpdateCallbacks(0, {}, {host}); })); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::NOT_SERVING); } @@ -5668,7 +5837,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaGoawayRemoveHostInCallback) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)) @@ -5676,7 +5845,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaGoawayRemoveHostInCallback) { cluster_->prioritySet().getMockHostSet(0)->hosts_ = {}; cluster_->prioritySet().runUpdateCallbacks(0, {}, {host}); })); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::Other); } @@ -5688,7 +5857,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaBadResponseRemoveHostInCallba expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)) @@ -5696,7 +5865,7 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFailViaBadResponseRemoveHostInCallba cluster_->prioritySet().getMockHostSet(0)->hosts_ = {}; cluster_->prioritySet().runUpdateCallbacks(0, {}, {host}); })); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); std::unique_ptr response_headers( new Http::TestResponseHeaderMapImpl{{":status", "500"}}); test_sessions_[0]->stream_response_callbacks_->decodeHeaders(std::move(response_headers), false); @@ -5710,13 +5879,13 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcHealthFail) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); // Explicit healthcheck failure immediately renders host unhealthy. expectHealthcheckStop(0); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::NOT_SERVING); expectHostHealthy(false); @@ -5749,7 +5918,7 @@ TEST_F(GrpcHealthCheckerImplTest, Disconnect) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); @@ -5765,7 +5934,7 @@ TEST_F(GrpcHealthCheckerImplTest, Disconnect) { expectHealthcheckStop(0); // Now, host should be unhealthy. EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); test_sessions_[0]->client_connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); expectHostHealthy(false); } @@ -5777,13 +5946,13 @@ TEST_F(GrpcHealthCheckerImplTest, Timeout) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); // Unhealthy threshold is 1 so first timeout causes unhealthy EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); test_sessions_[0]->timeout_timer_->invokeCallback(); expectHostHealthy(false); } @@ -5796,7 +5965,7 @@ TEST_F(GrpcHealthCheckerImplTest, DoubleTimeout) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); @@ -5810,7 +5979,7 @@ TEST_F(GrpcHealthCheckerImplTest, DoubleTimeout) { expectHealthcheckStop(0); EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); // Close connection. Timeouts and connection closes counts together. test_sessions_[0]->client_connection_->raiseEvent(Network::ConnectionEvent::RemoteClose); expectHostHealthy(false); @@ -5884,7 +6053,7 @@ TEST_F(GrpcHealthCheckerImplTest, HealthCheckIntervals) { // ignored and health state changes immediately. Since the threshold is ignored, next health // check respects "unhealthy_interval". EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(std::chrono::milliseconds(2000), _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::NOT_SERVING); @@ -5988,7 +6157,7 @@ TEST_F(GrpcHealthCheckerImplTest, HealthCheckIntervals) { // Subsequent failing checks should respect unhealthy_interval. As the unhealthy threshold is // reached, health state should also change. EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*test_sessions_[0]->interval_timer_, enableTimer(std::chrono::milliseconds(2000), _)); EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer()); test_sessions_[0]->timeout_timer_->invokeCallback(); @@ -6116,7 +6285,7 @@ TEST_F(GrpcHealthCheckerImplTest, DontReuseConnectionTimeout) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); @@ -6146,7 +6315,7 @@ TEST_F(GrpcHealthCheckerImplTest, DontReuseConnectionStreamReset) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); @@ -6172,8 +6341,8 @@ TEST_F(GrpcHealthCheckerImplTest, DontReuseConnectionStreamReset) { TEST_F(GrpcHealthCheckerImplTest, GrpcFailUnknown) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::UNKNOWN); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( @@ -6186,8 +6355,8 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcFailUnknown) { TEST_F(GrpcHealthCheckerImplTest, GrpcFailNullBytes) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondResponseSpec(0, ResponseSpec{{{":status", "200"}, {"content-type", "application/grpc"}}, {GrpcHealthCheckerImplTest::ResponseSpec::badData()}, {}}); @@ -6201,8 +6370,8 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcFailNullBytes) { TEST_F(GrpcHealthCheckerImplTest, GrpcValidFramesThenInvalidFrames) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondResponseSpec( 0, ResponseSpec{{{":status", "200"}, {"content-type", "application/grpc"}}, {GrpcHealthCheckerImplTest::ResponseSpec::validFramesThenInvalidFrames()}, @@ -6217,8 +6386,8 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcValidFramesThenInvalidFrames) { TEST_F(GrpcHealthCheckerImplTest, GrpcFailServiceUnknown) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondServiceStatus(0, grpc::health::v1::HealthCheckResponse::SERVICE_UNKNOWN); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( @@ -6231,8 +6400,8 @@ TEST_F(GrpcHealthCheckerImplTest, GrpcFailServiceUnknown) { TEST_F(GrpcHealthCheckerImplTest, GrpcFailUnknownHealthStatus) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); respondServiceStatus(0, static_cast(999)); EXPECT_TRUE(cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->healthFlagGet( @@ -6247,8 +6416,8 @@ TEST_F(GrpcHealthCheckerImplTest, GoAwayErrorProbeInProgress) { // is reached. setupHCWithUnhealthyThreshold(1); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); // GOAWAY with non-NO_ERROR code will result in a healthcheck failure // and the connection closing. @@ -6298,13 +6467,13 @@ TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressTimeout) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); // Unhealthy threshold is 1 so first timeout causes unhealthy EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); // GOAWAY during check should be handled gracefully. test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError); @@ -6333,13 +6502,13 @@ TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressStreamReset) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); // Unhealthy threshold is 1 so first stream reset causes unhealthy EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); // GOAWAY during check should be handled gracefully. test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError); @@ -6368,13 +6537,13 @@ TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressBadResponse) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); // Unhealthy threshold is 1 so first bad response causes unhealthy EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); // GOAWAY during check should be handled gracefully. test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError); @@ -6405,13 +6574,13 @@ TEST_F(GrpcHealthCheckerImplTest, GoAwayProbeInProgressConnectionClose) { expectSessionCreate(); expectHealthcheckStart(0); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); health_checker_->start(); expectHealthcheckStop(0); // Unhealthy threshold is 1 so first bad response causes unhealthy EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Changed)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); // GOAWAY during check should be handled gracefully. test_sessions_[0]->codec_client_->raiseGoAway(Http::GoAwayErrorCode::NoError); @@ -6560,8 +6729,8 @@ INSTANTIATE_TEST_SUITE_P( TEST_P(BadResponseGrpcHealthCheckerImplTest, GrpcBadResponse) { setupHC(); expectSingleHealthcheck(HealthTransition::Changed); - EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true)); - EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(event_logger_, logUnhealthy(_, _, _, true, _)); + EXPECT_CALL(event_logger_, logEjectUnhealthy(_, _, _, _)); ResponseSpec spec = GetParam(); respondResponseSpec(0, std::move(spec)); @@ -6622,11 +6791,12 @@ TEST(HealthCheckEventLoggerImplTest, All) { "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"port_value\":443," "\"resolver_name\":\"\",\"ipv4_compat\":false,\"network_namespace_filepath\":\"\"}}," "\"cluster_name\":\"fake_cluster\"," - "\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\"}," + "\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\",\"http_status_code\":0}," "\"timestamp\":\"2009-02-13T23:31:31.234Z\"," "\"metadata\":{\"filter_metadata\":{},\"typed_filter_metadata\":{}}," "\"locality\":{\"region\":\"\",\"zone\":\"\",\"sub_zone\":\"\"}}\n"})); - event_logger->logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE); + event_logger->logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE, + 0); EXPECT_CALL( *file, @@ -6665,11 +6835,11 @@ TEST(HealthCheckEventLoggerImplTest, All) { "name\":\"fake_cluster\"," "\"timestamp\":\"2009-02-13T23:31:31.234Z\"," "\"health_check_failure_event\":{\"failure_type\":\"ACTIVE\"," - "\"first_check\":false}," + "\"first_check\":false,\"http_status_code\":0}," "\"metadata\":{\"filter_metadata\":{},\"typed_filter_metadata\":{}}," "\"locality\":{\"region\":\"\",\"zone\":\"\",\"sub_zone\":\"\"}}\n"})); event_logger->logUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE, - false); + false, 0); EXPECT_CALL(*file, write(absl::string_view{ "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{" @@ -6725,14 +6895,15 @@ TEST(HealthCheckEventLoggerImplTest, OneEventLogger) { std::unique_ptr event_logger = *HealthCheckEventLoggerImpl::create(health_check_config, context); - event_logger->logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE); + event_logger->logEjectUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE, + 0); EXPECT_EQ( file_log_data.value(), "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{" "\"protocol\":\"TCP\",\"address\":\"10.0.0.1\",\"port_value\":443,\"resolver_name\":\"\"," "\"ipv4_compat\":false,\"network_namespace_filepath\":\"\"}},\"cluster_name\":\"fake_" "cluster\"," - "\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\"}," + "\"eject_unhealthy_event\":{\"failure_type\":\"ACTIVE\",\"http_status_code\":0}," "\"timestamp\":\"2009-02-13T23:31:31.234Z\"," "\"metadata\":{\"filter_metadata\":{},\"typed_filter_metadata\":{}}," "\"locality\":{\"region\":\"\",\"zone\":\"\",\"sub_zone\":\"\"}}\n"); @@ -6761,7 +6932,7 @@ TEST(HealthCheckEventLoggerImplTest, OneEventLogger) { "{\"region\":\"\",\"zone\":\"\",\"sub_zone\":\"\"},\"successful_health_check_event\":{}}\n"); event_logger->logUnhealthy(envoy::data::core::v3::HTTP, host, envoy::data::core::v3::ACTIVE, - false); + false, 0); EXPECT_EQ( file_log_data.value(), "{\"health_checker_type\":\"HTTP\",\"host\":{\"socket_address\":{" @@ -6770,7 +6941,7 @@ TEST(HealthCheckEventLoggerImplTest, OneEventLogger) { "cluster\"," "\"timestamp\":\"2009-02-13T23:31:31.234Z\"," "\"health_check_failure_event\":{\"failure_type\":\"ACTIVE\"," - "\"first_check\":false}," + "\"first_check\":false,\"http_status_code\":0}," "\"metadata\":{\"filter_metadata\":{},\"typed_filter_metadata\":{}}," "\"locality\":{\"region\":\"\",\"zone\":\"\",\"sub_zone\":\"\"}}\n"); diff --git a/test/extensions/health_checkers/redis/redis_test.cc b/test/extensions/health_checkers/redis/redis_test.cc index 8491db4d48a52..32dd45ec69e62 100644 --- a/test/extensions/health_checkers/redis/redis_test.cc +++ b/test/extensions/health_checkers/redis/redis_test.cc @@ -321,7 +321,7 @@ TEST_F(RedisHealthCheckerTest, PingWithAuth) { interval_timer_->invokeCallback(); // Failure, invalid auth - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -369,7 +369,7 @@ TEST_F(RedisHealthCheckerTest, ExistsWithAuth) { interval_timer_->invokeCallback(); // Failure, invalid auth - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -415,7 +415,7 @@ TEST_F(RedisHealthCheckerTest, PingAndVariousFailures) { interval_timer_->invokeCallback(); // Failure - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -483,8 +483,8 @@ TEST_F(RedisHealthCheckerTest, FailuresLogging) { interval_timer_->invokeCallback(); // Failure - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -494,7 +494,7 @@ TEST_F(RedisHealthCheckerTest, FailuresLogging) { interval_timer_->invokeCallback(); // Fail again - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -529,8 +529,8 @@ TEST_F(RedisHealthCheckerTest, LogInitialFailure) { client_->runLowWatermarkCallbacks(); // Redis failure via disconnect - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); pool_callbacks_->onFailure(); @@ -591,7 +591,7 @@ TEST_F(RedisHealthCheckerTest, Exists) { interval_timer_->invokeCallback(); // Failure, exists - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); response = std::make_unique(); @@ -688,7 +688,7 @@ TEST_F(RedisHealthCheckerTest, NoConnectionReuse) { interval_timer_->invokeCallback(); // The connection will close on failure. - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); EXPECT_CALL(*client_, close()); diff --git a/test/extensions/health_checkers/thrift/thrift_test.cc b/test/extensions/health_checkers/thrift/thrift_test.cc index e753f8e3c1343..60d7e9e0ef96b 100644 --- a/test/extensions/health_checkers/thrift/thrift_test.cc +++ b/test/extensions/health_checkers/thrift/thrift_test.cc @@ -207,7 +207,7 @@ TEST_F(ThriftHealthCheckerTest, Ping) { responseSuccess(); continueHealthCheck(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); responseFailure(); // Shutdown *without* an active request. @@ -227,7 +227,7 @@ TEST_F(ThriftHealthCheckerTest, PingAndVariousFailures) { responseSuccess(); continueHealthCheck(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); responseFailure(); continueHealthCheck(); @@ -258,13 +258,13 @@ TEST_F(ThriftHealthCheckerTest, AlwaysLogHealthCheckFailures) { continueHealthCheck(); // Fail on the exception response. - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false, _)); responseFailure(); continueHealthCheck(); // Fail again. - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, false, _)); responseFailure(); continueHealthCheck(); @@ -283,8 +283,8 @@ TEST_F(ThriftHealthCheckerTest, LogInitialFailure) { setup(); startHealthChecker(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true, _)); disconnectHealthCheck(); restartHealthCheckSession(); @@ -311,7 +311,7 @@ TEST_F(ThriftHealthCheckerTest, LogTempFailureFailure) { responseSuccess(); continueHealthCheck(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); disconnectHealthCheck(); restartHealthCheckSession(); @@ -335,8 +335,8 @@ TEST_F(ThriftHealthCheckerTest, LogConsecutiveFailures) { setup(); startHealthChecker(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); - EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); + EXPECT_CALL(*event_logger_, logUnhealthy(_, _, _, true, _)); responseFailure(); continueHealthCheck(); @@ -367,7 +367,7 @@ TEST_F(ThriftHealthCheckerTest, NoConnectionReuse) { client_->raiseResponseResult(true); restartHealthCheckSession(); - EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _)); + EXPECT_CALL(*event_logger_, logEjectUnhealthy(_, _, _, _)); EXPECT_CALL(*timeout_timer_, disableTimer()); EXPECT_CALL(*interval_timer_, enableTimer(_, _)); // The connection will be closed on failure. diff --git a/test/mocks/upstream/health_check_event_logger.h b/test/mocks/upstream/health_check_event_logger.h index 200512ec9e28a..9b3fb57598347 100644 --- a/test/mocks/upstream/health_check_event_logger.h +++ b/test/mocks/upstream/health_check_event_logger.h @@ -18,7 +18,7 @@ class MockHealthCheckEventLogger : public HealthCheckEventLogger { public: MOCK_METHOD(void, logEjectUnhealthy, (envoy::data::core::v3::HealthCheckerType, const HostDescriptionConstSharedPtr&, - envoy::data::core::v3::HealthCheckFailureType)); + envoy::data::core::v3::HealthCheckFailureType, uint64_t)); MOCK_METHOD(void, logAddHealthy, (envoy::data::core::v3::HealthCheckerType, const HostDescriptionConstSharedPtr&, bool)); @@ -26,7 +26,7 @@ class MockHealthCheckEventLogger : public HealthCheckEventLogger { (envoy::data::core::v3::HealthCheckerType, const HostDescriptionConstSharedPtr&)); MOCK_METHOD(void, logUnhealthy, (envoy::data::core::v3::HealthCheckerType, const HostDescriptionConstSharedPtr&, - envoy::data::core::v3::HealthCheckFailureType, bool)); + envoy::data::core::v3::HealthCheckFailureType, bool, uint64_t)); MOCK_METHOD(void, logDegraded, (envoy::data::core::v3::HealthCheckerType, const HostDescriptionConstSharedPtr&)); MOCK_METHOD(void, logNoLongerDegraded,