Skip to content

Commit

Permalink
cleanup(rest): only trace if enabled (#12098)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbolduc authored Jul 14, 2023
1 parent d46495c commit ff1a12b
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions google/cloud/internal/curl_rest_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "google/cloud/internal/curl_options.h"
#include "google/cloud/internal/curl_rest_response.h"
#include "google/cloud/internal/oauth2_google_credentials.h"
#include "google/cloud/internal/opentelemetry.h"
#include "google/cloud/internal/tracing_rest_client.h"
#include "google/cloud/internal/unified_rest_credentials.h"
#include "absl/strings/match.h"
Expand Down Expand Up @@ -74,6 +75,16 @@ std::string FormatHostHeaderValue(absl::string_view hostname) {
return std::string(hostname.substr(0, hostname.find('/')));
}

std::unique_ptr<RestClient> MakeRestClient(
std::string endpoint_address, std::shared_ptr<CurlHandleFactory> factory,
Options options) {
bool tracing_enabled = internal::TracingEnabled(options);
std::unique_ptr<RestClient> client = std::make_unique<CurlRestClient>(
std::move(endpoint_address), std::move(factory), std::move(options));
if (tracing_enabled) client = MakeTracingRestClient(std::move(client));
return client;
}

} // namespace

std::string CurlRestClient::HostHeader(Options const& options,
Expand Down Expand Up @@ -223,8 +234,8 @@ StatusOr<std::unique_ptr<RestResponse>> CurlRestClient::Put(
std::unique_ptr<RestClient> MakeDefaultRestClient(std::string endpoint_address,
Options options) {
auto factory = GetDefaultCurlHandleFactory(options);
return MakeTracingRestClient(std::make_unique<CurlRestClient>(
std::move(endpoint_address), std::move(factory), std::move(options)));
return MakeRestClient(std::move(endpoint_address), std::move(factory),
std::move(options));
}

std::unique_ptr<RestClient> MakePooledRestClient(std::string endpoint_address,
Expand All @@ -233,15 +244,11 @@ std::unique_ptr<RestClient> MakePooledRestClient(std::string endpoint_address,
if (options.has<ConnectionPoolSizeOption>()) {
pool_size = options.get<ConnectionPoolSizeOption>();
}
if (pool_size > 0) {
auto pool = std::make_shared<PooledCurlHandleFactory>(pool_size, options);
return MakeTracingRestClient(std::make_unique<CurlRestClient>(
std::move(endpoint_address), std::move(pool), std::move(options)));
}

auto pool = std::make_shared<DefaultCurlHandleFactory>(options);
return MakeTracingRestClient(std::make_unique<CurlRestClient>(
std::move(endpoint_address), std::move(pool), std::move(options)));
auto pool = pool_size > 0 ? std::make_shared<PooledCurlHandleFactory>(
pool_size, options)
: GetDefaultCurlHandleFactory(options);
return MakeRestClient(std::move(endpoint_address), std::move(pool),
std::move(options));
}

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down

0 comments on commit ff1a12b

Please sign in to comment.