Skip to content

Fix UI issue in routing rules page - present indicative message #660

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.trino.gateway.ha.clustermonitor.ClusterStats;
import io.trino.gateway.ha.config.HaGatewayConfiguration;
import io.trino.gateway.ha.config.ProxyBackendConfiguration;
import io.trino.gateway.ha.config.RoutingRulesConfiguration;
import io.trino.gateway.ha.config.RulesType;
import io.trino.gateway.ha.config.UIConfiguration;
import io.trino.gateway.ha.domain.Result;
import io.trino.gateway.ha.domain.RoutingRule;
Expand Down Expand Up @@ -73,6 +75,8 @@ public class GatewayWebAppResource
private final QueryHistoryManager queryHistoryManager;
private final BackendStateManager backendStateManager;
private final ResourceGroupsManager resourceGroupsManager;
private final boolean isRulesEngineEnabled;
private final RulesType ruleType;
// TODO Avoid putting mutable objects in fields
private final UIConfiguration uiConfiguration;
private final RoutingRulesManager routingRulesManager;
Expand All @@ -92,6 +96,9 @@ public GatewayWebAppResource(
this.resourceGroupsManager = requireNonNull(resourceGroupsManager, "resourceGroupsManager is null");
this.uiConfiguration = configuration.getUiConfiguration();
this.routingRulesManager = requireNonNull(routingRulesManager, "routingRulesManager is null");
RoutingRulesConfiguration routingRules = configuration.getRoutingRules();
isRulesEngineEnabled = routingRules.isRulesEngineEnabled();
ruleType = routingRules.getRulesType();
}

@POST
Expand Down Expand Up @@ -446,6 +453,10 @@ public Response readExactMatchSourceSelector()
public Response getRoutingRules()
throws IOException
{
if (isRulesEngineEnabled && ruleType == RulesType.EXTERNAL) {
return Response.status(Response.Status.NO_CONTENT)
.entity(Result.fail("Routing rules are managed by an external service")).build();
}
List<RoutingRule> routingRulesList = routingRulesManager.getRoutingRules();
return Response.ok(Result.ok(routingRulesList)).build();
}
Expand Down
16 changes: 16 additions & 0 deletions webapp/src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export class ClientApi {
if (res.status === 401 || res.status === 403) {
this.authErrorHandler()
}
else if (res.status === 204) {
// handle the case of Response.Status.NO_CONTENT when External Routing Service is used
return { isExternalRouting: true };
Copy link
Member

@andythsu andythsu Jun 19, 2025

Choose a reason for hiding this comment

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

Can we make 204 generic so it's not tied to only thrown by isExternalRouting only? Something like

const resJson = await res.json();
if (resJson.msg.type == "external_routing"){
     return { isExternalRouting: true }
} else{
      return {}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why?
204 is only thrown when: isRulesEngineEnabled && ruleType == RulesType.EXTERNAL under /getRoutingRules in GatewayWebAppResource so i don't seem to understand why make it genreric.

also when status === 204, the body will be empty so res.json() will be none

Copy link
Member

Choose a reason for hiding this comment

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

Uh I see. I wanted to make it generic so that we can throw 204 in other scenarios as well. But we can figure it out later if we have a use case for it

}
else if (res.status >= 500) {
const resJson = await res.json();
this.serverErrorHandler(resJson.msg);
}
else if (res.status !== 200) {
Toast.error({
content: Locale.Error.Network,
Expand Down Expand Up @@ -119,6 +127,14 @@ export class ClientApi {
accessStore.updateToken("");
throw new Error(Locale.Auth.Expiration);
}
serverErrorHandler(msg: string): void {
Toast.error({
content: msg,
duration: 5,
theme: "light"
});
throw new Error(msg);
}
}

export const api = new ClientApi();
Expand Down
50 changes: 42 additions & 8 deletions webapp/src/components/routing-rules.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import { routingRulesApi, updateRoutingRulesApi } from "../api/webapp/routing-rules.ts";
import { RoutingRulesData } from "../types/routing-rules";
import { Button, Card, Form, Toast } from "@douyinfe/semi-ui";
import { Button, Card, Form, Toast, Spin } from "@douyinfe/semi-ui";
import { FormApi } from "@douyinfe/semi-ui/lib/es/form";
import { Role, useAccessStore } from "../store";
import Locale from "../locales";
Expand All @@ -10,20 +10,30 @@ export function RoutingRules() {
const [rules, setRules] = useState<RoutingRulesData[]>([]);
const [editingStates, setEditingStates] = useState<boolean[]>([]);
const [formApis, setFormApis] = useState<(FormApi<any> | null)[]>([]);
const [isExternalRouting, setIsExternalRouting] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const access = useAccessStore();

useEffect(() => {
fetchRoutingRules();
}, []);

const fetchRoutingRules = () => {
setIsLoading(true);
routingRulesApi()
.then(data => {
setRules(data);
setEditingStates(new Array(data.length).fill(false));
setFormApis(new Array(data.length).fill(null));
if (data.isExternalRouting) {
setIsExternalRouting(true);
} else {
setRules(data);
setEditingStates(new Array(data.length).fill(false));
setFormApis(new Array(data.length).fill(null));
setIsExternalRouting(false);
}
}).catch(() => {
Toast.error(Locale.RoutingRules.ErrorFetch);
}).finally(() => {
setIsLoading(false);
});
};

Expand Down Expand Up @@ -80,8 +90,32 @@ export function RoutingRules() {
};

return (
<div>
{rules.map((rule, index) => (
<>
{isLoading ? (
<div style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
paddingTop: '40px'
}}>
<Spin size="large" />
</div>
) : rules.length === 0 ? (
<div style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
paddingTop: '40px',
fontSize: '16px',
color: '#666'
}}>
{isExternalRouting ?
"No routing rules available. Routing rules are managed by an external service." :
"No routing rules configured. Add rules to manage query routing."
}
</div>
) : (
rules.map((rule, index) => (
<div key={index} style={{marginBottom: '20px'}}>
<Card
shadows='always'
Expand Down Expand Up @@ -170,7 +204,7 @@ export function RoutingRules() {
</Form>
</Card>
</div>
))}
</div>
)))}
</>
);
}