Skip to content

fix: revise health metrics inflightBytes to become inflightBytesMax - #14613

Open
agrawal-siddharth wants to merge 1 commit into
googleapis:mainfrom
agrawal-siddharth:inflightonly
Open

agrawal-siddharth wants to merge 1 commit into
googleapis:mainfrom
agrawal-siddharth:inflightonly

Conversation

@agrawal-siddharth

Copy link
Copy Markdown
Contributor

No description provided.

@agrawal-siddharth
agrawal-siddharth requested review from a team as code owners October 9, 2026 01:50

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

Copy link
Copy Markdown
Contributor

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 modifies ConnectionWorker to track and evaluate the maximum windowed inflight bytes (windowedInflightBytesMax) instead of the instantaneous inflight bytes during health checks. While the changes correctly update the health check metrics and tests, the review identified critical compilation errors where AtomicLong is passed directly to updateInflightBytesMax instead of calling .get(). Additionally, a thread-safety issue was found where windowedInflightBytesMax is updated without acquiring the required lock.

AppendRequestAndResponse requestWrapper, boolean addToFront) {
this.inflightRequests.incrementAndGet();
this.inflightBytes.addAndGet(requestWrapper.messageSize);
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The method updateInflightBytesMax expects a long primitive argument, but this.inflightBytes is an AtomicLong object. Passing it directly will cause a compilation error. Use this.inflightBytes.get() to retrieve the primitive value.

Suggested change
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes);
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes.get());

requestProfilerHook.startOperation(RequestProfiler.OperationName.WAIT_QUEUE, requestUniqueId);
this.inflightRequests.incrementAndGet();
this.inflightBytes.addAndGet(requestWrapper.messageSize);
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The method updateInflightBytesMax expects a long primitive argument, but this.inflightBytes is an AtomicLong object. Passing it directly will cause a compilation error. Use this.inflightBytes.get() to retrieve the primitive value.

Suggested change
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes);
healthCheckMetrics.updateInflightBytesMax(this.inflightBytes.get());

Comment on lines +344 to +348
void updateInflightBytesMax(long currentInflightBytes) {
if (currentInflightBytes > windowedInflightBytesMax) {
windowedInflightBytesMax = currentInflightBytes;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The field windowedInflightBytesMax is annotated with @GuardedBy("lock"), but updateInflightBytesMax accesses and modifies it without acquiring the lock. This can lead to race conditions and thread-safety issues. In performance-sensitive code, prefer using explicit locks over the 'synchronized' keyword to protect shared state while ensuring thread safety and visibility.

    void updateInflightBytesMax(long currentInflightBytes) {
      lock.lock();
      try {
        if (currentInflightBytes > windowedInflightBytesMax) {
          windowedInflightBytesMax = currentInflightBytes;
        }
      } finally {
        lock.unlock();
      }
    }
References
  1. In performance-sensitive code, prefer using explicit locks over the 'synchronized' keyword to protect shared state while ensuring thread safety and visibility.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant