Skip to main content

Crate mz_balancerd

Crate mz_balancerd 

Source
Expand description

The balancerd service is a horizontally scalable, stateless, multi-tenant ingress router for pgwire and HTTPS connections.

It listens on pgwire and HTTPS ports. When a new pgwire connection starts, the requested user is authenticated with frontegg from which a tenant id is returned. From that a target internal hostname is resolved to an IP address, and the connection is proxied to that address which has a running environmentd’s pgwire port. When a new HTTPS connection starts, its SNI hostname is used to generate an internal hostname that is resolved to an IP address, which is similarly proxied.

ModulesΒ§

codec πŸ”’
dyncfgs πŸ”’
Dyncfgs used by the balancer.

StructsΒ§

BalancerConfig
BalancerMetrics
Prometheus monitoring metrics.
BalancerService
CountingConn πŸ”’
FronteggResolver
GaugeGuard πŸ”’
Wraps an IntGauge and automatically incs on init and drops on drop. Callers should not call inc().. Useful for handling multiple task exit points, for example in the case of a panic.
HttpsBalancer πŸ”’
InternalHttpServer πŸ”’
PgwireBalancer πŸ”’
ResolvedAddr πŸ”’
ServerMetrics πŸ”’
ServerMetricsConfig πŸ”’
SniTemplate
Template for constructing the destination hostname from a TLS SNI servername. {} is replaced with the first label of the servername.
TenantDnsResolver
Resolves tenant hostnames for pgwire and HTTPS routing.

EnumsΒ§

BalancerResolver
CancellationResolver
ResolveError πŸ”’
An error resolving a connection’s destination.

ConstantsΒ§

BUILD_INFO
Balancer build information.

TraitsΒ§

ClientStream πŸ”’

FunctionsΒ§

cancel_request πŸ”’
Broadcasts cancellation to all matching environmentds. conn_id’s bits [31..20] are the lower 12 bits of a UUID for an environmentd/organization. Using that and the template in cancellation_resolver we generate a hostname. That hostname resolves to all IPs of envds that match the UUID (cloud k8s infrastructure maintains that mapping). This function creates a new task for each envd and relays the cancellation message to it, broadcasting it to any envd that might match the connection.
create_resolver πŸ”’
Creates a resolver from the system DNS configuration.
extract_tenant_from_cname πŸ”’
Extracts the tenant ID from an environmentd CNAME target.
handle_readiness_check πŸ”’
strip_ipv6_brackets πŸ”’
Strips the surrounding brackets from an IPv6 host literal, e.g. [::1] becomes ::1. Leaves other hosts unchanged. This lets a bracketed IPv6 literal in an address template parse as an IpAddr and resolve, matching what tokio::net::lookup_host accepts.