Skip to content

Commit 0bd9521

Browse files
authored
impl(generator): reduce size of non-streaming logging decorators (#13769)
Generated logging decorators for services without streaming (read, write, or bidir) methods never use the `stream_logging_` member, so eliminate it in those cases.
1 parent d05b378 commit 0bd9521

583 files changed

Lines changed: 610 additions & 1455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

generator/integration_tests/golden/v1/internal/golden_kitchen_sink_logging_decorator.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ GoldenKitchenSinkLogging::GoldenKitchenSinkLogging(
3737
std::shared_ptr<GoldenKitchenSinkStub> child,
3838
TracingOptions tracing_options,
3939
std::set<std::string> const& components)
40-
: child_(std::move(child)), tracing_options_(std::move(tracing_options)),
40+
: child_(std::move(child)),
41+
tracing_options_(std::move(tracing_options)),
4142
stream_logging_(components.find("rpc-streams") != components.end()) {}
4243

4344
StatusOr<google::test::admin::database::v1::GenerateAccessTokenResponse>

generator/integration_tests/golden/v1/internal/golden_thing_admin_logging_decorator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3131
GoldenThingAdminLogging::GoldenThingAdminLogging(
3232
std::shared_ptr<GoldenThingAdminStub> child,
3333
TracingOptions tracing_options,
34-
std::set<std::string> const& components)
35-
: child_(std::move(child)), tracing_options_(std::move(tracing_options)),
36-
stream_logging_(components.find("rpc-streams") != components.end()) {}
34+
std::set<std::string> const&)
35+
: child_(std::move(child)),
36+
tracing_options_(std::move(tracing_options)) {}
3737

3838
StatusOr<google::test::admin::database::v1::ListDatabasesResponse>
3939
GoldenThingAdminLogging::ListDatabases(

generator/integration_tests/golden/v1/internal/golden_thing_admin_logging_decorator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class GoldenThingAdminLogging : public GoldenThingAdminStub {
161161
private:
162162
std::shared_ptr<GoldenThingAdminStub> child_;
163163
TracingOptions tracing_options_;
164-
bool stream_logging_;
165164
}; // GoldenThingAdminLogging
166165

167166
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

generator/integration_tests/golden/v1/internal/request_id_logging_decorator.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3131
RequestIdServiceLogging::RequestIdServiceLogging(
3232
std::shared_ptr<RequestIdServiceStub> child,
3333
TracingOptions tracing_options,
34-
std::set<std::string> const& components)
35-
: child_(std::move(child)), tracing_options_(std::move(tracing_options)),
36-
stream_logging_(components.find("rpc-streams") != components.end()) {}
34+
std::set<std::string> const&)
35+
: child_(std::move(child)),
36+
tracing_options_(std::move(tracing_options)) {}
3737

