Skip to content
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

Add keepalive options for dynamic backends #423

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
15 changes: 15 additions & 0 deletions crates/adapter/src/fastly/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ pub struct DynamicBackendConfig {
pub client_certificate: *const u8,
pub client_certificate_len: u32,
pub client_key: SecretHandle,
pub http_keepalive_time_ms: u32,
pub tcp_keepalive_enable: u32,
pub tcp_keepalive_interval_secs: u32,
pub tcp_keepalive_probes: u32,
pub tcp_keepalive_time_secs: u32,
}

impl Default for DynamicBackendConfig {
Expand All @@ -145,6 +150,11 @@ impl Default for DynamicBackendConfig {
client_certificate: std::ptr::null(),
client_certificate_len: 0,
client_key: 0,
http_keepalive_time_ms: 0,
tcp_keepalive_enable: 0,
tcp_keepalive_interval_secs: 0,
tcp_keepalive_probes: 0,
tcp_keepalive_time_secs: 0,
}
}
}
Expand Down Expand Up @@ -186,6 +196,7 @@ bitflags::bitflags! {
const DONT_POOL = 1 << 12;
const CLIENT_CERT = 1 << 13;
const GRPC = 1 << 14;
const KEEPALIVE = 1 << 15;
}
}

Expand Down Expand Up @@ -249,6 +260,10 @@ impl From<BackendConfigOptions> for crate::bindings::fastly::api::http_types::Ba
options.contains(BackendConfigOptions::CLIENT_CERT),
);
flags.set(Self::GRPC, options.contains(BackendConfigOptions::GRPC));
flags.set(
Self::KEEPALIVE,
options.contains(BackendConfigOptions::KEEPALIVE),
);
flags
}
}
Expand Down
45 changes: 44 additions & 1 deletion lib/compute-at-edge-abi/compute-at-edge.witx
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,49 @@
(error $fastly_status)))
)

;; Get the idle timeout for HTTP keepalive connections to the backend.
(@interface func (export "get_http_keepalive_time")
(param $backend string)
(result $err (expected
$timeout_ms
(error $fastly_status)))
)

;; Get whether TCP keepalives have been enabled on the backend.
(@interface func (export "get_tcp_keepalive_enable")
(param $backend string)
(result $err (expected
$is_keepalive
(error $fastly_status)))
)

;; Get how long to wait between sending each TCP keepalive probe to the
;; backend.
(@interface func (export "get_tcp_keepalive_interval")
(param $backend string)
(result $err (expected
$timeout_secs
(error $fastly_status)))
)

;; Get how long to wait after sending the last data before starting to send
;; TCP keepalives to the backend.
(@interface func (export "get_tcp_keepalive_probes")
(param $backend string)
(result $err (expected
$probe_count
(error $fastly_status)))
)

;; Get how long to wait after sending the last data before starting to send
;; TCP keepalives to the backend.
(@interface func (export "get_tcp_keepalive_time")
(param $backend string)
(result $err (expected
$timeout_secs
(error $fastly_status)))
)

;; Returns 1 if the backend is configured to use SSL.
(@interface func (export "is_ssl")
(param $backend string)
Expand Down Expand Up @@ -982,4 +1025,4 @@
(@interface func (export "get_vcpu_ms")
(result $err (expected $vcpu_ms (error $fastly_status)))
)
)
)
9 changes: 9 additions & 0 deletions lib/compute-at-edge-abi/typenames.witx
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@

(typename $port u16)
(typename $timeout_ms u32)
(typename $timeout_secs u32)
(typename $probe_count u32)
(typename $backend_exists u32)
(typename $is_dynamic u32)
(typename $is_keepalive u32)
(typename $is_ssl u32)
(typename $backend_health
(enum (@witx tag u32)
Expand Down Expand Up @@ -187,6 +190,7 @@
$dont_pool
$client_cert
$grpc
$keepalive
))

(typename $dynamic_backend_config
Expand All @@ -209,6 +213,11 @@
(field $client_certificate (@witx pointer (@witx char8)))
(field $client_certificate_len u32)
(field $client_key $secret_handle)
(field $http_keepalive_time_ms $timeout_ms)
(field $tcp_keepalive_enable u32)
(field $tcp_keepalive_interval_secs $timeout_secs)
(field $tcp_keepalive_probes $probe_count)
(field $tcp_keepalive_time_secs $timeout_secs)
))

;;; TLS client certificate verified result from downstream.
Expand Down
Binary file modified lib/data/viceroy-component-adapter.wasm
Binary file not shown.
45 changes: 45 additions & 0 deletions lib/src/wiggle_abi/backend_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,51 @@ impl FastlyBackend for Session {
Err(Error::NotAvailable("SSL version information"))
}

fn get_http_keepalive_time(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
backend: wiggle::GuestPtr<str>,
) -> Result<u32, Error> {
// Viceroy doesn't support pooling:
lookup_backend_definition(self, memory, backend).map(|_| 0)
}

fn get_tcp_keepalive_enable(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
backend: wiggle::GuestPtr<str>,
) -> Result<u32, Error> {
// Viceroy doesn't support TCP keepalives:
lookup_backend_definition(self, memory, backend).map(|_| 0)
}

fn get_tcp_keepalive_interval(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
backend: wiggle::GuestPtr<str>,
) -> Result<u32, Error> {
// Viceroy doesn't currently support TCP keepalives:
lookup_backend_definition(self, memory, backend).map(|_| 0)
}

fn get_tcp_keepalive_probes(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
backend: wiggle::GuestPtr<str>,
) -> Result<u32, Error> {
// Viceroy doesn't currently support TCP keepalives:
lookup_backend_definition(self, memory, backend).map(|_| 0)
}

fn get_tcp_keepalive_time(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
backend: wiggle::GuestPtr<str>,
) -> Result<u32, Error> {
// Viceroy doesn't currently support TCP keepalives:
lookup_backend_definition(self, memory, backend).map(|_| 0)
}

fn is_ssl(
&mut self,
memory: &mut wiggle::GuestMemory<'_>,
Expand Down
1 change: 1 addition & 0 deletions lib/wit/deps/fastly/compute.wit
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ interface http-types {
dont-pool,
client-cert,
grpc,
keepalive,
}

/// Create a backend for later use
Expand Down
Loading