Skip to content

Commit 0819ec0

Browse files
authored
impl(bigtable): rename RetryContext and support optional otel dep (#15265)
1 parent f74959a commit 0819ec0

19 files changed

+108
-82
lines changed

google/cloud/bigtable/BUILD.bazel

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
1516
load(":bigtable_client_testing.bzl", "bigtable_client_testing_hdrs", "bigtable_client_testing_srcs")
1617
load(":bigtable_client_unit_tests.bzl", "bigtable_client_unit_tests")
1718
load(":google_cloud_cpp_bigtable.bzl", "google_cloud_cpp_bigtable_hdrs", "google_cloud_cpp_bigtable_srcs")
@@ -21,6 +22,16 @@ package(default_visibility = ["//visibility:private"])
2122

2223
licenses(["notice"]) # Apache 2.0
2324

25+
bool_flag(
26+
name = "enable_metrics",
27+
build_setting_default = True,
28+
)
29+
30+
config_setting(
31+
name = "metrics_enabled",
32+
flag_values = {":enable_metrics": "true"},
33+
)
34+
2435
filegroup(
2536
name = "public_hdrs",
2637
srcs = [h for h in google_cloud_cpp_bigtable_hdrs if not h.startswith("internal/")],
@@ -31,6 +42,10 @@ cc_library(
3142
name = "google_cloud_cpp_bigtable",
3243
srcs = google_cloud_cpp_bigtable_srcs,
3344
hdrs = google_cloud_cpp_bigtable_hdrs,
45+
local_defines = select({
46+
":metrics_enabled": ["GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS"],
47+
"//conditions:default": [],
48+
}),
3449
visibility = [
3550
":__subpackages__",
3651
"//:__pkg__",
@@ -45,7 +60,14 @@ cc_library(
4560
"@com_google_googleapis//google/longrunning:longrunning_cc_grpc",
4661
"@com_google_googleapis//google/rpc:error_details_cc_proto",
4762
"@com_github_grpc_grpc//:grpc++",
48-
],
63+
] + select({
64+
":metrics_enabled": [
65+
"//:opentelemetry",
66+
"@io_opentelemetry_cpp//api",
67+
"@io_opentelemetry_cpp//sdk/src/metrics",
68+
],
69+
"//conditions:default": [],
70+
}),
4971
)
5072

5173
filegroup(

google/cloud/bigtable/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ add_library(
195195
internal/logging_data_client.h
196196
internal/mutate_rows_limiter.cc
197197
internal/mutate_rows_limiter.h
198+
internal/operation_context.cc
199+
internal/operation_context.h
198200
internal/prefix_range_end.cc
199201
internal/prefix_range_end.h
200202
internal/rate_limiter.cc
201203
internal/rate_limiter.h
202204
internal/readrowsparser.cc
203205
internal/readrowsparser.h
204-
internal/retry_context.cc
205-
internal/retry_context.h
206206
internal/retry_traits.h
207207
internal/row_reader_impl.h
208208
internal/rpc_policy_parameters.h
@@ -440,9 +440,9 @@ if (BUILD_TESTING)
440440
internal/legacy_row_reader_test.cc
441441
internal/logging_data_client_test.cc
442442
internal/mutate_rows_limiter_test.cc
443+
internal/operation_context_test.cc
443444
internal/prefix_range_end_test.cc
444445
internal/rate_limiter_test.cc
445-
internal/retry_context_test.cc
446446
internal/retry_traits_test.cc
447447
internal/traced_row_reader_test.cc
448448
legacy_table_test.cc

google/cloud/bigtable/bigtable_client_unit_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ bigtable_client_unit_tests = [
6060
"internal/legacy_row_reader_test.cc",
6161
"internal/logging_data_client_test.cc",
6262
"internal/mutate_rows_limiter_test.cc",
63+
"internal/operation_context_test.cc",
6364
"internal/prefix_range_end_test.cc",
6465
"internal/rate_limiter_test.cc",
65-
"internal/retry_context_test.cc",
6666
"internal/retry_traits_test.cc",
6767
"internal/traced_row_reader_test.cc",
6868
"legacy_table_test.cc",

google/cloud/bigtable/google_cloud_cpp_bigtable.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ google_cloud_cpp_bigtable_hdrs = [
9797
"internal/legacy_row_reader.h",
9898
"internal/logging_data_client.h",
9999
"internal/mutate_rows_limiter.h",
100+
"internal/operation_context.h",
100101
"internal/prefix_range_end.h",
101102
"internal/rate_limiter.h",
102103
"internal/readrowsparser.h",
103-
"internal/retry_context.h",
104104
"internal/retry_traits.h",
105105
"internal/row_reader_impl.h",
106106
"internal/rpc_policy_parameters.h",
@@ -199,10 +199,10 @@ google_cloud_cpp_bigtable_srcs = [
199199
"internal/legacy_row_reader.cc",
200200
"internal/logging_data_client.cc",
201201
"internal/mutate_rows_limiter.cc",
202+
"internal/operation_context.cc",
202203
"internal/prefix_range_end.cc",
203204
"internal/rate_limiter.cc",
204205
"internal/readrowsparser.cc",
205-
"internal/retry_context.cc",
206206
"internal/traced_row_reader.cc",
207207
"metadata_update_policy.cc",
208208
"mutation_batcher.cc",

google/cloud/bigtable/internal/async_bulk_apply.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void AsyncBulkApplier::MakeRequest() {
7373
internal::ScopedCallContext scope(call_context_);
7474
context_ = std::make_shared<grpc::ClientContext>();
7575
internal::ConfigureContext(*context_, *call_context_.options);
76-
retry_context_->PreCall(*context_);
76+
operation_context_->PreCall(*context_);
7777

7878
auto self = this->shared_from_this();
7979
PerformAsyncStreamingRead(
@@ -105,7 +105,7 @@ void AsyncBulkApplier::OnFinish(Status const& status) {
105105
return;
106106
}
107107

108-
retry_context_->PostCall(*context_);
108+
operation_context_->PostCall(*context_);
109109
context_.reset();
110110
auto self = this->shared_from_this();
111111
internal::TracedAsyncBackoff(cq_, *call_context_.options, *delay,

google/cloud/bigtable/internal/async_bulk_apply.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "google/cloud/bigtable/internal/bigtable_stub.h"
1919
#include "google/cloud/bigtable/internal/bulk_mutator.h"
20-
#include "google/cloud/bigtable/internal/retry_context.h"
20+
#include "google/cloud/bigtable/internal/operation_context.h"
2121
#include "google/cloud/bigtable/options.h"
2222
#include "google/cloud/bigtable/version.h"
2323
#include "google/cloud/completion_queue.h"
@@ -78,8 +78,8 @@ class AsyncBulkApplier : public std::enable_shared_from_this<AsyncBulkApplier> {
7878
internal::ImmutableOptions options_;
7979
internal::CallContext call_context_;
8080
std::shared_ptr<grpc::ClientContext> context_;
81-
std::shared_ptr<RetryContext> retry_context_ =
82-
std::make_shared<RetryContext>();
81+
std::shared_ptr<OperationContext> operation_context_ =
82+
std::make_shared<OperationContext>();
8383
};
8484

8585
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/bigtable/internal/async_row_reader.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void AsyncRowReader::MakeRequest() {
4747
internal::ScopedCallContext scope(call_context_);
4848
context_ = std::make_shared<grpc::ClientContext>();
4949
internal::ConfigureContext(*context_, *call_context_.options);
50-
retry_context_->PreCall(*context_);
50+
operation_context_->PreCall(*context_);
5151

5252
auto self = this->shared_from_this();
5353
PerformAsyncStreamingRead(
@@ -220,7 +220,7 @@ void AsyncRowReader::OnStreamFinished(Status status) {
220220
TryGiveRowToUser();
221221
return;
222222
}
223-
retry_context_->PostCall(*context_);
223+
operation_context_->PostCall(*context_);
224224
context_.reset();
225225
auto self = this->shared_from_this();
226226
internal::TracedAsyncBackoff(cq_, *call_context_.options, *delay,

google/cloud/bigtable/internal/async_row_reader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "google/cloud/bigtable/filters.h"
1919
#include "google/cloud/bigtable/internal/async_streaming_read.h"
2020
#include "google/cloud/bigtable/internal/bigtable_stub.h"
21+
#include "google/cloud/bigtable/internal/operation_context.h"
2122
#include "google/cloud/bigtable/internal/readrowsparser.h"
22-
#include "google/cloud/bigtable/internal/retry_context.h"
2323
#include "google/cloud/bigtable/options.h"
2424
#include "google/cloud/bigtable/row.h"
2525
#include "google/cloud/bigtable/row_set.h"
@@ -176,8 +176,8 @@ class AsyncRowReader : public std::enable_shared_from_this<AsyncRowReader> {
176176
internal::ImmutableOptions options_;
177177
internal::CallContext call_context_;
178178
std::shared_ptr<grpc::ClientContext> context_;
179-
std::shared_ptr<RetryContext> retry_context_ =
180-
std::make_shared<RetryContext>();
179+
std::shared_ptr<OperationContext> operation_context_ =
180+
std::make_shared<OperationContext>();
181181
};
182182

183183
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

google/cloud/bigtable/internal/async_row_sampler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void AsyncRowSampler::StartIteration() {
6464
internal::ScopedCallContext scope(call_context_);
6565
context_ = std::make_shared<grpc::ClientContext>();
6666
internal::ConfigureContext(*context_, *call_context_.options);
67-
retry_context_->PreCall(*context_);
67+
operation_context_->PreCall(*context_);
6868

6969
auto self = this->shared_from_this();
7070
PerformAsyncStreamingRead<v2::SampleRowKeysResponse>(
@@ -96,7 +96,7 @@ void AsyncRowSampler::OnFinish(Status const& status) {
9696
return;
9797
}
9898

99-
retry_context_->PostCall(*context_);
99+
operation_context_->PostCall(*context_);
100100
context_.reset();
101101
samples_.clear();
102102
auto self = this->shared_from_this();

google/cloud/bigtable/internal/async_row_sampler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "google/cloud/bigtable/completion_queue.h"
1919
#include "google/cloud/bigtable/internal/bigtable_stub.h"
20-
#include "google/cloud/bigtable/internal/retry_context.h"
20+
#include "google/cloud/bigtable/internal/operation_context.h"
2121
#include "google/cloud/bigtable/options.h"
2222
#include "google/cloud/bigtable/row_key_sample.h"
2323
#include "google/cloud/bigtable/version.h"
@@ -70,8 +70,8 @@ class AsyncRowSampler : public std::enable_shared_from_this<AsyncRowSampler> {
7070
internal::ImmutableOptions options_;
7171
internal::CallContext call_context_;
7272
std::shared_ptr<grpc::ClientContext> context_;
73-
std::shared_ptr<RetryContext> retry_context_ =
74-
std::make_shared<RetryContext>();
73+
std::shared_ptr<OperationContext> operation_context_ =
74+
std::make_shared<OperationContext>();
7575
};
7676

7777
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END

0 commit comments

Comments
 (0)