3838
StatusOr<google::test::requestid::v1::Foo>
3939
RequestIdServiceLogging::CreateFoo(

generator/integration_tests/golden/v1/internal/request_id_logging_decorator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class RequestIdServiceLogging : public RequestIdServiceStub {
7676
private:
7777
std::shared_ptr<RequestIdServiceStub> child_;
7878
TracingOptions tracing_options_;
79-
bool stream_logging_;
8079
}; // RequestIdServiceLogging
8180

8281
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

generator/internal/logging_decorator_generator.cc

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ LoggingDecoratorGenerator::LoggingDecoratorGenerator(
3535
service_descriptor, std::move(service_vars),
3636
std::move(service_method_vars), context) {}
3737

38+
bool LoggingDecoratorGenerator::HasStreamingMethod() {
39+
return HasStreamingReadMethod() || HasStreamingWriteMethod() ||
40+
HasBidirStreamingMethod();
41+
}
42+
3843
Status LoggingDecoratorGenerator::GenerateHeader() {
3944
HeaderPrint(CopyrightLicenseFileHeader());
4045
HeaderPrint( // clang-format off
@@ -76,10 +81,12 @@ Status LoggingDecoratorGenerator::GenerateHeader() {
7681
"\n"
7782
" private:\n"
7883
" std::shared_ptr<$stub_class_name$> child_;\n"
79-
" TracingOptions tracing_options_;\n"
80-
" bool stream_logging_;\n"
81-
"}; // $logging_class_name$\n");
84+
" TracingOptions tracing_options_;\n");
8285
// clang-format on
86+
if (HasStreamingMethod()) {
87+
HeaderPrint(" bool stream_logging_;\n");
88+
}
89+
HeaderPrint("}; // $logging_class_name$\n");
8390

8491
HeaderCloseNamespaces();
8592
HeaderPrint("\n#endif // $header_include_guard$\n");
@@ -126,10 +133,22 @@ Status LoggingDecoratorGenerator::GenerateCc() {
126133
"$logging_class_name$::$logging_class_name$(\n"
127134
" std::shared_ptr<$stub_class_name$> child,\n"
128135
" TracingOptions tracing_options,\n"
129-
" std::set<std::string> const& components)\n"
130-
" : child_(std::move(child)), tracing_options_(std::move(tracing_options)),\n"
131-
" stream_logging_(components.find(\"rpc-streams\") != components.end()) {}\n");
136+
" std::set<std::string> const&");
132137
// clang-format on
138+
if (HasStreamingMethod()) {
139+
CcPrint(" components");
140+
}
141+
CcPrint( // clang-format off
142+
")\n"
143+
" : child_(std::move(child)),\n"
144+
" tracing_options_(std::move(tracing_options))");
145+
// clang-format on
146+
if (HasStreamingMethod()) {
147+
CcPrint(
148+
",\n stream_logging_("
149+
"components.find(\"rpc-streams\") != components.end())");
150+
}
151+
CcPrint(" {}\n");
133152

134153
// logging decorator class member methods
135154
for (auto const& method : methods()) {

generator/internal/logging_decorator_generator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class LoggingDecoratorGenerator : public StubGeneratorBase {
4949
LoggingDecoratorGenerator& operator=(LoggingDecoratorGenerator&&) = default;
5050

5151
private:
52+
bool HasStreamingMethod();
5253
Status GenerateHeader() override;
5354
Status GenerateCc() override;
5455
};

google/cloud/accessapproval/v1/internal/access_approval_logging_decorator.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3030

3131
AccessApprovalLogging::AccessApprovalLogging(
3232
std::shared_ptr<AccessApprovalStub> child, TracingOptions tracing_options,
33-
std::set<std::string> const& components)
34-
: child_(std::move(child)),
35-
tracing_options_(std::move(tracing_options)),
36-
stream_logging_(components.find("rpc-streams") != components.end()) {}
33+
std::set<std::string> const&)
34+
: child_(std::move(child)), tracing_options_(std::move(tracing_options)) {}
3735

3836
StatusOr<google::cloud::accessapproval::v1::ListApprovalRequestsResponse>
3937
AccessApprovalLogging::ListApprovalRequests(

google/cloud/accessapproval/v1/internal/access_approval_logging_decorator.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class AccessApprovalLogging : public AccessApprovalStub {
9494
private:
9595
std::shared_ptr<AccessApprovalStub> child_;
9696
TracingOptions tracing_options_;
97-
bool stream_logging_;
9897
}; // AccessApprovalLogging
9998

10099
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/accesscontextmanager/v1/internal/access_context_manager_logging_decorator.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3030

3131
AccessContextManagerLogging::AccessContextManagerLogging(
3232
std::shared_ptr<AccessContextManagerStub> child,
33-
TracingOptions tracing_options, std::set<std::string> const& components)
34-
: child_(std::move(child)),
35-
tracing_options_(std::move(tracing_options)),
36-
stream_logging_(components.find("rpc-streams") != components.end()) {}
33+
TracingOptions tracing_options, std::set<std::string> const&)
34+
: child_(std::move(child)), tracing_options_(std::move(tracing_options)) {}
3735

3836
StatusOr<google::identity::accesscontextmanager::v1::ListAccessPoliciesResponse>
3937
AccessContextManagerLogging::ListAccessPolicies(

0 commit comments

Comments
 (0)