Skip to content

Commit 0b4c0a0

Browse files
committed
wip
1 parent 26153dd commit 0b4c0a0

30 files changed

Lines changed: 1520 additions & 978 deletions

ci/cloudbuild/builds/observability.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ chmod +x /tmp/observability_integration_test-dynamic-pool
159159
TEST_EXIT_CODE=0
160160
161161
echo "Running observability_integration_test-default..."
162+
GOOGLE_CLOUD_CPP_BIGTABLE_TESTING_CHANNEL_POOL=static \
162163
/tmp/observability_integration_test-default \
163164
--gtest_output=xml:/tmp/test-default.xml > /tmp/test-default.log 2>&1 || TEST_EXIT_CODE=\$?
164165
165166
echo "Running observability_integration_test-dynamic-pool..."
167+
GOOGLE_CLOUD_CPP_BIGTABLE_TESTING_CHANNEL_POOL=dynamic \
166168
/tmp/observability_integration_test-dynamic-pool \
167169
--gtest_output=xml:/tmp/test-dynamic-pool.xml > /tmp/test-dynamic-pool.log 2>&1 || TEST_EXIT_CODE=\$?
168170

google/cloud/bigtable/internal/async_bulk_apply_test.cc

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -168,40 +168,25 @@ class MockMetric : public Metric {
168168
(const, override));
169169
};
170170

171-
// This class is a vehicle to get a MockMetric into the OperationContext object.
172-
class CloningMetric : public Metric {
173-
public:
174-
explicit CloningMetric(std::unique_ptr<MockMetric> metric)
175-
: metric_(std::move(metric)) {}
176-
std::unique_ptr<Metric> clone(TableResourceLabels const&,
177-
TableDataLabels const&) const override {
178-
return std::move(metric_);
179-
}
180-
181-
private:
182-
mutable std::unique_ptr<MockMetric> metric_;
183-
};
184-
185171
#endif // GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
186172

187173
TEST_F(AsyncBulkApplyTest, Success) {
188174
bigtable::BulkMutation mut(IdempotentMutation("r0"),
189175
IdempotentMutation("r1"));
190176

191177
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
192-
auto mock_metric = std::make_unique<MockMetric>();
178+
auto mock_metric = std::make_shared<MockMetric>();
193179
EXPECT_CALL(*mock_metric, PreCall).Times(1);
194180
EXPECT_CALL(*mock_metric, PostCall).Times(1);
195181
EXPECT_CALL(*mock_metric, OnDone).Times(1);
196182

197-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
198183
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
199184

200185
// Normally std::make_shared would be used here, but some weird type deduction
201186
// is preventing it.
202187
// NOLINTNEXTLINE(modernize-make-shared)
203188
auto operation_context = std::shared_ptr<OperationContext>(
204-
new OperationContext({}, {}, {fake_metric}, clock));
189+
new OperationContext({mock_metric}, clock));
205190
#else
206191
auto operation_context = std::make_shared<OperationContext>();
207192
#endif
@@ -263,19 +248,18 @@ TEST_F(AsyncBulkApplyTest, PartialStreamIsRetried) {
263248
IdempotentMutation("r1"));
264249

265250
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
266-
auto mock_metric = std::make_unique<MockMetric>();
251+
auto mock_metric = std::make_shared<MockMetric>();
267252
EXPECT_CALL(*mock_metric, PreCall).Times(2);
268253
EXPECT_CALL(*mock_metric, PostCall).Times(2);
269254
EXPECT_CALL(*mock_metric, OnDone).Times(1);
270255

271-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
272256
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
273257

274258
// Normally std::make_shared would be used here, but some weird type deduction
275259
// is preventing it.
276260
// NOLINTNEXTLINE(modernize-make-shared)
277261
auto operation_context = std::shared_ptr<OperationContext>(
278-
new OperationContext({}, {}, {fake_metric}, clock));
262+
new OperationContext({mock_metric}, clock));
279263
#else
280264
auto operation_context = std::make_shared<OperationContext>();
281265
#endif
@@ -365,19 +349,18 @@ TEST_F(AsyncBulkApplyTest, IdempotentMutationPolicy) {
365349
NonIdempotentMutation("fail-with-transient-error"));
366350

367351
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
368-
auto mock_metric = std::make_unique<MockMetric>();
352+
auto mock_metric = std::make_shared<MockMetric>();
369353
EXPECT_CALL(*mock_metric, PreCall).Times(2);
370354
EXPECT_CALL(*mock_metric, PostCall).Times(2);
371355
EXPECT_CALL(*mock_metric, OnDone).Times(1);
372356

373-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
374357
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
375358

376359
// Normally std::make_shared would be used here, but some weird type deduction
377360
// is preventing it.
378361
// NOLINTNEXTLINE(modernize-make-shared)
379362
auto operation_context = std::shared_ptr<OperationContext>(
380-
new OperationContext({}, {}, {fake_metric}, clock));
363+
new OperationContext({mock_metric}, clock));
381364
#else
382365
auto operation_context = std::make_shared<OperationContext>();
383366
#endif
@@ -513,19 +496,18 @@ TEST_F(AsyncBulkApplyTest, RetryInfoHeeded) {
513496
bigtable::BulkMutation mut(IdempotentMutation("r0"));
514497

515498
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
516-
auto mock_metric = std::make_unique<MockMetric>();
499+
auto mock_metric = std::make_shared<MockMetric>();
517500
EXPECT_CALL(*mock_metric, PreCall).Times(2);
518501
EXPECT_CALL(*mock_metric, PostCall).Times(2);
519502
EXPECT_CALL(*mock_metric, OnDone).Times(1);
520503

521-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
522504
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
523505

524506
// Normally std::make_shared would be used here, but some weird type deduction
525507
// is preventing it.
526508
// NOLINTNEXTLINE(modernize-make-shared)
527509
auto operation_context = std::shared_ptr<OperationContext>(
528-
new OperationContext({}, {}, {fake_metric}, clock));
510+
new OperationContext({mock_metric}, clock));
529511
#else
530512
auto operation_context = std::make_shared<OperationContext>();
531513
#endif
@@ -586,19 +568,18 @@ TEST_F(AsyncBulkApplyTest, RetryInfoIgnored) {
586568
bigtable::BulkMutation mut(IdempotentMutation("r0"));
587569

588570
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
589-
auto mock_metric = std::make_unique<MockMetric>();
571+
auto mock_metric = std::make_shared<MockMetric>();
590572
EXPECT_CALL(*mock_metric, PreCall).Times(1);
591573
EXPECT_CALL(*mock_metric, PostCall).Times(1);
592574
EXPECT_CALL(*mock_metric, OnDone).Times(1);
593575

594-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
595576
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
596577

597578
// Normally std::make_shared would be used here, but some weird type deduction
598579
// is preventing it.
599580
// NOLINTNEXTLINE(modernize-make-shared)
600581
auto operation_context = std::shared_ptr<OperationContext>(
601-
new OperationContext({}, {}, {fake_metric}, clock));
582+
new OperationContext({mock_metric}, clock));
602583
#else
603584
auto operation_context = std::make_shared<OperationContext>();
604585
#endif
@@ -688,19 +669,18 @@ TEST_F(AsyncBulkApplyTest, CancelAfterSuccess) {
688669
promise<std::optional<v2::MutateRowsResponse>> p;
689670

690671
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
691-
auto mock_metric = std::make_unique<MockMetric>();
672+
auto mock_metric = std::make_shared<MockMetric>();
692673
EXPECT_CALL(*mock_metric, PreCall).Times(1);
693674
EXPECT_CALL(*mock_metric, PostCall).Times(1);
694675
EXPECT_CALL(*mock_metric, OnDone).Times(1);
695676

696-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
697677
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
698678

699679
// Normally std::make_shared would be used here, but some weird type deduction
700680
// is preventing it.
701681
// NOLINTNEXTLINE(modernize-make-shared)
702682
auto operation_context = std::shared_ptr<OperationContext>(
703-
new OperationContext({}, {}, {fake_metric}, clock));
683+
new OperationContext({mock_metric}, clock));
704684
#else
705685
auto operation_context = std::make_shared<OperationContext>();
706686
#endif
@@ -764,19 +744,18 @@ TEST_F(AsyncBulkApplyTest, CancelMidStream) {
764744
promise<std::optional<v2::MutateRowsResponse>> p;
765745

766746
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
767-
auto mock_metric = std::make_unique<MockMetric>();
747+
auto mock_metric = std::make_shared<MockMetric>();
768748
EXPECT_CALL(*mock_metric, PreCall).Times(1);
769749
EXPECT_CALL(*mock_metric, PostCall).Times(1);
770750
EXPECT_CALL(*mock_metric, OnDone).Times(1);
771751

772-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
773752
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
774753

775754
// Normally std::make_shared would be used here, but some weird type deduction
776755
// is preventing it.
777756
// NOLINTNEXTLINE(modernize-make-shared)
778757
auto operation_context = std::shared_ptr<OperationContext>(
779-
new OperationContext({}, {}, {fake_metric}, clock));
758+
new OperationContext({mock_metric}, clock));
780759
#else
781760
auto operation_context = std::make_shared<OperationContext>();
782761
#endif

