Skip to content

Add tags support to gateway backends - #947

Open
maswin wants to merge 1 commit into
trinodb:mainfrom
maswin:tags
Open

Add tags support to gateway backends#947
maswin wants to merge 1 commit into
trinodb:mainfrom
maswin:tags

Conversation

@maswin

@maswin maswin commented Mar 2, 2026

Copy link
Copy Markdown
Member

Description

The backend stored in Gateway today has only limited fields (external url, proxy-to, name, active/not-active).
But to make some sophisticated routing decision, having tags on them would help.
For instance the version of the cluster, environment (prod/test), team name etc.
This PR does the following -

  • Flyway V5 migrations for PostgreSQL, MySQL, and Oracle
  • GatewayBackend DAO record and GatewayBackendDao updated to include
    tags in INSERT/UPDATE queries
  • ProxyBackendConfiguration exposes tags as List
  • HaGatewayManager converts between comma-separated DB storage and
    List, with tagsToString/tagsFromString helpers
  • GatewayWebAppResource propagates tags in getAllBackends response
  • UI: Tags column in the backends table rendered as tag chips;
    TagInput in the create/edit modal with space-or-enter to add tags
    and × to remove them; editTagsRef ensures tags survive any
    Form.TagInput closure/submission quirks
  • Unit tests for tagsToString/tagsFromString edge cases and
    integration tests covering create, update, clear, and list

Additional context and related issues

Tags in UI -
Screenshot 2026-03-02 at 3 44 46 PM

Update box -
Screenshot 2026-03-02 at 3 44 58 PM

Tags updated -
Screenshot 2026-03-02 at 3 45 18 PM

Release notes

Add tags to gateway backends

( ) This is not user-visible or is docs only, and no release notes are required.
( X ) Release notes are required, with the following suggested text:

* Fix some things.

@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #trino-gateway-dev on Trino slack.

@github-actions github-actions Bot added the stale label Apr 9, 2026
JdbcConnectionManager connectionManager = createTestingJdbcConnectionManager(dataStoreConfig());
HaGatewayManager haGatewayManager = new HaGatewayManager(connectionManager.getJdbi(), new RoutingConfiguration(), new DatabaseCacheConfiguration());

var backend = new ProxyBackendConfiguration();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@ebyhr ebyhr May 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here's the latest rule:

Use var judiciously
Use var only when it improves readability. Prefer it when the type is obvious from the initializer, such as with new expressions, or when the explicit type is long or heavily generic and adds noise without improving clarity.

Avoid var when the inferred type is unclear, surprising, or important to understanding the code.

https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md#use-var-judiciously

// -----------------------------------------------------------------------

@Test
void tagsToStringReturnsNullForNullInput()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

prepend method name with test here and other places

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

Comment thread docs/backend-tags.md
VALUES
('trino-1', 'adhoc', 'http://localhost:8081', 'http://localhost:8081', true),
('trino-2', 'adhoc', 'http://localhost:8082', 'http://localhost:8082', true); No newline at end of file
('trino-1', 'adhoc', 'http://localhost:8081', 'http://localhost:8081', true, 'local,prod'),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there input validation in place to prevent commas in tag values? what if we have a tag like "version - 480,475"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. I have added a validation such that tags cannot have "," in them. Also added a note in the docs to avoid comma and if they need something like "version - 480,475" to use "version - 480","version - 475"

