Skip to content

Conversation

@kylepbit
Copy link

@kylepbit kylepbit commented Nov 2, 2020

PR for https://issues.apache.org/jira/browse/ARROW-10467

Add a CallOption for specifying arbitrary properties as headers for RPC calls.
Add a ServerMiddleware that will intercept and pass the properties to a handler
when registered via the FlightServer builder.

@github-actions
Copy link

github-actions bot commented Nov 2, 2020

@lidavidm
Copy link
Member

lidavidm commented Nov 2, 2020

What do you think about instead exposing headers as key-value metadata directly (on the sending side with a CallOption, on the receiving side via CallContext)? You could even still implement the server side like you've done here, with a standard middleware that can be configured.

@lidavidm
Copy link
Member

lidavidm commented Nov 2, 2020

Ah, I see you want some keys that wouldn't necessarily be valid headers.

@lidavidm
Copy link
Member

lidavidm commented Nov 2, 2020

Just stepping back for some context - what's the use case you have in mind for this?

@kylepbit
Copy link
Author

kylepbit commented Nov 2, 2020

The intent is to be able to provide preferences to requests that would not be part of the actual action. Ex context to run the action in, etc.

@lidavidm
Copy link
Member

lidavidm commented Nov 3, 2020

Ok. I think it'd make more sense to implement better support for headers in general, rather than have an interface to a single hardcoded header in Flight - anything higher-level (such as encoding an options map) can then be implemented in the application. Does that sound reasonable?

@kylepbit
Copy link
Author

kylepbit commented Nov 3, 2020

Yes - do you have suggestions as to how you think that would be best done? Perhaps a CallOption to specify a header and give it a key and value where the value is serializable, and have a method that serializes the value that can be overridden if people wish to specialize? The server could register a set of headers that it would like to receive.

@kylepbit kylepbit changed the title ARROW-10467: [Java] Add the ability to pass arbitrary client properties. ARROW-10467: [Java] Add the ability to pass arbitrary client headers. Nov 4, 2020
/**
* Interface for server side property handling.
*/
public interface ServerHeaderHandler extends Consumer<CallHeaders> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a unit test that demonstrate a sample usage for this handler?

Copy link
Author

Choose a reason for hiding this comment

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

/**
* Middleware that's used to extract and pass properties to the server during requests.
*/
public class ServerHeaderMiddleware implements FlightServerMiddleware {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename ServerHeaderMiddleware to ServerPropertyMiddleware? The current name is a bit too generic.

Copy link
Author

Choose a reason for hiding this comment

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

I think the name is appropriate given that this is intended to handle all headers for calls, which could be considered properties depending on the FlightServer implementation, but not necessarily.

/**
* Interface for server side property handling.
*/
public interface ServerHeaderHandler extends Consumer<CallHeaders> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename ServerHeaderHandler to ServerPropertyHandler? Like ServerHeaderMiddleware, the current name is a too generic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tifflhl's suggestion the name is too generic, would something like ServerPropertyHeaderHandler and ClientPropertyHeaderHandler be more appropriate similar to ClientBearerHeaderHandler.

Copy link
Author

Choose a reason for hiding this comment

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

This is not specific to properties - it's generally for handling all headers so I think the name fits.

public interface FlightConstants {

String SERVICE = "arrow.flight.protocol.FlightService";
String PROPERTY_HEADER = "Arrow-Properties";
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename this to something more specific (HEADERS_KEY?) and make it an instance of FlightServerMiddleware.Key. Let's also change the constant to something that's more clearly namespaced under arrow, e.g. "org.apache.arrow.flight.ServerHeaderHandler".

/**
* Interface for server side property handling.
*/
public interface ServerHeaderHandler extends Consumer<CallHeaders> {
Copy link
Member

Choose a reason for hiding this comment

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

This interface confuses me, as it seems within an RPC handler, there's no way to get the headers associated with that particular call.

Copy link
Author

@kylepbit kylepbit Nov 4, 2020

Choose a reason for hiding this comment

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

Not sure I understand the comment, are you saying you can't correlate the headers that are incoming with the RPC call that generated them?

Copy link
Member

Choose a reason for hiding this comment

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

Yes - within the body of an RPC handler, how do I access the headers that the client sent for that call?


@Test
public void singleProperty() {
final MetadataAdapter headers = new MetadataAdapter(new Metadata());
Copy link
Member

Choose a reason for hiding this comment

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

We probably need a CallHeaders implementation that doesn't come from the flight-grpc package, or there's no way to use HeaderCallOption.

/**
* Interface for server side property handling.
*/
public interface ServerHeaderHandler extends Consumer<CallHeaders> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @tifflhl's suggestion the name is too generic, would something like ServerPropertyHeaderHandler and ClientPropertyHeaderHandler be more appropriate similar to ClientBearerHeaderHandler.

/**
* Set the header handler.
*/
public Builder headerHandler(ServerHeaderHandler headerHandler) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this to propertyHeaderHandler if we decide to rename ServerHeaderHandler
to ServerPropertyHeaderHandler?

Copy link
Author

Choose a reason for hiding this comment

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

As mentioned in another comment, the intent is to handle all headers. You can interpret them as properties, but I think the name is reflective of intent.

@lidavidm
Copy link
Member

lidavidm commented Nov 4, 2020

Just a higher level comment - I see on ARROW-10428 cookie support is being worked on and ARROW-10427 is about session headers. Since cookies are a particular header and sessions are (usually) a particular cookie, is there any interest in making sure all these features work together and are built on top of each other?

headers in FlightClient.

Change how FlightServer accesses headers by requesting the
ServerHeaderMiddleware via the CallContext in the RPC handlers.
@kylepbit
Copy link
Author

kylepbit commented Nov 5, 2020

Regarding the comment about sessions and cookies - yes, there is definite interest in making sure that the work there is building on top of, instead of parallel to, one another.

@lidavidm lidavidm changed the title ARROW-10467: [Java] Add the ability to pass arbitrary client headers. ARROW-10467: [FlightRPC][Java] Add the ability to pass arbitrary client headers. Nov 5, 2020
@kylepbit
Copy link
Author

kylepbit commented Nov 5, 2020

@lidavidm any other comments on this?

Copy link
Member

@lidavidm lidavidm left a comment

Choose a reason for hiding this comment

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

Overall looks good. Two minor comments.

Fix bug trimming values from multi-valued headers when specifying as a HeaderCallOption.
@lidavidm lidavidm closed this in b26478a Nov 6, 2020
@lidavidm
Copy link
Member

lidavidm commented Nov 6, 2020

Thanks @kylepbit!

pribor pushed a commit to GlobalWebIndex/arrow that referenced this pull request Oct 24, 2025
…nt headers.

PR for https://issues.apache.org/jira/browse/ARROW-10467

Add a CallOption for specifying arbitrary properties as headers for RPC calls.
Add a ServerMiddleware that will intercept and pass the properties to a handler
when registered via the FlightServer builder.

Closes apache#8572 from kylepbit/ARROW-10467

Authored-by: Kyle Porter <[email protected]>
Signed-off-by: David Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants