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

Trino CLI: support --extra-header parameter #15826

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

Conversation

Pluies
Copy link
Contributor

@Pluies Pluies commented Jan 24, 2023

Description

Adds an --extra-header flag to the Trino CLI to allow for passing arbitrary HTTP headers to Trino requests.

Additional context and related issues

This can be useful for all sort of header-y things, including passing the X-Trino-Routing-Group header for the presto-gateway, or adding specific values needed by other fanciful architectures. :)

Release notes

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

# Section
* Add a `--extra-header` argument to the trino-cli to support sending arbitrary HTTP headers to Trino 

@Pluies
Copy link
Contributor Author

Pluies commented Jan 24, 2023

cc @electrum @hashhar , this is a more general rework of #15737, let me know your thoughts! 🙏

Copy link
Member

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

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

Is there an equivalent of this in the JDBC driver?

@github-actions github-actions bot added the docs label Jan 24, 2023
@Pluies
Copy link
Contributor Author

Pluies commented Jan 24, 2023

Is there an equivalent of this in the JDBC driver?

That's a good question - from a look at the docs, it appears not... At least not in Trino. Presto's JDBC client does support a customHeaders parameter since August 2021 (prestodb/presto@a6f1d0f), but Trino doesn't.

This was discussed in #3179 but not implemented at the time, as user impersonation was implemented with explicit headers and covered the use-case of the original reporter.

We're not using JDBC here so we only need this feature for the Trino CLI, but having support for extra headers in the code makes implementing this for JDBC easier.

Copy link
Member

@nineinchnick nineinchnick left a comment

Choose a reason for hiding this comment

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

I have mixed feelings about adding this if it's not available in the JDBC driver. Let's wait for other reviewers to comment on this.

docs/src/main/sphinx/client/cli.rst Outdated Show resolved Hide resolved
@Pluies Pluies force-pushed the trino-cli-headers branch from 0143cd9 to 0339741 Compare February 9, 2023 10:41
@dain
Copy link
Member

dain commented Feb 17, 2023

I would be surprised if this get approved. Trino generally does not allow flags to arbitrarily change core infrastructure like this. When we add features we like to start from the core problem and come up with a specific solution for that problem.

@msf
Copy link

msf commented Feb 22, 2023

@dain our usecase is we use presto-gateway to load-balance and front multiple trino clusters. we divide them into groups and would like to be able to use the trino-cli to issue queries to a specific group of clusters.

I understand presto-gateway isn't core trino, but it is a fairly used system and more importantly this design pattern of having a gateway/load-balancer to allow for blue/green or rolling deployments of trino without causing downtime is necessary for us (and many others I'd imagine).

We'd like all our tooling that issues requests to trino (including the trino-cli) to use this gateway and to be able to select a specific group of clusters.

how would you suggest this be approached? should we modify presto-gateway to use a specific existing HTTP API client http header ? the only i see that is somewhat a candidate is X-Trino-Client-Tags and even that.. feels like overloading it for a different purpose

@Pluies
Copy link
Contributor Author

Pluies commented Feb 23, 2023

Especially as Trino's own website lists the presto-gateway in its list of resources, so it would make sense (imho!) to be able to support it from the official CLI 🙏

Copy link
Member

@mosabua mosabua left a comment

Choose a reason for hiding this comment

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

Docs need an example

@rwilliams-r7
Copy link

Is this PR dead or will it make it into the code base?

@mosabua
Copy link
Member

mosabua commented Aug 10, 2023

Is this PR dead or will it make it into the code base?

Currently that depends on @Pluies to update and resolve the conflicts. Subsequently it can be reviewed again.

@Pluies
Copy link
Contributor Author

Pluies commented Aug 11, 2023

@mosabua thanks for the ping, this was flying under my radar - updating now!

Adds an --extra-header flag to the Trino CLI to allow for passing
arbitrary HTTP headers to Trino requests.
@Pluies Pluies force-pushed the trino-cli-headers branch from 0339741 to f9d15ce Compare August 11, 2023 15:14
@Pluies
Copy link
Contributor Author

Pluies commented Aug 11, 2023

PR updated and ready for re-review 👍

@mosabua , there's an example in docs/src/main/sphinx/client/cli.md, do you have another thing in mind for documentation?

@Pluies Pluies changed the title Trino CLI: support --extra-headers parameter Trino CLI: support --extra-header parameter Aug 11, 2023
@mosabua
Copy link
Member

mosabua commented Aug 11, 2023

