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

Support serving of Virtual Host requests #51

Merged
merged 1 commit into from
Jun 6, 2024

Conversation

vagaerg
Copy link
Member

@vagaerg vagaerg commented May 31, 2024

Closes #19

This PR also goes slightly into #37 , by creating an S3RequestInformation record - if @ragnard and @mosiac1 are happy with this choice, I'm glad to add the remaining fields and make the signer use it too.

@cla-bot cla-bot bot added the cla-signed label May 31, 2024
@vagaerg vagaerg force-pushed the vhost-support-outward branch 2 times, most recently from 5989fa2 to cd70a6a Compare June 4, 2024 08:22
return this;
}

public Optional<String> getHostName()
Copy link
Member

Choose a reason for hiding this comment

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

Add @NotNull

{
this.signingController = requireNonNull(signingController, "signingController is null");
this.proxyClient = requireNonNull(proxyClient, "proxyClient is null");
this.restConfig = requireNonNull(restConfig, "restConfig is null");
Copy link
Member

Choose a reason for hiding this comment

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

Because config objects are mutable we don't use them directly. Instead, we assign the value from the config object to a immutable field.


import java.util.Optional;

public class RestConfig
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is only used by TrinoS3ProxyResource I'd rename it to TrinoS3ProxyConfig (and update the config names).

import java.util.Locale;
import java.util.function.BiFunction;

public class MultiMapHelper
Copy link
Member

Choose a reason for hiding this comment

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

👍

import static io.trino.s3.proxy.server.collections.MultiMapHelper.lowercase;
import static java.util.Objects.requireNonNull;

public record S3RequestInformation(String bucketName, String pathInBucket, MultivaluedMap<String, String> requestHeaders, MultivaluedMap<String, String> requestQueryParameters,
Copy link
Member

Choose a reason for hiding this comment

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

S3RequestMetadata?

Copy link
Member Author

Choose a reason for hiding this comment

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

S3RequestInformation does not have the body of the request at present, but I think as part of #37 the request body would also be put into it - so it would not be metadata only.

What do you think about S3Request?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, what about IncomingS3Request?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe ParsedS3Request or InternalS3Request? Or leave it as is is fine too.

Copy link
Member Author

Choose a reason for hiding this comment

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

ParsedS3Request sounds good!

@@ -134,23 +131,4 @@ private static String buildRemoteHost(URI remoteUri)
}
return remoteUri.getHost() + ":" + port;
}

private static String rewriteRequestPath(ContainerRequest request, String bucket)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move buildRemoteHost() too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Where do you think we could move this to? rewriteRequestsPath got removed because the new S3 Metadata record has been parsed enough that we don't need to compute it again.

buildRemoteHost computes the remote host, which doesn't really belong to S3RequestMetadata I don't think.

Happy to create a helper class though, perhaps RemoteRequestUtil?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure actually. Let's leave it.


import java.util.List;

@TrinoS3ProxyTest(modules = {WithConfiguredBuckets.class, WithVirtualHostEnabledProxy.class}, filters = WithVirtualHostEnabledProxy.class)
Copy link
Member

Choose a reason for hiding this comment

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

nit: the testing builder has an addModule method so WithVirtualHostEnabledProxy as a module specified here isn't necessary. Maybe we don't even need modules in TrinoS3ProxyTest and can move everything to filters.

@@ -69,6 +71,7 @@ public static Builder builder()
public static class Builder
{
private final ImmutableSet.Builder<Module> modules = ImmutableSet.builder();
private final ImmutableMap.Builder<String, String> configs = ImmutableMap.builder();
Copy link
Member

Choose a reason for hiding this comment

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

We usually name this properties.

@Randgalt
Copy link
Member

Randgalt commented Jun 4, 2024

@vagaerg reminder to squash the rebase commit please

@vagaerg vagaerg force-pushed the vhost-support-outward branch from cd70a6a to 589e29a Compare June 4, 2024 12:28
{
private Optional<String> hostName = Optional.empty();

@Config("rest.hostname")
Copy link
Member

Choose a reason for hiding this comment

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

Now that the class is renamed, the value should too. maybe s3proxy.hostname

Copy link
Member Author

Choose a reason for hiding this comment

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

I was a bit unsure about this one, as we may have rest and non-rest properties. But we can figure it out later, happy to rename for now

Copy link
Member

@Randgalt Randgalt left a comment

Choose a reason for hiding this comment

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

A few nits/comments, but LGTM

@vagaerg vagaerg force-pushed the vhost-support-outward branch from 589e29a to aaff406 Compare June 5, 2024 09:22
import static io.trino.s3.proxy.server.collections.MultiMapHelper.lowercase;
import static java.util.Objects.requireNonNull;

public record ParsedS3Request(String bucketName, String pathInBucket, MultivaluedMap<String, String> requestHeaders, MultivaluedMap<String, String> requestQueryParameters,
Copy link
Contributor

Choose a reason for hiding this comment

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

some NITs:

we can call this just S3Request, i don't think anything else is using that name. WDYT?

can we have each field on a new line?

Copy link
Member Author

Choose a reason for hiding this comment

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

Refer to #51 (comment) for the name, I originally named this S3RequestInformation, then we discussed S3Request but settled on this.

I don't really have a strong preference between this or S3Request so happy for you & @Randgalt to discuss

Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't have a strong preference, so let's go with this for now!

@vagaerg vagaerg force-pushed the vhost-support-outward branch from aaff406 to d73cba3 Compare June 5, 2024 14:31
@vagaerg vagaerg merged commit f8a3733 into trinodb:main Jun 6, 2024
2 checks passed
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.

Implement support for virtual-host style addressing
3 participants