-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat: add custom Azure host/port to support custom blob endpoint #164
Conversation
9a54a02
to
c0ce800
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #164 +/- ##
==========================================
+ Coverage 71.97% 72.44% +0.47%
==========================================
Files 35 35
Lines 3928 4035 +107
==========================================
+ Hits 2827 2923 +96
- Misses 1101 1112 +11 ☔ View full report in Codecov by Sentry. |
2f2c3b9
to
a7ae503
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixup commits should be folded.
Overall LGTM but I agree with Emanuele that commit history could be cleaned up before merging. |
8d91072
to
2e7e68f
Compare
@exg @giacomo-alzetta-aiven thanks! Commits are folded now, have another look. |
rohmu/object_storage/azure.py
Outdated
conn.append(f"EndpointSuffix={endpoint_suffix}") | ||
else: | ||
if not host or not port: | ||
raise InvalidConfigurationError("Custom host and port must be specified together") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to use pydantic validators for custom validation, see https://docs.pydantic.dev/1.10/usage/validators/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Adding this on the latest commit, have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation of azure_cloud
can also be moved in the validator. Also, remember to fold fixup commits before pushing :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can move it to validators as well.
Re: fixups, I prefer to keep them separate for easier review, but can surely rebase/squash once approved if that's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also fine, and I used to recommend that too before. I just find it unnecessary given that GitHub provides the diff between the previous and current branch tip on force push (via the "Compare" button).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if a reviewer marks the files as "viewed" when reviewing GitHub will also show them which files have changed when the PR is updated, so it's not like reviewers are forced to re-read everything to discover what you updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, will keep that in mind.
I've squashed all commits now for this change.
f4e5491
to
9ff51d4
Compare
9a3dd93
to
aee7dee
Compare
rohmu/object_storage/config.py
Outdated
@root_validator | ||
@classmethod | ||
def host_and_port_must_be_set_together(cls, values: Dict[str, Any]) -> Dict[str, Any]: | ||
if "host" in values and "port" in values: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is redundant because the fields have a default value and so they are always present. BTW, another option would be to introduce a HostInfo
model, similar to ProxyInfo
, containing the new fields. This way there would be no need for a custom validator, and it would be more consistent. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixing that on the latest commit.
About HostInfo, I like the idea, but we could do that as a separate refactoring PR as there are many places where this type would fit. At the moment this is consistent with the S3 approach to set custom host/port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I did not realize that this is based on the existing S3 config.
aee7dee
to
e5e4303
Compare
rohmu/object_storage/config.py
Outdated
@root_validator | ||
@classmethod | ||
def host_and_port_must_be_set_together(cls, values: Dict[str, Any]) -> Dict[str, Any]: | ||
if not values["host"] or not values["port"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rejects (existing) configs where host and port are both missing, which is not correct. I think you want
(values["host"] is None) != (values["port"] is None)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, test_azure_config_host_port_set_together
or a similar test should also verify that the valid cases do not raise an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, good catch! I added tests to validate the minimal case and fix this.
e5e4303
to
04fe766
Compare
04fe766
to
579d154
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I will wait @exg review too before merging
if not host and not port: | ||
endpoint_suffix = AZURE_ENDPOINT_SUFFIXES[azure_cloud] | ||
conn.append(f"EndpointSuffix={endpoint_suffix}") | ||
else: | ||
conn.append(f"BlobEndpoint={protocol}://{host}:{port}/{account_name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I guess we could do something like:
if not host and not port: | |
endpoint_suffix = AZURE_ENDPOINT_SUFFIXES[azure_cloud] | |
conn.append(f"EndpointSuffix={endpoint_suffix}") | |
else: | |
conn.append(f"BlobEndpoint={protocol}://{host}:{port}/{account_name}") | |
if not host and not port: | |
endpoint_suffix = AZURE_ENDPOINT_SUFFIXES[azure_cloud] | |
conn.append(f"EndpointSuffix={endpoint_suffix}") | |
elif host and port: | |
conn.append(f"BlobEndpoint={protocol}://{host}:{port}/{account_name}") | |
else: | |
raise ValueError("You must either specify both host and port or neither of them") |
In most cases the AzureTransfer
will be build using the get_transfer
facade where we have the PyDantic validation, but I believe people can still manually create the transfer, so maybe validating this again here is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it is possible to create transfers bypassing the pydantic config models?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just saying that we are not indicating that AzureTransfer
is private, so users could instantiate it directly instead of going through the factory methods that use from_model
to create the instance from the pydantic configuration.
I don't this is a big deal, hence why I class this as nitpicking.
Since we all agree let's merge this. |
About this change - What it does
Adds custom host and port configs to Azure to support custom blob endpoint like Azurite.
Resolves: #163
Why this way
Follow similar approach to S3, to set custom host/port.
Moved conn_string construction out of the initialization to be able to test it.