Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

feat: implement async rest transport constructor#2123

Merged
ohmayr merged 8 commits into
mainfrom
introduce-async-transport
Sep 5, 2024
Merged

feat: implement async rest transport constructor#2123
ohmayr merged 8 commits into
mainfrom
introduce-async-transport

Conversation

@ohmayr

@ohmayr ohmayr commented Sep 1, 2024

Copy link
Copy Markdown
Contributor

This PR introduces an async rest transport with minimal parameters and a kind property. It also sets up the testing infra for async rest i.e:

  • add a new nox session to test async rest transport.
  • updates the github workflow to include the new nox session.
  • adds a list of configurations to run macros against.
  • update the redis golden service yaml file to include the experimental feature flag
  • update the service yaml for showcase within the noxfile for testing the new feature against the added feature flag.

@product-auto-label product-auto-label Bot added size: m Pull request size is medium. size: l Pull request size is large. and removed size: m Pull request size is medium. labels Sep 1, 2024
@ohmayr ohmayr force-pushed the introduce-async-transport branch from 5f258b8 to 9b45d08 Compare September 1, 2024 20:01
@ohmayr ohmayr changed the title initial setup: implement async rest transport constructor setup: implement async rest transport constructor Sep 1, 2024
@ohmayr ohmayr force-pushed the introduce-async-transport branch from 90999f3 to 7d58f1f Compare September 1, 2024 20:44
@ohmayr ohmayr changed the base branch from main to async-rest-initial September 1, 2024 20:46
@ohmayr ohmayr force-pushed the introduce-async-transport branch 2 times, most recently from b90b18f to 7124af4 Compare September 1, 2024 20:52
@ohmayr ohmayr changed the title setup: implement async rest transport constructor feat: implement async rest transport constructor Sep 1, 2024
@ohmayr ohmayr force-pushed the introduce-async-transport branch 5 times, most recently from 097aa19 to 9f9471d Compare September 2, 2024 17:12
@ohmayr ohmayr marked this pull request as ready for review September 3, 2024 17:26
@ohmayr ohmayr requested a review from a team September 3, 2024 17:26
@ohmayr ohmayr force-pushed the introduce-async-transport branch from 9f9471d to f4f941c Compare September 3, 2024 19:48
@ohmayr ohmayr force-pushed the async-rest-initial branch from fbceb22 to dd34d55 Compare September 3, 2024 20:20
@ohmayr ohmayr force-pushed the introduce-async-transport branch 2 times, most recently from 2c28ab3 to 6cad5b9 Compare September 3, 2024 20:33
@ohmayr ohmayr force-pushed the async-rest-initial branch from dd34d55 to aa4bfa6 Compare September 3, 2024 20:35
@ohmayr ohmayr force-pushed the async-rest-initial branch from aa4bfa6 to d9f8d2b Compare September 3, 2024 20:36
@ohmayr ohmayr force-pushed the introduce-async-transport branch from 6cad5b9 to fcc89de Compare September 3, 2024 20:42
Comment thread .github/workflows/tests.yaml Outdated
Comment thread .github/workflows/tests.yaml Outdated
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins]
variant: ['', _alternative_templates, _mixins, _alternative_templates_mixins, "_w_rest_async"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like the previous entries were a comprehensive listing of various combinations (on/off along two axes: alternate_templates, mixins). Now it seems like you're adding another axis, async_rest, so we should have 8 entries to test all combinations. (In other words, with _w_rest_async, what are we using for template type and for mixins?

Ideally, we would have a 2x2x2 matrix here of (template-type, mixins, rest_async). That said, we don't want to get too distracted from the async work right now, so maybe simply a comment about what this variant includes/excludes is fine for now.

Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 Outdated
Comment on lines +70 to +72
{% if rest_async_io_enabled %}
from .transports.rest_asyncio import Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
{% if rest_async_io_enabled %}
from .transports.rest_asyncio import Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}
{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove this condition (and the variable set at the top of this file) for async rest transport once support for it is GA #}
{% if rest_async_io_enabled %}
from .transports.rest_asyncio import Async{{ service.name }}RestTransport
{% endif %}{# if rest_async_io_enabled #}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also use the same format for these GA-TODOs in the other files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed.

{% endif %}
{% if "rest" in opts.transport %}
_transport_registry["rest"] = {{ service.name }}RestTransport
{% if rest_async_io_enabled %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

{# TODO(https://github.com/googleapis/gapic-generator-python/issues/2121): Remove this condition when async rest is GA #}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LOL. GitHub shortened and hyperlinked the full URL I intended here.

Comment on lines +1881 to +1882
{% macro transport_kind_test(service, transport_name) %}
{%- set named_clients = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
{% macro transport_kind_test(service, transport_name) %}
{%- set named_clients = {
{% macro transport_kind_test(service, transport_name) %}
{# Look-up tables for parameter values corresponding to each possible transport-name #}
{%- set named_clients = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I ended up removing this dict since there's only two possible clients that we can have i.e. sync or async. Added a separate macro for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Comment thread noxfile.py
Comment thread noxfile.py Outdated
Comment thread noxfile.py
session, templates="DEFAULT", other_opts: typing.Iterable[str] = (),
include_service_yaml=True,
retry_config=True,
rest_async_io_enabled=False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line should also have a TODO to remove the param once async REST is GA?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed.

Comment thread noxfile.py
Comment thread tests/integration/redis_v1.yaml
Comment on lines +1884 to +1891
{% macro get_client(service, is_async) %}
{{-service.async_client_name if is_async else service.client_name-}}
{% endmacro %}

{% macro transport_kind_test(service, transport_name, is_async) %}
def test_transport_kind_{{transport_name}}():
transport = {{ get_client(service, is_async) }}.get_transport_class("{{transport_name}}")(
credentials={{get_credentials(is_async)}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
{% macro get_client(service, is_async) %}
{{-service.async_client_name if is_async else service.client_name-}}
{% endmacro %}
{% macro transport_kind_test(service, transport_name, is_async) %}
def test_transport_kind_{{transport_name}}():
transport = {{ get_client(service, is_async) }}.get_transport_class("{{transport_name}}")(
credentials={{get_credentials(is_async)}}
{% macro get_client(service, is_async) %}
{{- service.async_client_name if is_async else service.client_name -}}
{% endmacro %}
{% macro transport_kind_test(service, transport_name, is_async) %}
def test_transport_kind_{{ transport_name }}():
transport = {{ get_client(service, is_async) }}.get_transport_class("{{ transport_name }}")(
credentials={{ get_credentials(is_async) }}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed.

Comment thread gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Outdated
Base automatically changed from async-rest-initial to main September 4, 2024 21:16
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 Outdated
Comment thread gapic/templates/tests/unit/gapic/%name_%version/%sub/test_macros.j2 Outdated
Comment thread noxfile.py Outdated
{% endif %}
{% if "rest" in opts.transport %}
_transport_registry["rest"] = {{ service.name }}RestTransport
{% if rest_async_io_enabled %}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LOL. GitHub shortened and hyperlinked the full URL I intended here.

@vchudnov-g vchudnov-g left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for doing this! Looks great!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants