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

feat: adds dynamic routing. #1135

Merged
merged 14 commits into from
Feb 3, 2022
Merged

feat: adds dynamic routing. #1135

merged 14 commits into from
Feb 3, 2022

Conversation

atulep
Copy link
Contributor

@atulep atulep commented Jan 19, 2022

Adds dynamic routing feature.

@atulep atulep requested a review from software-dov January 19, 2022 19:24
@atulep
Copy link
Contributor Author

atulep commented Jan 19, 2022

This PR is almost ready, but misses the following:

  1. Associated changes to ads-templates.
  2. Updated integration golden files.

I will make changes for 1) after I get an approval of the method used in regular templates. As far as 2), I'm currently running into bazel build issues that I need to debug.

Copy link
Contributor

@software-dov software-dov left a comment

Choose a reason for hiding this comment

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

One worry: there are APIs that use separators other than / in their path templates. I think that the logic here may need to support that.

gapic/schema/wrappers.py Outdated Show resolved Hide resolved
Comment on lines 853 to 854
# Only 1 named segment is allowed and so only 1 key.
return list(regex.groupindex)[0] if list(regex.groupindex) else self.field
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: maybe lift list(regex.groupindex) before the conditional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know a good variable name.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about group_names

Args:
path_template (str): A path template corresponding to a resource name.
It can only have 0 or 1 named segments. It can not contain complex resource ID path segments.
See https://google.aip.dev/122 and https://google.aip.dev/client-libraries/4231 for more details.
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe aip/4222 is also relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

assert args[0] == request

_, _, kw = call.mock_calls[0]
# This test doesn't assert anything useful.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we just want to make sure that the metadata is there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, ideally, we want to assert correct x-goog-parameters are set. However, it's impossible to do it since the headers are set using complicated process difficult to mock.

gapic/schema/wrappers.py Show resolved Hide resolved
Comment on lines 97 to 105
([wrappers.RoutingParameter("table_name", "{project_id=projects/*}/instances/*/**")],
RoutingTestRequest(table_name="projects/100/instances/200/tables/300"),
{"project_id": "projects/100"}),
([wrappers.RoutingParameter("table_name", "{project_id=projects/*}/instances/*/**"),
wrappers.RoutingParameter(
"table_name", "projects/*/{instance_id=instances/*}/**"),
],
RoutingTestRequest(table_name="projects/100/instances/200/tables/300"),
{"project_id": "projects/100", "instance_id": "instances/200"})
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a little hard to eyeball parse. Can you reformat it using black?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran black, but it looks like style_check CI test fails. So, looks like the file needs to be formatted using find gapic tests -name "*.py" -not -path 'tests/**/goldens/*' | xargs autopep8 --in-place

Comment on lines +850 to +851
if self.path_template == "":
return self.field
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this code path ever tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the coverage is 100%

@atulep atulep requested a review from software-dov January 25, 2022 19:49
@atulep
Copy link
Contributor Author

atulep commented Jan 25, 2022

there are APIs that use separators other than / in their path templates. I think that the logic here may need to support that.

Can you elaborate? I think path template in routing parameter always uses '/'.

@atulep atulep marked this pull request as ready for review January 25, 2022 19:59
@atulep atulep requested review from a team as code owners January 25, 2022 19:59
gapic/schema/wrappers.py Show resolved Hide resolved
def _convert_to_regex(self, path_template):
if self._how_many_named_segments(path_template) > 1:
# This also takes care of complex patterns (i.e. {foo}~{bar})
raise ValueError("There should be exactly one named segment.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some more context when raising the exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 853 to 854
# Only 1 named segment is allowed and so only 1 key.
return list(regex.groupindex)[0] if list(regex.groupindex) else self.field
Copy link
Contributor

Choose a reason for hiding this comment

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

What about group_names

Comment on lines 302 to 303
assert isinstance(
method.routing_rule.routing_parameters[0], wrappers.RoutingParameter)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this check is necessary; the check above tests equality, which should check the type since you haven't overridden __equal__.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@atulep atulep merged commit 8c191a5 into googleapis:main Feb 3, 2022
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.

2 participants