Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show RoutingGroup info in query history #607

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andythsu
Copy link
Member

@andythsu andythsu commented Feb 3, 2025

Description

It is useful to show what routing group a request is being routed to because if two routing groups have the same routedTo url, it will show the wrong information on the history page

Old:
image

New:
image

Additional context and related issues

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:

@cla-bot cla-bot bot added the cla-signed label Feb 3, 2025
@andythsu andythsu force-pushed the routing_group branch 4 times, most recently from f57f2ad to d23d058 Compare February 3, 2025 11:48
@ebyhr ebyhr removed their request for review February 5, 2025 23:24
{
Optional<String> previousBackend = getPreviousBackend(request);
String clusterHost = previousBackend.orElseGet(() -> getBackendFromRoutingGroup(request));
// This falls back on adhoc routing group if no routing group can be determined
String routingGroup = routingGroupSelector.findRoutingGroup(request).orElse("adhoc");
Copy link
Contributor

Choose a reason for hiding this comment

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

moving this call out of the orElseGet will cause the routing logic to be triggered for every incoming request, including those containing query IDs. Please revert

*/
package io.trino.gateway.ha.handler;

public record RoutingDestinationInfo(String group, String clusterUri) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It would expand the scope of this change, but it seems like a good time to add some audibility on which rules were triggered. For example, you could have RoutingDestinationInfo(String group, String clusterUri, List<String> rulesFired), where rulesFired would contain the names of all rules who's condition evaluated to true. We can chat about this offline

*/
package io.trino.gateway.ha.handler;

public record RoutingDestinationInfo(String group, String clusterUri) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can clusterUri be URIinstead of aString`?

@@ -181,6 +183,8 @@ private void performRequest(
ImmutableList.Builder<NewCookie> cookieBuilder = ImmutableList.builder();
cookieBuilder.addAll(getOAuth2GatewayCookie(remoteUri, servletRequest));

requestBuilder.addHeader("X-Routing-Group", routingDestinationInfo.group());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you pass the routing info directly to recordBackendForQueryId in the future.transform call? If not, then use ROUTING_GROUP_HEADER from RoutingGroupSelector as the header key

@@ -0,0 +1,2 @@
ALTER TABLE query_history
ADD routing_group VARCHAR(255);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: end the file with a newline. This goes for the other .sql files as well

@@ -85,11 +85,11 @@ void testByRoutingGroupHeader()
// If the header is present the routing group is the value of that header.
when(mockRequest.getHeader(ROUTING_GROUP_HEADER)).thenReturn("batch_backend");
assertThat(RoutingGroupSelector.byRoutingGroupHeader().findRoutingGroup(mockRequest))
.isEqualTo("batch_backend");
.contains("batch_backend");
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to change this?

String clusterHost = previousBackend.orElseGet(() -> getBackendFromRoutingGroup(request));
// This falls back on adhoc routing group if no routing group can be determined
String routingGroup = routingGroupSelector.findRoutingGroup(request).orElse("adhoc");
String user = request.getHeader(USER_HEADER);
Copy link
Member

Choose a reason for hiding this comment

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

This may not be always true, especially in case of bearer tokens (JWT). But I see that this logic is from before and it's not newly added as a part of the PR.

*/
package io.trino.gateway.ha.handler;

public record RoutingDestinationInfo(String group, String clusterUri) {}
Copy link
Member

Choose a reason for hiding this comment

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

name RoutingDestination would be better.

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.

3 participants