Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 312 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["source/extensions/dynamic_modules/sdk/rust", "test/extensions/dynamic_modules/test_data/rust"]
resolver = "2"
14 changes: 14 additions & 0 deletions api/envoy/service/health/v3/hds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "envoy/config/endpoint/v3/endpoint_components.proto";

import "google/api/annotations.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/struct.proto";

import "envoy/annotations/deprecation.proto";
import "udpa/annotations/status.proto";
Expand Down Expand Up @@ -109,6 +110,19 @@ message EndpointHealth {
config.endpoint.v3.Endpoint endpoint = 1;

config.core.v3.HealthStatus health_status = 2;

// Optional metadata about the health check result, populated by the active
// health checker and forwarded to the management server for richer health
// state interpretation.
//
// Well-known keys:
//
// ``http_status_code`` (number)
// Set by the HTTP health checker. Contains the HTTP response status code
// returned by the upstream endpoint during the most recent health check,
// e.g. ``200``, ``503``. Only present when the health check received a
// complete HTTP response; absent on connection failures or timeouts.
google.protobuf.Struct health_metadata = 3;
}

// Group endpoint health by locality under each cluster.
Expand Down
13 changes: 13 additions & 0 deletions envoy/upstream/upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,19 @@ class Host : virtual public HostDescription {
* Set true to disable active health check for the host.
*/
virtual void setDisableActiveHealthCheck(bool disable_active_health_check) PURE;

/**
* Store the HTTP status code from the last active health check response.
* Used by HDS to report richer health state to the control plane.
* 0 means no response has been recorded yet.
*/
virtual void setLastHealthCheckHttpStatus(uint64_t) PURE;

/**
* @return the HTTP status code from the last active health check response, or
* 0 if no response has been recorded.
*/
virtual absl::optional<uint64_t> lastHealthCheckHttpStatus() const PURE;
};

using HostConstSharedPtr = std::shared_ptr<const Host>;
Expand Down
8 changes: 8 additions & 0 deletions source/common/upstream/health_discovery_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ envoy::service::health::v3::HealthCheckRequestOrEndpointHealthResponse HdsDelega
}
}

// If a HTTP health check has run, attach the last response code to the
// HDS report so the control plane can interpret richer health states.
auto http_status = host->lastHealthCheckHttpStatus();
if (http_status.has_value()) {
(*endpoint->mutable_health_metadata()->mutable_fields())["http_status_code"]
.set_number_value(http_status.value());
}

// TODO(drewsortega): remove this once we are on v4 and endpoint_health_response is
// removed. Copy this endpoint's health info to the legacy flat-list.
response.mutable_endpoint_health_response()->add_endpoints_health()->MergeFrom(*endpoint);
Expand Down
6 changes: 6 additions & 0 deletions source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ class HostImplBase : public Host,
uint32_t healthFlagsGetAll() const override { return health_flags_; }
void healthFlagsSetAll(uint32_t bits) override { health_flags_ |= bits; }

void setLastHealthCheckHttpStatus(uint64_t status) override { last_hc_http_status_ = status; }
absl::optional<uint64_t> lastHealthCheckHttpStatus() const override {
return last_hc_http_status_;
}

Host::HealthStatus healthStatus() const override {
// Evaluate active health status first.

Expand Down Expand Up @@ -471,6 +476,7 @@ class HostImplBase : public Host,
// flag access? May be we could refactor HealthFlag to contain all these statuses and flags in the
// future.
std::atomic<Host::HealthStatus> eds_health_status_{};
absl::optional<std::atomic<uint64_t>> last_hc_http_status_ = absl::nullopt;

struct HostHandleImpl : HostHandle {
HostHandleImpl(const std::shared_ptr<const HostImplBase>& parent) : parent_(parent) {
Expand Down
Loading
Loading