Skip to content

refactor(bigtable): move clone method from Metric to TableSchemaMetric - #16359

Open
scotthart wants to merge 2 commits into
googleapis:mainfrom
scotthart:bigtable_metric_class_hierarchy
Open

refactor(bigtable): move clone method from Metric to TableSchemaMetric#16359
scotthart wants to merge 2 commits into
googleapis:mainfrom
scotthart:bigtable_metric_class_hierarchy

Conversation

@scotthart

Copy link
Copy Markdown
Member

In preparation for adding client schema metrics, we're moving the clone method from Metric to TableSchemaMetric as it's signature is specific to the Labels type being passed. We're also taking this opportunity to reduce the size of the metrics* files by adding table_schema_metrics* files, with client_schema_metrics* files coming soon. To facilitate cloning, we introduced a schema method to indicate what the derived class is when processing a Metric. We could also have used a double dispatch pattern to achieve this, but opted to keep things simpler for the time being.

@scotthart
scotthart requested a review from a team as a code owner August 19, 2026 23:19
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label Aug 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the Bigtable metrics implementation by extracting table-specific schema metrics from metrics.cc and metrics.h into new dedicated files table_schema_metrics.cc and table_schema_metrics.h. It also introduces a MetricSchema enum to categorize metrics and updates the cloning logic to handle table schema metrics specifically. Feedback on the changes highlights several critical issues: a correctness bug in AttemptLatency2 where stale peer info labels are not reset on null peer info, a potential undefined behavior (invalid downcast) in operation_context_test.cc due to incorrect inheritance of MockMetric, violations of the repository style guide regarding the use of auto for protobuf messages and absl::string_view instead of std::string_view, and inconsistent/unsafe usage of .release() when initializing OpenTelemetry shared pointers.

Comment thread google/cloud/bigtable/internal/table_schema_metrics.cc
Comment on lines +123 to +125
class MockMetric : public Metric {
public:
MetricSchema schema() const override { return MetricSchema::kTable; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

MockMetric in operation_context_test.cc inherits from Metric but overrides schema() to return MetricSchema::kTable. This violates the class hierarchy and triggers undefined behavior (invalid downcast) in CloneMetrics (defined in operation_context_factory.cc), which performs a static_cast<TableSchemaMetric const*> on any metric returning MetricSchema::kTable. MockMetric should inherit from TableSchemaMetric instead. Note that you will also need to include 'google/cloud/bigtable/internal/table_schema_metrics.h' at the top of this file.

class MockMetric : public TableSchemaMetric {
 public:

Comment thread google/cloud/bigtable/internal/table_schema_metrics.cc
Comment on lines +35 to +37
#include <string>
#include <unordered_map>
#include <vector>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Add #include <string_view> to support the use of std::string_view in table_schema_metrics.cc.

#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

@scotthart scotthart Aug 19, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better idea, #include <string_view> directly in table_schema_metrics.cc to reduce compile time wherever this .h file is included.

Comment thread google/cloud/bigtable/internal/table_schema_metrics.cc
Comment thread google/cloud/bigtable/internal/table_schema_metrics.cc Outdated
Comment thread google/cloud/bigtable/internal/table_schema_metrics.cc Outdated
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.57143% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.24%. Comparing base (b9dc56c) to head (595d9c0).

Files with missing lines Patch % Lines
...le/cloud/bigtable/internal/table_schema_metrics.cc 98.75% 4 Missing ⚠️
...e/cloud/bigtable/internal/async_bulk_apply_test.cc 0.00% 1 Missing ⚠️
...e/cloud/bigtable/internal/async_row_reader_test.cc 0.00% 1 Missing ⚠️
.../cloud/bigtable/internal/async_row_sampler_test.cc 0.00% 1 Missing ⚠️
...oogle/cloud/bigtable/internal/bulk_mutator_test.cc 0.00% 1 Missing ⚠️
...cloud/bigtable/internal/default_row_reader_test.cc 0.00% 1 Missing ⚠️
...oud/bigtable/internal/operation_context_factory.cc 88.88% 1 Missing ⚠️
.../cloud/bigtable/internal/operation_context_test.cc 0.00% 1 Missing ⚠️
...igtable/internal/partial_result_set_source_test.cc 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16359   +/-   ##
=======================================
  Coverage   92.23%   92.24%           
=======================================
  Files        2227     2229    +2     
  Lines      209573   209659   +86     
=======================================
+ Hits       193309   193395   +86     
  Misses      16264    16264           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was it intentional to move all of the tests? If so, delete the file?

Comment on lines -515 to +518
v2::MutateRowRequest const& request, auto const&) {
v2::MutateRowRequest const& request,
bigtable_internal::OperationContext&) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these edits are distracting

clock_);
}

std::vector<std::shared_ptr<Metric>> CloneMetrics(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at this and not much else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants