Skip to content

Commit

Permalink
refactor(logging): versioned clients (#10926)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc committed Feb 23, 2023
1 parent 8c5eb6a commit 8640260
Show file tree
Hide file tree
Showing 45 changed files with 1,131 additions and 1,003 deletions.
Binary file modified ci/abi-dumps/google_cloud_cpp_logging.expected.abi.dump.gz
Binary file not shown.
4 changes: 3 additions & 1 deletion ci/etc/expected_install_directories
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,10 @@
./include/google/cloud/language/v1/internal
./include/google/cloud/language/v1/mocks
./include/google/cloud/logging
./include/google/cloud/logging/internal
./include/google/cloud/logging/mocks
./include/google/cloud/logging/v2
./include/google/cloud/logging/v2/internal
./include/google/cloud/logging/v2/mocks
./include/google/cloud/managedidentities
./include/google/cloud/managedidentities/internal
./include/google/cloud/managedidentities/mocks
Expand Down
3 changes: 2 additions & 1 deletion generator/generator_config.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,8 @@ service {
# Logging
service {
service_proto_path: "google/logging/v2/logging.proto"
product_path: "google/cloud/logging"
product_path: "google/cloud/logging/v2"
forwarding_product_path: "google/cloud/logging"
initial_copyright_year: "2021"
gen_async_rpcs: ["WriteLogEntries"]
retryable_status_codes: ["kInternal", "kUnavailable"]
Expand Down
41 changes: 34 additions & 7 deletions google/cloud/logging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@ package(default_visibility = ["//visibility:private"])

licenses(["notice"]) # Apache 2.0

load(":google_cloud_cpp_logging.bzl", "google_cloud_cpp_logging_hdrs", "google_cloud_cpp_logging_srcs")
service_dirs = [
"",
"v2/",
]

src_dirs = service_dirs + [d + "internal/" for d in service_dirs]

filegroup(
name = "srcs",
srcs = glob([d + "*.cc" for d in src_dirs]),
)

filegroup(
name = "hdrs",
srcs = glob([d + "*.h" for d in src_dirs]),
)

filegroup(
name = "mocks",
srcs = glob([d + "mocks/*.h" for d in service_dirs]),
)

cc_library(
name = "google_cloud_cpp_logging",
srcs = google_cloud_cpp_logging_srcs,
hdrs = google_cloud_cpp_logging_hdrs,
srcs = [":srcs"],
hdrs = [":hdrs"],
visibility = ["//:__pkg__"],
deps = [
"//:common",
Expand All @@ -30,15 +50,22 @@ cc_library(
],
)

load(":google_cloud_cpp_logging_mocks.bzl", "google_cloud_cpp_logging_mocks_hdrs", "google_cloud_cpp_logging_mocks_srcs")

cc_library(
name = "google_cloud_cpp_logging_mocks",
srcs = google_cloud_cpp_logging_mocks_srcs,
hdrs = google_cloud_cpp_logging_mocks_hdrs,
hdrs = [":mocks"],
visibility = ["//:__pkg__"],
deps = [
":google_cloud_cpp_logging",
"@com_google_googletest//:gtest",
],
)

[cc_test(
name = sample.replace("/", "_").replace(".cc", ""),
srcs = [sample],
tags = ["integration-test"],
deps = [
"//:logging",
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
],
) for sample in glob([d + "samples/*.cc" for d in service_dirs])]
83 changes: 39 additions & 44 deletions google/cloud/logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,35 @@ include(GoogleapisConfig)
set(DOXYGEN_PROJECT_NAME "Google Cloud Logging C++ Client")
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for Google Cloud Logging")
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION}")
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "logging_internal" "logging_testing"
"examples")
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/samples
${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
set(DOXYGEN_EXCLUDE_SYMBOLS "internal")
set(DOXYGEN_EXAMPLE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/quickstart")

unset(mocks_globs)
unset(source_globs)
set(service_dirs "" "v2/")
foreach (dir IN LISTS service_dirs)
string(REPLACE "/" "_" ns "${dir}")
list(APPEND source_globs "${dir}*.h" "${dir}*.cc" "${dir}internal/*")
list(APPEND mocks_globs "${dir}mocks/*.h")
list(APPEND DOXYGEN_EXCLUDE_SYMBOLS "logging_${ns}internal")
if (NOT dir STREQUAL "")
list(APPEND DOXYGEN_EXAMPLE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/${dir}samples")
endif ()
endforeach ()

include(GoogleCloudCppDoxygen)
google_cloud_cpp_doxygen_targets("logging" DEPENDS cloud-docs
google-cloud-cpp::logging_protos)

include(GoogleCloudCppCommon)

# configure_file(version_info.h.in ${CMAKE_CURRENT_SOURCE_DIR}/version_info.h)
add_library(
google_cloud_cpp_logging # cmake-format: sort
internal/logging_service_v2_auth_decorator.cc
internal/logging_service_v2_auth_decorator.h
internal/logging_service_v2_connection_impl.cc
internal/logging_service_v2_connection_impl.h
internal/logging_service_v2_logging_decorator.cc
internal/logging_service_v2_logging_decorator.h
internal/logging_service_v2_metadata_decorator.cc
internal/logging_service_v2_metadata_decorator.h
internal/logging_service_v2_option_defaults.cc
internal/logging_service_v2_option_defaults.h
internal/logging_service_v2_retry_traits.h
internal/logging_service_v2_stub.cc
internal/logging_service_v2_stub.h
internal/logging_service_v2_stub_factory.cc
internal/logging_service_v2_stub_factory.h
internal/logging_service_v2_tracing_connection.cc
internal/logging_service_v2_tracing_connection.h
internal/logging_service_v2_tracing_stub.cc
internal/logging_service_v2_tracing_stub.h
internal/streaming.cc
logging_service_v2_client.cc
logging_service_v2_client.h
logging_service_v2_connection.cc
logging_service_v2_connection.h
logging_service_v2_connection_idempotency_policy.cc
logging_service_v2_connection_idempotency_policy.h
logging_service_v2_options.h)
file(
GLOB source_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${source_globs})
list(SORT source_files)
add_library(google_cloud_cpp_logging ${source_files})
target_include_directories(
google_cloud_cpp_logging
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
Expand All @@ -79,27 +67,27 @@ target_compile_options(google_cloud_cpp_logging

add_library(google-cloud-cpp::logging ALIAS google_cloud_cpp_logging)

# To avoid maintaining the list of files for the library, export them to a .bzl
# file.
include(CreateBazelConfig)
create_bazel_config(google_cloud_cpp_logging YEAR "2021")

# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
# for these, a regular library would not work on macOS (where the library needs
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
# that they need absolute paths for their sources.
file(
GLOB relative_mock_files
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
${mocks_globs})
list(SORT relative_mock_files)
set(mock_files)
foreach (file IN LISTS relative_mock_files)
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
endforeach ()
add_library(google_cloud_cpp_logging_mocks INTERFACE)
target_sources(
google_cloud_cpp_logging_mocks
INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/mocks/mock_logging_service_v2_connection.h)
target_sources(google_cloud_cpp_logging_mocks INTERFACE ${mock_files})
target_link_libraries(
google_cloud_cpp_logging_mocks
INTERFACE google-cloud-cpp::logging GTest::gmock_main GTest::gmock
GTest::gtest)
set_target_properties(google_cloud_cpp_logging_mocks
PROPERTIES EXPORT_NAME google-cloud-cpp::logging_mocks)
create_bazel_config(google_cloud_cpp_logging_mocks YEAR "2021")
target_include_directories(
google_cloud_cpp_logging_mocks
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
Expand Down Expand Up @@ -181,3 +169,10 @@ install(
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_logging-config-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_logging"
COMPONENT google_cloud_cpp_development)

# google-cloud-cpp::logging must be defined before we can add the samples.
foreach (dir IN LISTS service_dirs)
if (BUILD_TESTING AND GOOGLE_CLOUD_CPP_ENABLE_CXX_EXCEPTIONS)
google_cloud_cpp_add_samples_relative("logging" "${dir}samples/")
endif ()
endforeach ()
10 changes: 5 additions & 5 deletions google/cloud/logging/doc/main.dox
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ library. Use the `google::cloud::EndpointOption` when initializing the client
library to change this default.

<!-- inject-endpoint-snippet-start -->
For example, this will override the default endpoint for `logging::LoggingServiceV2Client`:
For example, this will override the default endpoint for `logging_v2::LoggingServiceV2Client`:

@snippet logging_service_v2_client_samples.cc set-client-endpoint

Expand Down Expand Up @@ -138,15 +138,15 @@ can override the default policies.

// <!-- inject-endpoint-pages-start -->

/*! @page logging::LoggingServiceV2Client-endpoint-snippet Override logging::LoggingServiceV2Client Endpoint Configuration
/*! @page logging_v2::LoggingServiceV2Client-endpoint-snippet Override logging_v2::LoggingServiceV2Client Endpoint Configuration

@snippet google/cloud/logging/samples/logging_service_v2_client_samples.cc set-client-endpoint
@snippet google/cloud/logging/v2/samples/logging_service_v2_client_samples.cc set-client-endpoint

*/

/*! @page logging::LoggingServiceV2Client-service-account-snippet Override logging::LoggingServiceV2Client Authentication Defaults
/*! @page logging_v2::LoggingServiceV2Client-service-account-snippet Override logging_v2::LoggingServiceV2Client Authentication Defaults

@snippet google/cloud/logging/samples/logging_service_v2_client_samples.cc with-service-account
@snippet google/cloud/logging/v2/samples/logging_service_v2_client_samples.cc with-service-account

*/
// <!-- inject-endpoint-pages-end -->
50 changes: 0 additions & 50 deletions google/cloud/logging/google_cloud_cpp_logging.bzl

This file was deleted.

24 changes: 0 additions & 24 deletions google/cloud/logging/google_cloud_cpp_logging_mocks.bzl

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "google/cloud/logging/internal/logging_service_v2_stub_factory.h"
#include "google/cloud/logging/logging_service_v2_client.h"
#include "google/cloud/logging/logging_service_v2_options.h"
#include "google/cloud/logging/v2/internal/logging_service_v2_stub_factory.h"
#include "google/cloud/logging/v2/logging_service_v2_client.h"
#include "google/cloud/logging/v2/logging_service_v2_options.h"
#include "google/cloud/common_options.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/log.h"
Expand All @@ -25,7 +25,7 @@

namespace google {
namespace cloud {
namespace logging {
namespace logging_v2 {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace {

Expand Down Expand Up @@ -117,6 +117,6 @@ TEST_F(LoggingIntegrationTest, ListLogsFailure) {

} // namespace
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace logging
} // namespace logging_v2
} // namespace cloud
} // namespace google
Loading

0 comments on commit 8640260

Please sign in to comment.