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

impl(generator): add Start and Await overloads to connections #14348

Merged

Conversation

scotthart
Copy link
Member

@scotthart scotthart commented Jun 18, 2024

part of the work for #7658

This PR adds the connection methods and decorator overrides to create an overload set for each LRO rpc, adding a "Start" method and an "Await" method. A new tag type NoAwaitTag is used to signal a call to the "Start" overload and passing an Operation signals a call to the "Await" overload.

A few Bigtable tests needed their EXPECT_CALL invocations adjusted to remove ambiguities the additional overloads introduced.

The PR is split into multiple commits to separate the generator changes, tests for the golden generated code, and all the generated code updates.


This change is Reviewable

Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 64.75771% with 240 lines in your changes missing coverage. Please review.

Project coverage is 93.09%. Comparing base (514e2bd) to head (269f57b).
Report is 15 commits behind head on main.

Files Patch % Lines
.../internal/golden_thing_admin_tracing_connection.cc 20.00% 56 Missing ⚠️
.../v1/internal/golden_thing_admin_connection_impl.cc 64.00% 45 Missing ⚠️
...nerator/internal/connection_impl_rest_generator.cc 0.00% 32 Missing ⚠️
...n_tests/golden/v1/golden_thing_admin_connection.cc 0.00% 25 Missing ⚠️
...s/golden/v1/internal/request_id_connection_impl.cc 0.00% 25 Missing ⚠️
...nternal/golden_thing_admin_rest_connection_impl.cc 80.00% 20 Missing ⚠️
...olden/v1/internal/request_id_tracing_connection.cc 0.00% 14 Missing ⚠️
...lden/v1/mocks/mock_golden_thing_admin_connection.h 20.00% 8 Missing ⚠️
generator/internal/connection_impl_generator.cc 0.00% 7 Missing ⚠️
...tegration_tests/golden/v1/request_id_connection.cc 0.00% 5 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14348      +/-   ##
==========================================
- Coverage   93.74%   93.09%   -0.66%     
==========================================
  Files        2270     2183      -87     
  Lines      202965   192857   -10108     
==========================================
- Hits       190277   179543   -10734     
- Misses      12688    13314     +626     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

I didn't get very far in the review. My browser keeps crashing when I open the "generated code" commit. Can you put the golden changes in its own commit?

"NAM4",
# Metadata is mispelled in this proto message name found in
# google/cloud/aiplatform/v1/vizier_service.proto
"CheckTrialEarlyStoppingStateMetatdata"
Copy link
Member

Choose a reason for hiding this comment

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

lol

" virtual StatusOr<$longrunning_operation_type$>\n"},
// clang-format on
// TODO(#14344): Remove experimental tag.
{" $method_name$(google::cloud::ExperimentalTag, "
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would omit google::cloud:: from all of these things.

@@ -18,6 +18,7 @@

google_cloud_cpp_common_hdrs = [
"access_token.h",
"await_tag.h",
Copy link
Member

Choose a reason for hiding this comment

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

nit: rename to no_await_tag.h ?

@@ -21,7 +21,9 @@

#include "generator/integration_tests/golden/v1/golden_kitchen_sink_connection_idempotency_policy.h"
#include "generator/integration_tests/golden/v1/internal/golden_kitchen_sink_retry_traits.h"
#include "google/cloud/await_tag.h"
Copy link
Member

Choose a reason for hiding this comment

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

unused?

Copy link
Member Author

@scotthart scotthart left a comment

Choose a reason for hiding this comment

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

Done.

Reviewable status: 0 of 2029 files reviewed, 4 unresolved discussions (waiting on @dbolduc)

Copy link
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

Only nits, and suggestions so approved. The two important things are:

  1. We should consider naming the wait method: Await$method_name$
  2. We should change the OTelScope thingy in the synchronous tracing method.

@@ -52,6 +52,22 @@ GoldenThingAdminConnection::CreateDatabase(
Status(StatusCode::kUnimplemented, "not implemented"));
}

StatusOr<google::longrunning::Operation>
Copy link
Member

Choose a reason for hiding this comment

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

pre-checkers nit: remove space at the start of the line?

@@ -52,6 +52,22 @@ GoldenThingAdminConnection::CreateDatabase(
Status(StatusCode::kUnimplemented, "not implemented"));
}

StatusOr<google::longrunning::Operation>
GoldenThingAdminConnection::CreateDatabase(
google::cloud::ExperimentalTag, google::cloud::NoAwaitTag,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd drop the google::cloud::

@@ -126,6 +126,53 @@ GoldenThingAdminConnectionImpl::CreateDatabase(google::test::admin::database::v1
polling_policy(*current), __func__);
}


Copy link
Member

Choose a reason for hiding this comment

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

nit: extra space

google::cloud::NoAwaitTag, google::test::admin::database::v1::CreateDatabaseRequest const& request) {
auto span = internal::MakeSpan(
"golden_v1::GoldenThingAdminConnection::CreateDatabase");
internal::OTelScope scope(span);
Copy link
Member

Choose a reason for hiding this comment

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

For synchronous calls, it is simpler to use:

opentelemetry::trace::Scope scope(span);

google::longrunning::Operation const& operation) {
auto span = internal::MakeSpan(
"golden_v1::GoldenThingAdminConnection::CreateDatabase");
internal::OTelScope scope(span);
Copy link
Member

Choose a reason for hiding this comment

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

comment: FTR, this OTelScope is necessary.

GoldenThingAdminTracingConnection::UpdateDatabaseDdl(google::cloud::ExperimentalTag,
google::cloud::NoAwaitTag, google::test::admin::database::v1::UpdateDatabaseDdlRequest const& request) {
auto span = internal::MakeSpan(
"golden_v1::GoldenThingAdminConnection::UpdateDatabaseDdl");
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to defer this.

I am noticing that the spans for the three overloads are identical in names and attributes. How will we tell them apart in the trace UI?

I think we would at least want an attribute equivalent of "NoAwaitTag"

auto mock = std::make_shared<MockGoldenThingAdminConnection>();
EXPECT_CALL(*mock, CreateDatabase(_, _, _)).WillOnce([] {
EXPECT_TRUE(ThereIsAnActiveSpan());
EXPECT_TRUE(OTelContextCaptured());
Copy link
Member

Choose a reason for hiding this comment

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

this expectation is only necessary for async operations

EXPECT_EQ(expected_operation.name(), r.name());
google::longrunning::Operation op;
op.set_name(r.name());
op.set_done(true);
Copy link
Member

Choose a reason for hiding this comment

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

comment for myself: I was wondering if we need/want tests for the polling loop side of things? Like, when the operation is not immediately done.

I think no. I think those cases are covered in async_long_running_operation_test.cc. We do not need to recreate the tests for AsyncAwaitLongRunningOperation in the connections.

google::cloud::NoAwaitTag, $request_type$ const& request) {
auto span = internal::MakeSpan(
"$product_namespace$::$connection_class_name$::$method_name$");
internal::OTelScope scope(span);
Copy link
Member

Choose a reason for hiding this comment

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

s/internal::OtelScope/opentelemetry::trace::Scope

What you have works, it just does some unnecessary extra work (duplicating OTel's thread_local state) that we do not need to do in the synchronous case.

" virtual future<Status>\n",
" virtual future<StatusOr<$longrunning_deduced_response_type$>>\n"},
// TODO(#14344): Remove experimental tag.
{" $method_name$(google::cloud::ExperimentalTag,"
Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer to call these things: AwaitCreateFoo(...) or WaitForCreateFoo(...).

It stops being an overload set. I don't think that's bad.

auto operation = CreateFoo(request);
auto foo = CreateFoo(..., *operation);

The second line isn't creating a foo. That already happened. It is waiting on a foo. That is why I like the different name.

It seems super unlikely, but it could open us up to RPC name clashes. If that is the concern, feel free to leave it as is.

Copy link
Member Author

@scotthart scotthart left a comment

Choose a reason for hiding this comment

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

  1. My concern is that method names are defined by the service, not us. While small, we risk future naming collisions.
  2. Fixed.

Reviewable status: 0 of 2029 files reviewed, 13 unresolved discussions (waiting on @dbolduc)


.typos.toml line 67 at r2 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

lol

Done.


generator/integration_tests/golden/v1/golden_thing_admin_connection.cc line 55 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

pre-checkers nit: remove space at the start of the line?

Fixed


generator/integration_tests/golden/v1/golden_thing_admin_connection.cc line 57 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

nit: I'd drop the google::cloud::

Dropped


generator/integration_tests/golden/v1/internal/golden_thing_admin_connection_impl.cc line 129 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

nit: extra space

Fixed


generator/integration_tests/golden/v1/internal/golden_thing_admin_tracing_connection.cc line 58 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

For synchronous calls, it is simpler to use:

opentelemetry::trace::Scope scope(span);

Done.


generator/integration_tests/golden/v1/internal/golden_thing_admin_tracing_connection.cc line 68 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

comment: FTR, this OTelScope is necessary.

Done.


generator/integration_tests/golden/v1/internal/golden_thing_admin_tracing_connection.cc line 92 at r5 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

Feel free to defer this.

I am noticing that the spans for the three overloads are identical in names and attributes. How will we tell them apart in the trace UI?

I think we would at least want an attribute equivalent of "NoAwaitTag"

Created issue #14367


generator/integration_tests/tests/golden_thing_admin_connection_test.cc line 263 at r4 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

comment for myself: I was wondering if we need/want tests for the polling loop side of things? Like, when the operation is not immediately done.

I think no. I think those cases are covered in async_long_running_operation_test.cc. We do not need to recreate the tests for AsyncAwaitLongRunningOperation in the connections.

Done.


generator/integration_tests/tests/golden_thing_admin_tracing_connection_test.cc line 131 at r4 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

this expectation is only necessary for async operations

Removed


generator/internal/connection_generator.cc line 264 at r2 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

nit: I would omit google::cloud:: from all of these things.

Done


generator/internal/connection_generator.cc line 272 at r2 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

I think I prefer to call these things: AwaitCreateFoo(...) or WaitForCreateFoo(...).

It stops being an overload set. I don't think that's bad.

auto operation = CreateFoo(request);
auto foo = CreateFoo(..., *operation);

The second line isn't creating a foo. That already happened. It is waiting on a foo. That is why I like the different name.

It seems super unlikely, but it could open us up to RPC name clashes. If that is the concern, feel free to leave it as is.

Same as previous comment. My concern is that the service defines the methods, not us. While small, there is a risk of a name collision in the future.


generator/internal/tracing_connection_generator.cc line 327 at r2 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

s/internal::OtelScope/opentelemetry::trace::Scope

What you have works, it just does some unnecessary extra work (duplicating OTel's thread_local state) that we do not need to do in the synchronous case.

Done.


google/cloud/google_cloud_cpp_common.bzl line 21 at r2 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

nit: rename to no_await_tag.h ?

Renamed

@scotthart scotthart merged commit c91821e into googleapis:main Jun 25, 2024
66 of 67 checks passed
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