Skip to content

Conversation

kongweihan
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Rollback plan is reviewed and LGTMed
  • All new data plane features have a completed end to end testing plan

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

@kongweihan kongweihan requested review from a team as code owners October 6, 2025 16:18
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigtable Issues related to the googleapis/java-bigtable API. labels Oct 6, 2025
@kongweihan kongweihan force-pushed the csm-batch-write-flow-control branch 2 times, most recently from 2ca884e to b4006a2 Compare October 6, 2025 16:54
Instant now = Instant.now();

if (now.isBefore(nextTime)) {
bigtableTracer.addBatchWriteFlowControlFactor(cappedFactor, status, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check here that bigtableTracer is not null? I don't think you need status, it doesn't mean anything for this metric? Also the QPS is not updated, do we want to update the metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm good point, I guess in case context.getTracer() instanceof BigtableTracer is false? How do we deal with it now? Looks like we don't log error?

Recall that status is to record to indicate whether the factor is from the server or due to errors. One theory for the original issue was that a bunch of errors results in min_factor and throttles the client. We'd want to confirm that theory and know which error it is in the future.

We want to report this factor distribution even if it's not applied to target QPS, thus the field "applied" in the metric.

Copy link
Contributor

Choose a reason for hiding this comment

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

We skip exporting the tracer if it's not an instance of BigtableTracer ( which should never happen). I think you can add a sanity check for not null.

*
* @param targetQps The new target QPS for the client.
*/
public void setBatchWriteFlowControlTargetQps(double targetQps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@InternalApi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why this and not other methods in this class?

* @param status Status of the request.
* @param applied Whether the factor was actually applied.
*/
public void addBatchWriteFlowControlFactor(double factor, @Nullable Throwable status, boolean applied) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@InternalApi

Aggregation.sum(),
InstrumentType.GAUGE,
"1",
ImmutableSet.<AttributeKey>builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is what you defined on the server side? You shouldn't need the status_key

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm very strange I didn't recall I added this... removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's still here?

Copy link
Contributor

Choose a reason for hiding this comment

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

And it should have method_key

@kongweihan kongweihan force-pushed the csm-batch-write-flow-control branch from b4006a2 to e8a246f Compare October 7, 2025 03:03
Instant now = Instant.now();

if (now.isBefore(nextTime)) {
bigtableTracer.addBatchWriteFlowControlFactor(cappedFactor, status, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

We skip exporting the tracer if it's not an instance of BigtableTracer ( which should never happen). I think you can add a sanity check for not null.

*
* @param targetQps The new target QPS for the client.
*/
public void setBatchWriteFlowControlTargetQps(double targetQps) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add @InternalApi annotation here and the other method.

static final AttributeKey<String> METHOD_KEY = AttributeKey.stringKey("method");
static final AttributeKey<String> STATUS_KEY = AttributeKey.stringKey("status");
static final AttributeKey<String> CLIENT_UID_KEY = AttributeKey.stringKey("client_uid");
static final AttributeKey<Boolean> APPLIED_KEY = AttributeKey.booleanKey("applied");
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe rename it to BATCH_WRITE_QPS_APPLIED_KEY

Aggregation.sum(),
InstrumentType.GAUGE,
"1",
ImmutableSet.<AttributeKey>builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build());
Copy link
Contributor

Choose a reason for hiding this comment

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

It's still here?

"1",
ImmutableSet.<AttributeKey>builder()
.addAll(COMMON_ATTRIBUTES)
.add(STREAMING_KEY, STATUS_KEY)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right, this should be APPLIED_KEY, STATUS_KEY and METHOD_KEY

Aggregation.sum(),
InstrumentType.GAUGE,
"1",
ImmutableSet.<AttributeKey>builder().addAll(COMMON_ATTRIBUTES).add(STATUS_KEY).build());
Copy link
Contributor

Choose a reason for hiding this comment

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

And it should have method_key

}

private void updateQps(double factor, Duration period) {
private void updateQps(double factor, Duration period, @Nullable Throwable t) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe instead of throwable pass in the status. So you don't need to do the null check, you can just have OK status if the update is from a response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But updateQps is used by both onResponseImpl and onErrorImpl

@kongweihan kongweihan force-pushed the csm-batch-write-flow-control branch from e8a246f to ae0ed5a Compare October 8, 2025 14:27
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 googleapis/java-bigtable API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants