Skip to content

Conversation

@raj-manvar
Copy link
Member

Description

Use external url field for query routing history page

Additional context and related issues

The backendUrl used by Trino gateway may not be accessible for users, instead the external url field is used to indicate the hostname that's accessible by Trino users.

For example, when hosted on Kubernetes, it's common to use Kubernetes Service for inter apps communication like between Gateway and Trino clusters, in such cases the hostname used by Gateway would be something like service-name.namespace.svc.cluster.local which is only accessible from within the Kubernetes cluster.

#81 is relevant issue with other discussion points.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(x) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

* Fix some things. ({issue}`issuenumber`)

@cla-bot
Copy link

cla-bot bot commented Jun 2, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

1 similar comment
@cla-bot
Copy link

cla-bot bot commented Jun 2, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 56701b6 to 9af7eb5 Compare June 3, 2025 01:36
@cla-bot cla-bot bot added the cla-signed label Jun 3, 2025
@xkrogen
Copy link
Member

xkrogen commented Jun 5, 2025

Big +1 on this, we actually just finished an internal implementation of this only a couple of weeks ago that we have been planning to open source. cc @felicity3786 can you help collaborate on this?

Copy link

@felicity3786 felicity3786 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM!
Internally our implementation is a more "normalized" approache, we keep query_history without external_url, and join the gateway_backend to get it at the read time. It would leads to some potential mismatch if the gateway_backend table got updated, but no schema migration needed.
I feel in this PR, it's handled cleaner and simpler. Although there will be risk of "stale" data like if admins rename external_url, but given query_history will be purged periodically I don't think it would be a very big concern.
cc @xkrogen

@xkrogen
Copy link
Member

xkrogen commented Jun 6, 2025

Although there will be risk of "stale" data like if admins rename external_url, but given query_history will be purged periodically I don't think it would be a very big concern.

Agree that this could be a concern, but it applies even with the backend_url (i.e. even without this change, if we change the backend_url for a backend, the old history won't update). To actually tackle this, we would have to begin registering backends under some ID, and then store the backend's ID in the history instead of the URLs, and join with the backend table to reconstruct. So I think adding external_url is still fine, consistent with our current approach of the history table storing point-in-time info as of when the query was executed. If/when practical issues are observed that would encourage us to normalize this data, moving out both backend_url/external_url should be no more work than just moving backend_url.

Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the docs on explaning difference between RoutedTo and ExternalURL? Adding purpose of why 2 url exists would be great.
As you have noticed, external URL was not used at all before.

@raj-manvar
Copy link
Member Author

Added documentation on two URLs, purposes and example for the same. cc: @Chaho12

Copy link
Member

@vishalya vishalya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for filling the gap @raj-manvar. Could you also please add some unit tests in TestHaGatewayManager

  • default value and setting explicit values
  • towards cache hits and misses

Copy link
Member

@vishalya vishalya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.
Does it good to the rest of reviewers before I merge it?

@ebyhr
Copy link
Member

ebyhr commented Jun 24, 2025

Does it good to the rest of reviewers before I merge it?

Yes, please don't merge this PR yet.

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash commits and separate commits into "Use external url for query routing history" and other style changes.

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 682b757 to d4de4c1 Compare June 24, 2025 02:18
@ebyhr
Copy link
Member

ebyhr commented Jun 24, 2025

Please rebase on main to resolve conflicts.

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 8ce6366 to 2ce79b9 Compare June 24, 2025 16:57
@raj-manvar
Copy link
Member Author

Thanks @ebyhr for the help & feedback! I have rebased with main branch and also squashed all commits into a single commit

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use external url for query routing history

Please capitalize the commit title
https://trino.io/development/process.html#pull-request-and-commit-guidelines-

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 2ce79b9 to 475974b Compare June 25, 2025 01:46
@raj-manvar
Copy link
Member Author

use external url for query routing history

Please capitalize the commit title https://trino.io/development/process.html#pull-request-and-commit-guidelines-

Thanks! I'll be careful for future commits. Updated current MR commit messages.

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 475974b to 5f41101 Compare June 25, 2025 02:07
Copy link
Member

@Chaho12 Chaho12 Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we now need mapping[backend.proxyTo] = backend.name;? i think we can now remove that part in this code

        for (let index = 0; index < data.length; index++) {
          const backend = data[index] as BackendData;
          mapping[backend.name] = backend.proxyTo;
          mapping[backend.proxyTo] = backend.name;
          mapping[backend.externalUrl] = backend.name;
        }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's still used in getting the backend Name from backendUrl at https://github.com/trinodb/trino-gateway/blob/main/webapp/src/components/history.tsx#L125

It's also getting used at https://github.com/trinodb/trino-gateway/blob/main/webapp/src/components/history.tsx#L99, but we can replace this usage with just b.name ?
We could remove the remaining two mapping ( backend.name -> proxyTo and externalUrl -> name ), should we do it as part of this pull request though, as it's not strictly related to this change ? or create a separate PR ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A separate PR sounds better :) Thx for checking logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I created #711 so that we don't miss this.

Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you misunderstood ebyhr comment on capitalizing commit message. We only capitalize the first letter of the subject line.
e.g) Use external URL for query routing history, Remove inferred types and this references

@raj-manvar raj-manvar force-pushed the use_external_url_for_query_history branch from 5f41101 to 1fbf355 Compare June 26, 2025 03:59
@raj-manvar
Copy link
Member Author

I think you misunderstood ebyhr comment on capitalizing commit message. We only capitalize the first letter of the subject line. e.g) Use external URL for query routing history, Remove inferred types and this references

Ah thanks okay. I updated the commit messages accordingly.

@Chaho12 Chaho12 requested a review from ebyhr June 26, 2025 05:16
@raj-manvar
Copy link
Member Author

@ebyhr Does this good look to merge now ?

@mosabua
Copy link
Member

mosabua commented Jun 27, 2025

I checked docs now .. all good there. @andythsu @ebyhr @vishalya @Chaho12 .. is this good to go? Please update your review notes.

Copy link
Member

@Chaho12 Chaho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

@andythsu andythsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 !

@raj-manvar
Copy link
Member Author

@ebyhr @vishalya can you please help merge this.

@Chaho12
Copy link
Member

Chaho12 commented Jul 8, 2025

Will rebase and merge in few hours if you don't have any further comments @ebyhr :)

@Chaho12
Copy link
Member

Chaho12 commented Jul 9, 2025

Just for safety, I checked that rebase has no conflict :) so will rebase and merge

image

@Chaho12 Chaho12 merged commit e755b6b into trinodb:main Jul 9, 2025
3 checks passed
@github-actions github-actions bot added this to the 16 milestone Jul 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

9 participants