Skip to content

Commit

Permalink
feat(generator): document details about *Client (#7673)
Browse files Browse the repository at this point in the history
Customers often wonder about the performance, thread-safety, and
connection pooling in our `*Client` classes. This changes the generator
to include this information in the generated code.
  • Loading branch information
coryan authored Nov 30, 2021
1 parent 8d5c432 commit b92933b
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 2 deletions.
23 changes: 23 additions & 0 deletions generator/integration_tests/golden/golden_kitchen_sink_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// tokens, OpenID Connect ID tokens, self-signed JSON Web Tokens (JWTs), and
/// more.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class GoldenKitchenSinkClient {
public:
explicit GoldenKitchenSinkClient(std::shared_ptr<GoldenKitchenSinkConnection> connection);
Expand Down
23 changes: 23 additions & 0 deletions generator/integration_tests/golden/golden_thing_admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// databases. It can be also used to create, delete and list backups for a
/// database and to restore from an existing backup.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class GoldenThingAdminClient {
public:
explicit GoldenThingAdminClient(std::shared_ptr<GoldenThingAdminConnection> connection);
Expand Down
26 changes: 25 additions & 1 deletion generator/internal/descriptor_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,31 @@ std::string FormatClassCommentsFromServiceComments(
absl::StrReplaceAll(
ChompByValue(service_source_location.leading_comments),
{{"\n\n", "\n///\n/// "}, {"\n", "\n/// "}}),
"\n///");
R"""(
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///)""");
return absl::StrReplaceAll(doxygen_formatted_comments, {{"/// ", "/// "}});
}

Expand Down
2 changes: 1 addition & 1 deletion generator/internal/descriptor_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ TEST_P(CreateServiceVarsTest, KeySetCorrectly) {
{std::make_pair("product_path", "google/cloud/frobber/")});
auto iter = service_vars_.find(GetParam().first);
EXPECT_TRUE(iter != service_vars_.end());
EXPECT_EQ(iter->second, GetParam().second);
EXPECT_THAT(iter->second, HasSubstr(GetParam().second));
}

INSTANTIATE_TEST_SUITE_P(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/bigquery/bigquery_read_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
///
/// The Read API can be used to read data from BigQuery.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class BigQueryReadClient {
public:
explicit BigQueryReadClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/iam/iam_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// * Check which roles you can grant for a specific resource
/// * Lint, or validate, condition expressions in an IAM policy
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class IAMClient {
public:
explicit IAMClient(std::shared_ptr<IAMConnection> connection);
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/iam/iam_credentials_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// tokens, OpenID Connect ID tokens, self-signed JSON Web Tokens (JWTs), and
/// more.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class IAMCredentialsClient {
public:
explicit IAMCredentialsClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/logging/logging_service_v2_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
///
/// Service for ingesting and querying logs.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class LoggingServiceV2Client {
public:
explicit LoggingServiceV2Client(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/pubsublite/admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// subscriptions, such creating, listing, and deleting topics and
/// subscriptions.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class AdminServiceClient {
public:
explicit AdminServiceClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/secretmanager/secret_manager_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// * [Secret][google.cloud.secretmanager.v1.Secret]
/// * [SecretVersion][google.cloud.secretmanager.v1.SecretVersion]
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class SecretManagerServiceClient {
public:
explicit SecretManagerServiceClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/spanner/admin/database_admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// databases. It can be also used to create, delete and list backups for a
/// database and to restore from an existing backup.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class DatabaseAdminClient {
public:
explicit DatabaseAdminClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/spanner/admin/instance_admin_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// instance resources, fewer resources are available for other
/// databases in that instance, and their performance may suffer.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class InstanceAdminClient {
public:
explicit InstanceAdminClient(
Expand Down
23 changes: 23 additions & 0 deletions google/cloud/tasks/cloud_tasks_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
/// Cloud Tasks allows developers to manage the execution of background
/// work in their applications.
///
/// @par Equality
///
/// Instances of this class created via copy-construction or copy-assignment
/// always compare equal. Instances created with equal
/// `std::shared_ptr<*Connection>` objects compare equal. Objects that compare
/// equal share the same underlying resources.
///
/// @par Performance
///
/// Creating a new instance of this class is a relatively expensive operation,
/// new objects establish new connections to the service. In contrast,
/// copy-construction, move-construction, and the corresponding assignment
/// operations are relatively efficient as the copies share all underlying
/// resources.
///
/// @par Thread Safety
///
/// Concurrent access to different instances of this class, even if they compare
/// equal, is guaranteed to work. Two or more threads operating on the same
/// instance of this class is not guaranteed to work. Since copy-construction
/// and move-construction is a relatively efficient operation, consider using
/// such a copy when using this class from multiple threads.
///
class CloudTasksClient {
public:
explicit CloudTasksClient(std::shared_ptr<CloudTasksConnection> connection);
Expand Down

0 comments on commit b92933b

Please sign in to comment.