Skip to content

impl(bigtable): add directpath metric - #16370

Merged
scotthart merged 4 commits into
googleapis:mainfrom
scotthart:bigtable_dp_diagnostic_metric
Aug 24, 2026
Merged

impl(bigtable): add directpath metric#16370
scotthart merged 4 commits into
googleapis:mainfrom
scotthart:bigtable_dp_diagnostic_metric

Conversation

@scotthart

Copy link
Copy Markdown
Member

This PR adds the client schema metric used to report the result of attempting to use DirectPath.

@scotthart
scotthart requested a review from a team as a code owner August 22, 2026 20:18
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label Aug 22, 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 introduces the DirectAccessCompatibility metric and its associated labels to track Bigtable DirectPath compatibility, and updates MakeClientResourceLabels to extract instance and application profile details from options. Unit tests are also added to verify these changes. The review feedback recommends a performance optimization in IntoLabelMap to avoid unnecessary string copies and allocations on the hot path by directly emplacing labels instead of using a temporary array of structs.

Comment on lines 107 to 119
struct {
std::string key;
std::string value;
} data[] = {
{"ip_preference", d.ip_preference},
{"reason", d.reason},
};

for (auto& [key, value] : data) {
if (filtered_data_labels.find(key) == filtered_data_labels.end()) {
labels.emplace(std::move(key), std::move(value));
}
}

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

Creating a temporary array of structs with std::string members causes unnecessary copies and allocations of d.ip_preference and d.reason on every call to IntoLabelMap, which is on the hot path of recording metrics. Since there are only two labels to process, we can avoid the temporary array, the loop, and any unnecessary string copies by directly checking filtered_data_labels and emplacing the values.

  if (filtered_data_labels.find("ip_preference") == filtered_data_labels.end()) {
    labels.emplace("ip_preference", d.ip_preference);
  }
  if (filtered_data_labels.find("reason") == filtered_data_labels.end()) {
    labels.emplace("reason", d.reason);
  }
References
  1. Scrutinize copies of non-fundamental C++ types. Is it necessary to copy the data? Can we move the data instead? (link)
  2. When using a map with transparent lookups (e.g., absl::flat_hash_map<std::string, ...>), prefer find() over operator[] to avoid constructing a key object on every call. This is often more performant, especially if cache hits are common.

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.

Creation of temp structs removed.

@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.12281% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.27%. Comparing base (30817a8) to head (2eb6e73).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...e/cloud/bigtable/internal/client_schema_metrics.cc 98.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16370      +/-   ##
==========================================
+ Coverage   92.26%   92.27%   +0.01%     
==========================================
  Files        2239     2239              
  Lines      210719   210816      +97     
==========================================
+ Hits       194412   194535     +123     
+ Misses      16307    16281      -26     

☔ 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.


LabelMap IntoLabelMap(ClientResourceLabels const& r,
DirectAccessCompatibilityLabels const& d,
std::set<std::string> const& filtered_data_labels = {});

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.

nit: avoid default params for internal functions

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.

Done. A follow-up PR will update the .md files to help catch and prevent this type of style violation from occurring.

Comment on lines +79 to +81
auto emplace_if_not_filtered = [&](std::string key, std::string value) {
if (filtered_data_labels.find(key) == filtered_data_labels.end()) {
labels.emplace(std::move(key), std::move(value));

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.

optional super nit:

I think if filtered_data_labels is a std::set<std::string, std::less<>> then we can have this fn take std::string_views as arguments, and only allocate the std::string if we need to emplace after the lookup.

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.

Good catch; done.

@scotthart
scotthart merged commit d2bb2bb into googleapis:main Aug 24, 2026
66 of 67 checks passed
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