google/cloud/bigtable/internal/async_row_reader_test.cc

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,26 @@ class MockMetric : public Metric {
120120
(const, override));
121121
};
122122

123-
// This class is a vehicle to get a MockMetric into the OperationContext object.
124-
class CloningMetric : public Metric {
125-
public:
126-
explicit CloningMetric(std::unique_ptr<MockMetric> metric)
127-
: metric_(std::move(metric)) {}
128-
std::unique_ptr<Metric> clone(TableResourceLabels const&,
129-
TableDataLabels const&) const override {
130-
return std::move(metric_);
131-
}
132-
133-
private:
134-
mutable std::unique_ptr<MockMetric> metric_;
135-
};
136-
137123
#endif // GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
138124
/// @test Verify that successfully reading rows works.
139125
TEST_F(AsyncRowReaderTest, Success) {
140126
CompletionQueue cq;
141127

142128
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
143-
auto mock_metric = std::make_unique<MockMetric>();
129+
auto mock_metric = std::make_shared<MockMetric>();
144130
EXPECT_CALL(*mock_metric, PreCall).Times(1);
145131
EXPECT_CALL(*mock_metric, PostCall).Times(1);
146132
EXPECT_CALL(*mock_metric, OnDone).Times(1);
147133
EXPECT_CALL(*mock_metric, ElementRequest).Times(3);
148134
EXPECT_CALL(*mock_metric, ElementDelivery).Times(3);
149135

150-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
151136
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
152137

153138
// Normally std::make_shared would be used here, but some weird type deduction
154139
// is preventing it.
155140
// NOLINTNEXTLINE(modernize-make-shared)
156141
auto operation_context = std::shared_ptr<OperationContext>(
157-
new OperationContext({}, {}, {fake_metric}, clock));
142+
new OperationContext({mock_metric}, clock));
158143
#else
159144
auto operation_context = std::make_shared<OperationContext>();
160145
#endif
@@ -239,21 +224,20 @@ TEST_F(AsyncRowReaderTest, SuccessDelayedFuture) {
239224
CompletionQueue cq;
240225

241226
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
242-
auto mock_metric = std::make_unique<MockMetric>();
227+
auto mock_metric = std::make_shared<MockMetric>();
243228
EXPECT_CALL(*mock_metric, PreCall).Times(1);
244229
EXPECT_CALL(*mock_metric, PostCall).Times(1);
245230
EXPECT_CALL(*mock_metric, OnDone).Times(1);
246231
EXPECT_CALL(*mock_metric, ElementRequest).Times(3);
247232
EXPECT_CALL(*mock_metric, ElementDelivery).Times(3);
248233

249-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
250234
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
251235

252236
// Normally std::make_shared would be used here, but some weird type deduction
253237
// is preventing it.
254238
// NOLINTNEXTLINE(modernize-make-shared)
255239
auto operation_context = std::shared_ptr<OperationContext>(
256-
new OperationContext({}, {}, {fake_metric}, clock));
240+
new OperationContext({mock_metric}, clock));
257241
#else
258242
auto operation_context = std::make_shared<OperationContext>();
259243
#endif
@@ -332,21 +316,20 @@ TEST_F(AsyncRowReaderTest, SuccessDelayedFuture) {
332316
TEST_F(AsyncRowReaderTest, ResponseInMultipleChunks) {
333317
CompletionQueue cq;
334318
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
335-
auto mock_metric = std::make_unique<MockMetric>();
319+
auto mock_metric = std::make_shared<MockMetric>();
336320
EXPECT_CALL(*mock_metric, PreCall).Times(1);
337321
EXPECT_CALL(*mock_metric, PostCall).Times(1);
338322
EXPECT_CALL(*mock_metric, OnDone).Times(1);
339323
EXPECT_CALL(*mock_metric, ElementRequest).Times(1);
340324
EXPECT_CALL(*mock_metric, ElementDelivery).Times(1);
341325

342-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
343326
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
344327

345328
// Normally std::make_shared would be used here, but some weird type deduction
346329
// is preventing it.
347330
// NOLINTNEXTLINE(modernize-make-shared)
348331
auto operation_context = std::shared_ptr<OperationContext>(
349-
new OperationContext({}, {}, {fake_metric}, clock));
332+
new OperationContext({mock_metric}, clock));
350333
#else
351334
auto operation_context = std::make_shared<OperationContext>();
352335
#endif
@@ -405,21 +388,20 @@ TEST_F(AsyncRowReaderTest, ResponseInMultipleChunks) {
405388
TEST_F(AsyncRowReaderTest, ParserEofFailsOnUnfinishedRow) {
406389
CompletionQueue cq;
407390
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
408-
auto mock_metric = std::make_unique<MockMetric>();
391+
auto mock_metric = std::make_shared<MockMetric>();
409392
EXPECT_CALL(*mock_metric, PreCall).Times(1);
410393
EXPECT_CALL(*mock_metric, PostCall).Times(1);
411394
EXPECT_CALL(*mock_metric, OnDone).Times(1);
412395
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
413396
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);
414397

415-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
416398
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
417399

418400
// Normally std::make_shared would be used here, but some weird type deduction
419401
// is preventing it.
420402
// NOLINTNEXTLINE(modernize-make-shared)
421403
auto operation_context = std::shared_ptr<OperationContext>(
422-
new OperationContext({}, {}, {fake_metric}, clock));
404+
new OperationContext({mock_metric}, clock));
423405
#else
424406
auto operation_context = std::make_shared<OperationContext>();
425407
#endif
@@ -477,21 +459,20 @@ TEST_F(AsyncRowReaderTest, ParserEofFailsOnUnfinishedRow) {
477459
TEST_F(AsyncRowReaderTest, ParserEofDoesntFailOnUnfinishedRowIfRowLimit) {
478460
CompletionQueue cq;
479461
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
480-
auto mock_metric = std::make_unique<MockMetric>();
462+
auto mock_metric = std::make_shared<MockMetric>();
481463
EXPECT_CALL(*mock_metric, PreCall).Times(1);
482464
EXPECT_CALL(*mock_metric, PostCall).Times(1);
483465
EXPECT_CALL(*mock_metric, OnDone).Times(1);
484466
EXPECT_CALL(*mock_metric, ElementRequest).Times(1);
485467
EXPECT_CALL(*mock_metric, ElementDelivery).Times(1);
486468

487-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
488469
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
489470

490471
// Normally std::make_shared would be used here, but some weird type deduction
491472
// is preventing it.
492473
// NOLINTNEXTLINE(modernize-make-shared)
493474
auto operation_context = std::shared_ptr<OperationContext>(
494-
new OperationContext({}, {}, {fake_metric}, clock));
475+
new OperationContext({mock_metric}, clock));
495476
#else
496477
auto operation_context = std::make_shared<OperationContext>();
497478
#endif
@@ -555,21 +536,20 @@ TEST_F(AsyncRowReaderTest, ParserEofDoesntFailOnUnfinishedRowIfRowLimit) {
555536
TEST_F(AsyncRowReaderTest, PermanentFailure) {
556537
CompletionQueue cq;
557538
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
558-
auto mock_metric = std::make_unique<MockMetric>();
539+
auto mock_metric = std::make_shared<MockMetric>();
559540
EXPECT_CALL(*mock_metric, PreCall).Times(1);
560541
EXPECT_CALL(*mock_metric, PostCall).Times(1);
561542
EXPECT_CALL(*mock_metric, OnDone).Times(1);
562543
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
563544
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);
564545

565-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
566546
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
567547

568548
// Normally std::make_shared would be used here, but some weird type deduction
569549
// is preventing it.
570550
// NOLINTNEXTLINE(modernize-make-shared)
571551
auto operation_context = std::shared_ptr<OperationContext>(
572-
new OperationContext({}, {}, {fake_metric}, clock));
552+
new OperationContext({mock_metric}, clock));
573553
#else
574554
auto operation_context = std::make_shared<OperationContext>();
575555
#endif
@@ -627,21 +607,20 @@ TEST_F(AsyncRowReaderTest, RetryPolicyExhausted) {
627607
});
628608
CompletionQueue cq(mock_cq);
629609
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
630-
auto mock_metric = std::make_unique<MockMetric>();
610+
auto mock_metric = std::make_shared<MockMetric>();
631611
EXPECT_CALL(*mock_metric, PreCall).Times(kNumRetries + 1);
632612
EXPECT_CALL(*mock_metric, PostCall).Times(kNumRetries + 1);
633613
EXPECT_CALL(*mock_metric, OnDone).Times(1);
634614
EXPECT_CALL(*mock_metric, ElementRequest).Times(0);
635615
EXPECT_CALL(*mock_metric, ElementDelivery).Times(0);
636616

637-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
638617
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
639618

640619
// Normally std::make_shared would be used here, but some weird type deduction
641620
// is preventing it.
642621
// NOLINTNEXTLINE(modernize-make-shared)
643622
auto operation_context = std::shared_ptr<OperationContext>(
644-
new OperationContext({}, {}, {fake_metric}, clock));
623+
new OperationContext({mock_metric}, clock));
645624
#else
646625
auto operation_context = std::make_shared<OperationContext>();
647626
#endif
@@ -793,21 +772,20 @@ TEST_F(AsyncRowReaderTest, RetrySkipsReadRows) {
793772
});
794773
CompletionQueue cq(mock_cq);
795774
#ifdef GOOGLE_CLOUD_CPP_BIGTABLE_WITH_OTEL_METRICS
796-
auto mock_metric = std::make_unique<MockMetric>();
775+
auto mock_metric = std::make_shared<MockMetric>();
797776
EXPECT_CALL(*mock_metric, PreCall).Times(2);
798777
EXPECT_CALL(*mock_metric, PostCall).Times(2);
799778
EXPECT_CALL(*mock_metric, OnDone).Times(1);
800779
EXPECT_CALL(*mock_metric, ElementRequest).Times(2);
801780
EXPECT_CALL(*mock_metric, ElementDelivery).Times(2);
802781

803-
auto fake_metric = std::make_shared<CloningMetric>(std::move(mock_metric));
804782
auto clock = std::make_shared<testing_util::FakeSteadyClock>();
805783

806784
// Normally std::make_shared would be used here, but some weird type deduction
807785
// is preventing it.
808786
// NOLINTNEXTLINE(modernize-make-shared)
809787
auto operation_context = std::shared_ptr<OperationContext>(
810-
new OperationContext({}, {}, {fake_metric}, clock));
788+
new OperationContext({mock_metric}, clock));
811789
#else
812790
auto operation_context = std::make_shared<OperationContext>();
813791
#endif

0 commit comments

Comments
 (0)