@Path("/updateBackend")
public Response updateBackend(ProxyBackendConfiguration backend)
{
ProxyBackendConfiguration proxyBackendConfiguration = gatewayBackendManager.updateBackend(backend);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the payload doesn't send the tags, they will be cleared. But this code can inspect the payload and decide to use the sent one vs existing one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is true for every other field. Adding a special update logic for tags might make it inconsistent with other APIs. The UI always sends a full list of tags.

@github-actions github-actions Bot removed the stale label Apr 10, 2026
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #trino-gateway-dev on Trino slack.

@github-actions github-actions Bot added the stale label May 1, 2026
@github-actions

Copy link
Copy Markdown

Closing this pull request, as it has been stale for six weeks. Feel free to re-open at any time.

@github-actions github-actions Bot closed this May 22, 2026
@mosabua mosabua reopened this May 22, 2026
@mosabua mosabua added stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed. and removed stale labels May 23, 2026
@Chaho12

Chaho12 commented May 27, 2026

Copy link
Copy Markdown
Member

Can you sqaush & rewrite commit message ?

@maswin

maswin commented May 28, 2026

Copy link
Copy Markdown
Member Author

Can you sqaush & rewrite commit message ?

@Chaho12 - Done

@maswin

maswin commented Jun 4, 2026

Copy link
Copy Markdown
Member Author

@vishalya - can you review the changes?

checkArgument(backend.getExternalUrl() != null, "Backend external url cannot be null");
for (String tag : backend.getTags()) {
checkArgument(tag != null && !tag.isBlank(), "Backend tag cannot be null or blank");
checkArgument(!tag.contains(","), "Backend tag cannot contain ',' character: %s", tag);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need for line 236, as comma is rejected anyway in line 268, as it uses , as storage delimiter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The checkArgument is still needed - an un-rejected "a,b" tag would silently split into two tags on read rather than being rejected. This validation was also requested earlier in the review and is covered by tests.

Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
@ebyhr ebyhr removed the stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed. label Jun 8, 2026
@github-actions

Copy link
Copy Markdown

This pull request has gone a while without any activity. Ask for help on #trino-gateway-dev on Trino slack.

@github-actions github-actions Bot added the stale label Jun 29, 2026
@mosabua

mosabua commented Jul 9, 2026

Copy link
Copy Markdown
Member

@maswin can you address comments and work with @ebyhr and @Chaho12 ? I would like to get this feature in.

@maswin

maswin commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@maswin can you address comments and work with @ebyhr and @Chaho12 ? I would like to get this feature in.

Sure. Addressed all review comments. Hoping to get this feature in.

@Chaho12

Chaho12 commented Jul 20, 2026

Copy link
Copy Markdown
Member

Build is failing. Please try building locally and fix the failure.

@maswin

maswin commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

Build is failing. Please try building locally and fix the failure.

Done.

@maswin

maswin commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

@vishalya @Chaho12 - Is this good to be merged?

@Chaho12
Chaho12 requested a review from ebyhr July 27, 2026 23:21
@Chaho12

Chaho12 commented Jul 27, 2026

Copy link
Copy Markdown
Member

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Backend tags are added as a list-based backend configuration field, validated and serialized for database persistence across supported database schemas. Backend responses and frontend cluster management now include tag data for display and editing. Tests cover persistence, updates, clearing, validation, response mapping, and conversion utilities. New documentation describes tag behavior, API examples, validation, and usage scenarios.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/backend-tags.md`:
- Around line 11-13: Update the tag-format description in the backend tags
documentation to state that tags must be nonblank strings, cannot contain
commas, and have surrounding whitespace trimmed. Remove the claim that any
string is accepted and keep the key:value convention as an example rather than a
requirement.

In `@docs/gateway-api.md`:
- Around line 86-87: Update the trino-2 object in the list response example to
include the tags property, using an empty array or representative tag values
consistent with the other objects and the response contract.

In `@webapp/src/components/cluster.tsx`:
- Around line 68-73: Update tagsRender to ensure each rendered Tag has a unique
React key when backend tags contain duplicates, preferably by incorporating the
map index into the key while preserving the existing tag text and styling.
- Around line 222-227: Update the Form.TagInput configuration in the cluster
form to stop treating spaces as tag separators by removing the space entry from
separator. Preserve tags containing spaces as single values while retaining
supported delimiter behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 64e5252d-0b2b-455c-85bb-13e935bc54af

📥 Commits

Reviewing files that changed from the base of the PR and between 8abc020 and 8d8d88f.

📒 Files selected for processing (16)
  • docs/backend-tags.md
  • docs/gateway-api.md
  • gateway-ha/src/main/java/io/trino/gateway/ha/config/ProxyBackendConfiguration.java
  • gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackend.java
  • gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/GatewayBackendDao.java
  • gateway-ha/src/main/java/io/trino/gateway/ha/resource/GatewayWebAppResource.java
  • gateway-ha/src/main/java/io/trino/gateway/ha/router/HaGatewayManager.java
  • gateway-ha/src/main/resources/gateway-ha-persistence-mysql.sql
  • gateway-ha/src/main/resources/gateway-ha-persistence-postgres.sql
  • gateway-ha/src/main/resources/mysql/V5__add_tags_to_gateway_backend.sql
  • gateway-ha/src/main/resources/oracle/V5__add_tags_to_gateway_backend.sql
  • gateway-ha/src/main/resources/postgresql/V5__add_tags_to_gateway_backend.sql
  • gateway-ha/src/test/java/io/trino/gateway/ha/router/TestHaGatewayManager.java
  • mkdocs.yml
  • webapp/src/components/cluster.tsx
  • webapp/src/types/cluster.d.ts

Comment thread docs/backend-tags.md Outdated
Comment thread docs/gateway-api.md
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
Comment thread webapp/src/components/cluster.tsx Outdated
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.

5 participants