Skip to content

[Server] Forward pluggable components through the one Armeria API port - #2036

Closed
s-maling-celonis wants to merge 4 commits into
unitycatalog:mainfrom
s-maling-celonis:poc/armeria-single-port
Closed

s-maling-celonis wants to merge 4 commits into
unitycatalog:mainfrom
s-maling-celonis:poc/armeria-single-port

Conversation

@s-maling-celonis

Copy link
Copy Markdown
Contributor

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Draft, proof of concept. Stacked on #1979. Until #1979 merges, this diff includes its commits. The change here is the last two commits, be4b6d0f and 8144c5dc (+276 lines, about 40 of them non-test).

Description of changes

In #1979, @yili-db asked to keep the Vert.x URL transcoder because it can serve pluggable components, such as the embedded OpenSharing server proposed in #1825, through one public port. This PR shows Armeria can do that itself, without proxying every UC request through Vert.x.

A component runs its own listener on loopback. UC forwards its path prefix from the API port, and Armeria keeps serving every other path directly:

client -> UC's public port (e.g. 8080, Armeria)
             |
             +-- /api/2.1/opensharing/**  -> forwarded to the component on 127.0.0.1:<port>
             |
             +-- everything else          -> UC's own services, no extra hop

This change:

  • adds ArmeriaServerBuilder#forward(pathPrefix, target): registers a handler for pathPrefix on the API virtual host that sends the request, with method, path, query, headers and body unchanged, through an Armeria WebClient to target, and streams the response back. Host is rewritten to the target's address, as a reverse proxy would. A prefix that overlaps the UC or control API paths is rejected.
  • adds UnityCatalogServer.Builder#forward(pathPrefix, target), which registers each forward on the API virtual host alongside the UC services.

For #1825, the embedding code would be:

UnityCatalogServer.builder()
    .port(8080)
    .forward("/api/2.1/opensharing/", URI.create("http://127.0.0.1:" + openSharingPort))
    .build();

Compared with keeping the transcoder

  • Only forwarded paths take a second hop. UC's own requests reach Armeria directly, so none of the issues listed in [Server] Serve clients from Armeria directly and remove the Vert.x URL transcoder #1979 come back: no HTTP/1.1 connection pool to size to JDBC, no Vert.x and Netty 4.1 dependencies, Datadog spans close properly, and HTTP/2 and real client addresses are kept.
  • The forward streams, so request and response bodies are not held in memory.

Behavior and limits

Tests

  • ArmeriaForwardTest: a separate Armeria server on loopback, reached only through UC's API port. Checks that a POST with a query, bearer token and JSON body arrives unchanged; that the component's status and headers come back; that UC routes and look-alike paths (/api/2.1/opensharingX) are not forwarded; and that an unreachable target returns a 5xx.
  • UnityCatalogServerForwardTest: a full UnityCatalogServer with authorization enabled and a component on loopback. Through the one port, the component answers under its prefix while /api/2.1/unity-catalog/catalogs still returns 401.
  • ArmeriaServerBuilderTest: a forwarded prefix inside the UC API is rejected.

Verification

  • build/sbt javafmtAll
  • build/sbt "server/testOnly io.unitycatalog.server.UnityCatalogServerForwardTest io.unitycatalog.server.ArmeriaForwardTest io.unitycatalog.server.ArmeriaServerBuilderTest io.unitycatalog.server.UnityCatalogServerTest": 18 tests passed.

🤖 Generated with Claude Code

…L transcoder

The launcher ran a Vert.x verticle on the client port that forwarded
every request over HTTP/1.1 to Armeria on port + 1. Its only rewrite
turned Iceberg's %1F nested-namespace separator into a period. Unity
Catalog has no nested namespaces, so that rewrite only changed which
error a client got for a name it could never resolve.

Removing it means one listener, one event-loop stack, no second
connection pool to keep sized to the JDBC pool, and no Vert.x and
Netty 4.1 dependency line next to Armeria's Netty 4.2.

- main binds Armeria to the -p port instead of port + 1, and closes
  the server if it cannot start.
- The API port binds all interfaces, since clients now connect to it
  directly. The loopback bind existed only because the transcoder sat
  in front.
- A %1F namespace now reaches the Iceberg service as-is and is
  reported as a missing namespace (404) instead of a bad request.
- The http_server_requests_total hostname_pattern label now names the
  -p port (*:8080 by default) instead of port + 1 (*:8081).

Signed-off-by: s-maling-celonis <[email protected]>
BaseServerTest picks two free ports with ServerSocket(0) and closes
them before the server binds, so another process can take one in
between. CI hit this as a ServerPortBindException in
AuthServiceAllowlistTest. Now that the API port binds all interfaces
instead of loopback, it can collide with more sockets.

Retry the start with fresh ports, up to three attempts, when the cause
is a ServerPortBindException. Any other start failure is thrown as
before.

Signed-off-by: s-maling-celonis <[email protected]>
Proof of concept for keeping one public port without the Vert.x
transcoder. A component that runs its own listener, such as the
embedded OpenSharing server proposed in unitycatalog#1825, binds to loopback, and
ArmeriaServerBuilder#forward routes its path prefix to it from the API
port. Every other path is still served by Armeria directly.

ArmeriaForwardTest starts a separate server on loopback and checks
that a request through the API port reaches it with method, path,
query, auth header and body unchanged; that its status and headers
come back; that UC routes are not forwarded; and that an unreachable
target is reported as a server error.

Signed-off-by: s-maling-celonis <[email protected]>
…ponents

UnityCatalogServer.Builder#forward(pathPrefix, target) registers each
forward on the API virtual host, alongside the UC services, so a
component on its own loopback listener is reached through the one
public port.

UnityCatalogServerForwardTest starts a component on loopback next to a
full UnityCatalogServer with authorization enabled, and checks through
the API port that the component answers under its prefix while UC's
own API still requires authentication.

Signed-off-by: s-maling-celonis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant