Skip to content

Fix early return in multi-batch metric scraping#1202

Open
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-poll-early-return
Open

Fix early return in multi-batch metric scraping#1202
courageJ wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
courageJ:fix-poll-early-return

Conversation

@courageJ
Copy link
Copy Markdown
Contributor

PR Description: Fix early return in multi-batch metric scraping

Problem

In kubelet-to-gcm/monitor/poll.go, the Once function splits metrics into multiple batches (sub-requests) to avoid exceeding API limits. However, the current error handling logic uses an early return if any batch fails to be written to Google Cloud Monitoring.

This causes all remaining batches in the same scraping cycle to be skipped, even if they would have succeeded. This leads to unnecessary data loss during intermittent API failures or if a single batch contains a malformed metric.

Additionally, the code contained verbose JSON marshalling and logging of failed requests, which adds unnecessary overhead and log noise.

Solution

  1. Replace return with continue in the batch processing loop. This ensures that a failure in one batch does not prevent subsequent batches from being attempted.
  2. Remove the verbose MarshalJSON and log.Warningf of the full JSON request to improve logging hygiene and performance.

Testing

  • Verified that the code compiles successfully (go build ./...).
  • Manual code review confirms that the loop now correctly proceeds to the next iteration on error.

@courageJ courageJ force-pushed the fix-poll-early-return branch from e6fd30a to 2651a0a Compare May 21, 2026 12:20
@courageJ courageJ requested a review from erain May 21, 2026 12:22
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