Skip to content

impl(bigtable): add ChannelUsage class#16031

Open
scotthart wants to merge 2 commits intogoogleapis:mainfrom
scotthart:bigtable_dynamic_channel_usage
Open

impl(bigtable): add ChannelUsage class#16031
scotthart wants to merge 2 commits intogoogleapis:mainfrom
scotthart:bigtable_dynamic_channel_usage

Conversation

@scotthart
Copy link
Member

This PR adds the ChannelUsage class which tracks RPC usage over the previous minute on a T (typically a Stub class). This will be used as part of the upcoming DynamicChannelPool Bigtable feature.

@scotthart scotthart requested a review from a team as a code owner March 6, 2026 02:16
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the Bigtable API. label Mar 6, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the ChannelUsage class, a foundational component designed to track RPC usage for Bigtable stub classes. This class provides mechanisms to monitor the number of outstanding RPCs and calculate their average over a one-minute window, which is crucial for the upcoming DynamicChannelPool feature. The changes lay the groundwork for more intelligent channel management based on real-time usage metrics.

Highlights

  • New ChannelUsage Class: Introduced the ChannelUsage template class, designed to track RPC activity and manage stub instances for Bigtable clients.
  • RPC Usage Tracking: Implemented methods within ChannelUsage to acquire and release stubs, incrementing and decrementing a counter for outstanding RPCs, and recording timestamped measurements.
  • Usage Metrics Calculation: Added functionality to calculate both the instant number of outstanding RPCs and a weighted average over the previous 60 seconds, crucial for dynamic channel management.
  • Comprehensive Unit Tests: Included a dedicated unit test file (channel_usage_test.cc) to thoroughly validate the behavior and correctness of the ChannelUsage class.
  • Build System Integration: Updated CMake and Bazel build configurations to properly include the new channel_usage.h header and channel_usage_test.cc source file.
Changelog
  • google/cloud/bigtable/CMakeLists.txt
    • Added internal/channel_usage.h to the bigtable library sources.
    • Added internal/channel_usage_test.cc to the bigtable_test sources.
  • google/cloud/bigtable/bigtable_client_unit_tests.bzl
    • Added internal/channel_usage_test.cc to the list of unit tests.
  • google/cloud/bigtable/google_cloud_cpp_bigtable.bzl
    • Added internal/channel_usage.h to the list of Bigtable headers.
  • google/cloud/bigtable/internal/channel_usage.h
    • Added the ChannelUsage template class, including methods for RPC tracking, stub management, and usage calculation.
  • google/cloud/bigtable/internal/channel_usage_test.cc
    • Added unit tests for ChannelUsage functionality, covering stub setting, instant and average RPC counts, error propagation, and weak pointer creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 a new ChannelUsage class for tracking RPC usage, which is a good addition for the upcoming DynamicChannelPool feature. My review focuses on the implementation of this new class. I've identified a potential logic issue in the calculation of the average outstanding RPCs under specific edge conditions and suggest a fix. Additionally, I've pointed out a couple of minor code cleanup opportunities: an unused header and a commented-out line in the test file.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.64%. Comparing base (eea3715) to head (3358ff2).

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16031    +/-   ##
========================================
  Coverage   92.64%   92.64%            
========================================
  Files        2335     2337     +2     
  Lines      214792   214928   +136     
========================================
+ Hits       198986   199120   +134     
- Misses      15806    15808     +2     

☔ View full report in Codecov by Sentry.
📢 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.

Comment on lines +53 to +60
while (iter != measurements_.rend() && iter->timestamp >= window_start) {
double weight =
std::chrono::duration<double>(last_time - iter->timestamp).count();
last_time = iter->timestamp;
sum += iter->outstanding_rpcs * weight;
total_weight += weight;
++iter;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible for all items in measurements_ to be older than window_start? If so, we'd be returning sum=0, but that may not be correctly representing the outstanding rpcs, right? Also, in that case, would erasing the measurements_ be desirable? I'm thinking that may drop the active RPC count.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added logic to always keep an old measurement in the deque. This enables computing any missing time from the window that measurements < 60s do not cover. This includes extreme situations like having a constant outstanding rpc level for an hour. Added expectation to test for this.

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