Skip to content

Commit c7d381d

Browse files
committed
Fix balancerd tests after sni fastpath
- don't use fastpath when tenant resolution is required sni fastpath, like http, does not support tenant resolution in docker compose - fix workflow_user test to close connection before looking at writes - add more logging for man_connections
1 parent 72ce294 commit c7d381d

File tree

2 files changed

+65
-26
lines changed

2 files changed

+65
-26
lines changed

src/balancerd/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,13 +1318,13 @@ impl Resolver {
13181318
port,
13191319
}),
13201320
) => {
1321-
debug!("Found sni servername: {servername:?} (pgwire)");
13221321
let sni_addr = sni_addr_template.replace("{}", servername);
13231322
let tenant = stub_resolver.tenant(&sni_addr).await;
1324-
debug!("sni_addr tenant lookup {:?} - {:?}", sni_addr, tenant);
13251323
let sni_addr = format!("{sni_addr}:{port}");
1326-
debug!("sni_addr backend lookup {sni_addr}");
13271324
let addr = lookup(&sni_addr).await?;
1325+
if tenant.is_some() {
1326+
debug!("SNI header found for tenant {:?}", tenant);
1327+
}
13281328
ResolvedAddr {
13291329
addr,
13301330
password: None,
@@ -1354,10 +1354,9 @@ impl Resolver {
13541354
addr_template.replace("{}", &auth_session.tenant_id().to_string());
13551355
let addr = lookup(&addr).await?;
13561356
let tenant = Some(auth_session.tenant_id().to_string());
1357-
debug!(
1358-
"No sni header found for tenant connection {:?}, used frontegg",
1359-
tenant
1360-
);
1357+
if tenant.is_some() {
1358+
debug!("SNI header NOT found for tenant {:?}", tenant);
1359+
}
13611360
ResolvedAddr {
13621361
addr,
13631362
password: Some(password),

test/balancerd/mzcompose.py

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import socket
1818
import ssl
1919
import struct
20+
import time
2021
import uuid
2122
from collections.abc import Callable
2223
from textwrap import dedent
@@ -99,11 +100,14 @@ def app_password(email: str) -> str:
99100
f"--frontegg-api-token-url={FRONTEGG_URL}/identity/resources/auth/v1/api-token",
100101
f"--frontegg-admin-role={ADMIN_ROLE}",
101102
"--https-sni-resolver-template=materialized:6876",
102-
"--pgwire-sni-resolver-template=materialized:6875",
103+
# This will be turned off until we can resolve perf issues
104+
# https://github.com/MaterializeInc/database-issues/issues/9700
105+
# "--pgwire-sni-resolver-template=materialized:6875",
103106
"--tls-key=/secrets/balancerd.key",
104107
"--tls-cert=/secrets/balancerd.crt",
105-
"--default-config=balancerd_inject_proxy_protocol_header_http=true",
106108
"--internal-tls",
109+
"--tls-mode=require",
110+
"--default-config=balancerd_inject_proxy_protocol_header_http=true",
107111
# Nonsensical but we don't need cancellations here
108112
"--cancellation-resolver-dir=/secrets/",
109113
],
@@ -248,7 +252,6 @@ def workflow_plaintext(c: Composition) -> None:
248252
f"--frontegg-api-token-url={FRONTEGG_URL}/identity/resources/auth/v1/api-token",
249253
f"--frontegg-admin-role={ADMIN_ROLE}",
250254
"--https-resolver-template=materialized:6876",
251-
"--pgwire-sni-resolver-template=materialized:6876",
252255
"--tls-key=/secrets/balancerd.key",
253256
"--tls-cert=/secrets/balancerd.crt",
254257
"--default-config=balancerd_inject_proxy_protocol_header_http=true",
@@ -593,6 +596,7 @@ def workflow_mz_not_running(c: Composition) -> None:
593596
"failure in name resolution",
594597
"failed to lookup address information",
595598
"Name or service not known",
599+
"SSL connection has been closed unexpectedly",
596600
]
597601
)
598602
except:
@@ -605,24 +609,55 @@ def workflow_mz_not_running(c: Composition) -> None:
605609

606610
def workflow_user(c: Composition) -> None:
607611
"""Test that the user is passed all the way to Mz itself."""
608-
c.up("balancerd", "frontegg-mock", "materialized")
609-
610-
# Non-admin user.
611-
cursor = sql_cursor(c, email=OTHER_USER)
612+
with c.override(
613+
Balancerd(
614+
command=[
615+
"--startup-log-filter=debug",
616+
"service",
617+
"--pgwire-listen-addr=0.0.0.0:6875",
618+
"--https-listen-addr=0.0.0.0:6876",
619+
"--internal-http-listen-addr=0.0.0.0:6878",
620+
"--frontegg-resolver-template=materialized:6875",
621+
"--frontegg-jwk-file=/secrets/frontegg-mock.crt",
622+
f"--frontegg-api-token-url={FRONTEGG_URL}/identity/resources/auth/v1/api-token",
623+
f"--frontegg-admin-role={ADMIN_ROLE}",
624+
"--https-sni-resolver-template=materialized:6876",
625+
# Same defaults but we want to remove the pgwire-sni-resolver
626+
# In order for SNI to do tenant resoluition we need an extra CNAME rec to be added
627+
# which we can't do in docker compose
628+
# "--pgwire-sni-resolver-template=materialized:6875",
629+
"--tls-key=/secrets/balancerd.key",
630+
"--tls-cert=/secrets/balancerd.crt",
631+
"--internal-tls",
632+
"--tls-mode=require",
633+
"--default-config=balancerd_inject_proxy_protocol_header_http=true",
634+
# Nonsensical but we don't need cancellations here
635+
"--cancellation-resolver-dir=/secrets/",
636+
],
637+
depends_on=["test-certs"],
638+
volumes=[
639+
"secrets:/secrets",
640+
],
641+
),
642+
):
643+
c.up("balancerd", "frontegg-mock", "materialized")
644+
# Non-admin user.
645+
cursor = sql_cursor(c, email=OTHER_USER)
612646

613-
try:
614-
cursor.execute("DROP DATABASE materialize CASCADE")
615-
raise RuntimeError("execute() expected to fail")
616-
except ProgrammingError as e:
617-
assert "must be owner of DATABASE materialize" in str(e)
618-
except:
619-
raise RuntimeError("execute() threw an unexpected exception")
647+
try:
648+
cursor.execute("DROP DATABASE materialize CASCADE")
649+
raise RuntimeError("execute() expected to fail")
650+
except ProgrammingError as e:
651+
assert "must be owner of DATABASE materialize" in str(e)
652+
except:
653+
raise RuntimeError("execute() threw an unexpected exception")
620654

621-
cursor.execute("SELECT current_user()")
622-
assert OTHER_USER in str(cursor.fetchall())
655+
cursor.execute("SELECT current_user()")
656+
assert OTHER_USER in str(cursor.fetchall())
657+
cursor.close()
623658

624-
assert_metrics(c, 'mz_balancer_tenant_connection_active{source="pgwire"')
625-
assert_metrics(c, 'mz_balancer_tenant_connection_rx{source="pgwire"')
659+
assert_metrics(c, 'mz_balancer_tenant_connection_active{source="pgwire"')
660+
assert_metrics(c, 'mz_balancer_tenant_connection_rx{source="pgwire"')
626661

627662

628663
def workflow_many_connections(c: Composition) -> None:
@@ -631,9 +666,14 @@ def workflow_many_connections(c: Composition) -> None:
631666
cursors = []
632667
connections = 1000 - 10 # Go almost to the limit, but not above
633668
print(f"Opening {connections} connections.")
634-
for i in range(connections):
669+
start = time.time()
670+
for _ in range(connections):
635671
cursor = sql_cursor(c)
636672
cursors.append(cursor)
673+
duration = time.time() - start
674+
print(
675+
f"{connections} connections opened in {duration} seconds, {duration/float(connections)} avg connection time"
676+
)
637677

638678
for cursor in cursors:
639679
cursor.execute("SELECT 'abc'")

0 commit comments

Comments
 (0)