@electrum @dain @nineinchnick - can we decide on a direction for this. Does it maybe fit in given that we are working towards trino-gateway ?

@nineinchnick
Copy link
Member

@msf could you suggest a name for a new header to be used for routing?

@msf
Copy link

msf commented Aug 30, 2023

@msf could you suggest a name for a new header to be used for routing?

I would suggest X-Trino-Routing-Group, like mentioned above, which is already used by: https://github.com/trinodb/trino-gateway and other open source projects: https://github.com/search?q=X-Trino-Routing-Group&type=code

@Chaho12

This comment was marked as resolved.

@Chaho12
Copy link
Member

Chaho12 commented Sep 26, 2023

FYI, I just tested the approach of using X-Trino-Client-Tags with trino-gateway which works brilliantly so either way works :)
Gateway provides routing-rules engine option for those circumstance where it is hard to add X-Trino-Routing-Group request header (JDBC, Trino CLI etc.)

@patrickdemers6
Copy link

I opened a similar change in trinodb/trino-go-client#91 and was pointed to this PR.

Depending on the environment and other systems at play, custom headers are a go-to way for passing information between systems. I have use cases for passing an Authorization header with each request, as well as other random headers such as transaction ID and trace ID. I would love to see this happen as it opens many doors for developers with little downside.

Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Jan 17, 2024
@patrickdemers6
Copy link

@bitsondatadev @colebow @mosabua Any chance the team at Trino can get some eyes on this?

Copy link

github-actions bot commented Mar 1, 2024

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Mar 1, 2024
@mosabua mosabua requested a review from electrum March 1, 2024 18:29
@github-actions github-actions bot removed the stale label Mar 4, 2024
Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Mar 26, 2024
@mosabua
Copy link
Member

mosabua commented Mar 27, 2024

I requested a review/decision on next steps from @electrum

@github-actions github-actions bot removed the stale label Mar 28, 2024
Copy link

This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua

@github-actions github-actions bot added the stale label Apr 19, 2024
Copy link

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 10, 2024
@mosabua mosabua reopened this May 26, 2024
@mosabua mosabua assigned mosabua and electrum and unassigned mosabua May 26, 2024
@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 26, 2024
@dprophet
Copy link
Contributor

Interesting. Yet another feature I need. @mosabua

@wendigo
Copy link
Contributor

wendigo commented Oct 23, 2024

@Pluies can you rebase this PR? I'll take a look :) I've refactored a lot of things around property handling to make these consistent across CLI/JDBC/Client so this will make sure that once you've add extra headers it will be supported there.

@mosabua
Copy link
Member

mosabua commented Oct 23, 2024

Haha @dprophet .. I know .. we will want some sort of generic bucket for more stuff in the protocol. This is in great hands with @wendigo and @Pluies, but please do let us know your use cases so we can take them into account and help with reviews (or telling others to review ;-))

@mosabua
Copy link
Member

mosabua commented Oct 30, 2024

go client and python client already support custom headers, this Pr just catches up the CLI for that. Could @wendigo and @electrum please look at this in general and if this is ok .. can @Pluies rebase?

@mosabua
Copy link
Member

mosabua commented Oct 30, 2024

@mosabua
Copy link
Member

mosabua commented Oct 30, 2024

Maybe we also have to add this to the JDBC driver

@Chaho12
Copy link
Member

Chaho12 commented Oct 30, 2024

oops manfred, I shared wrong line. here is the actual logic that checks if header args is passed on and starts with X-Trino, to save it to the http.Header.
https://github.com/trinodb/trino-go-client/blob/master/trino/trino.go#L934-L941

e.g. rows, err := db.Query("SELECT current_user", sql.Named("X-Trino-User", string("TestUser"))) would set X-Trino-User header with value of 'TestUser'

so here we can set `sql.Named('X-Trino-Routing-Group', 'groupLarge') to set trino routing group large

@mosabua
Copy link
Member

mosabua commented Oct 31, 2024

Thank you @oneonestar .. I think we should figure out how we make this behavior consistent across all the clients .. at least the ones from the trinodb org .. so cli, jdbc, go, js, and python at this stage.

I pinged @wendigo @martint and @electrum so we can discuss as needed and move this forward.

@Pluies
Copy link
Contributor Author

Pluies commented Nov 4, 2024

Sorry I won't have bandwidth to rebase this until mid-December at the least, feel free to take over the PR or close this one and open another more recent one 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed docs stale-ignore Use this label on PRs that should be ignored by the stale bot so they are not flagged or closed.
Development

Successfully merging this pull request may close these issues.