trinodb / trino-gateway

Home Page:https://trinodb.github.io/trino-gateway/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] The query history UI should use externalUrl instead of backendUrl

lambrospetrou opened this issue · comments

Hello folks, we hit a bug using the new trino-gateway when opening query details from the gateway's UI displaying query history.

The trino-gateway uses backendUrl instead of externalUrl in the links it shows in the UI (see code) which means when opened from our internal users, they do not resolve properly since it's trying to use the internal endpoints that the gateway uses to communicate with the clusters.

The previous presto-gateway was using the gateway's URL for this (see code), which works so far in our case, and then it routes the UI calls to fetch the query details to the right coordinator cluster using the query mapping table/cache. At some point there is a request http://<gateway-url>/ui/api/query/<query_id>, which is matched by the request handler and gets sent to the right coordinator that has the query details.

Solution

I suggest one of the following:

  1. Use the externalUrl of the backend cluster for the links in the query history, and then we will need to set those to something resolvable by the expected users of the admin UI.
  2. Revert to using the gateway's URL and let the routing take care of finding the right backend cluster.

I believe the better solution is 2, so that the gateway handles all the query routing requests, same as it does for the actual execution. With 1, we will need to make sure all clusters have user-resolvable endpoints, which in our case is impossible, so we would anyway set the externalUrl to the gateway URL if that's the solution you pick.

I can provide a PR to fix this as long as we decide on which of the two solutions you would like to use. Maybe @mosabua can chime in with a preference or route to the right folks?

Hello, any ETA for this? It seems like even setting externalUrl to the gateway URL has no effect. It is probably using the backend URL anyway https://github.com/trinodb/trino-gateway/blob/49c5c82dbc18a50b9104d001917dc3139088a0da/webapp/src/components/history.tsx#L57C30-L57C47

This issue is a bit complicated. Currently, we only store the backend_url in the query history table. Both backend_url and external_url can change at any time. This can lead to problems when the URLs are changed and the old backend_url in the query history no longer matches with the current setting.

Storing the foreign key gateway_backend.name in the query history table could solve the issue. We can get the latest backend_url and external_url for the cluster. For audit and debugging purposes, backend_url should also be kept for reference.

CREATE TABLE IF NOT EXISTS gateway_backend (
name VARCHAR(256) PRIMARY KEY,
routing_group VARCHAR (256),
backend_url VARCHAR (256),
external_url VARCHAR (256),
active BOOLEAN
);

CREATE TABLE IF NOT EXISTS query_history (
query_id VARCHAR(256) PRIMARY KEY,
query_text VARCHAR (256),
created bigint,
backend_url VARCHAR (256),
user_name VARCHAR(256),
source VARCHAR(256)
);