Skip to content

batch: reserve 10KiB gRPC framing overhead in split and add batch_splits_total metric#2078

Merged
jmank88 merged 3 commits into
mainfrom
chip-ingress-batching-split-metric
May 21, 2026
Merged

batch: reserve 10KiB gRPC framing overhead in split and add batch_splits_total metric#2078
jmank88 merged 3 commits into
mainfrom
chip-ingress-batching-split-metric

Conversation

@pkcll

@pkcll pkcll commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Add observability for batch splitting in the chipingress batch client:

  • New metric chip_ingress.batch.batch_splits_total — Int64Counter that increments each time splitMessagesByRequestSize produces more than one sub-batch, indicating the original batch exceeded the effective gRPC request size limit.
  • Reserve 10 KiB framing overheadsplitMessagesByRequestSize now subtracts a 10 KiB buffer from maxGRPCRequestSize to account for gRPC framing, HTTP/2 headers, auth tokens, and tracing metadata not captured by proto.Size.

Changes

  • pkg/chipingress/batch/client.go: Add batchSplitsTotal counter, register it in newBatchClientMetrics(), record it in sendBatch() when a split occurs, and apply grpcFramingOverhead in the split logic.

@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common/pkg/chipingress

View full report

@pkcll pkcll force-pushed the chip-ingress-batching-split-metric branch from 5f4b2c3 to cbf9a38 Compare May 20, 2026 22:38
@pkcll pkcll marked this pull request as ready for review May 20, 2026 22:46
@pkcll pkcll requested a review from a team as a code owner May 20, 2026 22:46
Copilot AI review requested due to automatic review settings May 20, 2026 22:46

Copilot AI 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.

Pull request overview

This PR improves observability and safety around batching in the chipingress batch client by (1) tracking when a batch is split due to request-size constraints and (2) reserving a fixed buffer to account for gRPC/HTTP2/request metadata not captured by proto.Size.

Changes:

  • Added a new counter metric chip_ingress.batch.batch_splits_total and increments it when a queued batch is split into multiple sub-batches.
  • Adjusted batch-splitting logic to use an “effective max” request size that subtracts a 10KiB overhead buffer from maxGRPCRequestSize.
  • Registered the new metric in the batch client metrics initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/chipingress/batch/client.go Outdated
}
batchSplitsTotal, err := meter.Int64Counter(
"chip_ingress.batch.batch_splits_total",
otelmetric.WithDescription("Total number of times a batch was split due to exceeding max gRPC request size"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed — updated the description to: "Total number of times a batch was split due to exceeding the effective gRPC request size limit (max request size minus reserved framing overhead)"

Comment thread pkg/chipingress/batch/client.go Outdated
Comment on lines +318 to +321
effectiveMax := maxRequestSize - grpcFramingOverhead
if effectiveMax <= 0 {
effectiveMax = maxRequestSize
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed — enforced a minimum maxGRPCRequestSize of 1 MiB in WithMaxGRPCRequestSize. Values below this are clamped up, ensuring the 10 KiB framing overhead reservation is always meaningful. The fallback branch now has a comment noting it should not be reachable given the minimum.

Comment thread pkg/chipingress/batch/client.go Outdated
Comment on lines +264 to +267
splitBatches := splitMessagesByRequestSize(messages, b.maxGRPCRequestSize)
if len(splitBatches) > 1 {
b.metrics.batchSplitsTotal.Add(ctx, 1)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed — added TestSendBatch/records_batch_splits_total_metric_when_batch_is_split that forces a split and asserts the counter equals 1.

@pkcll pkcll force-pushed the chip-ingress-batching-split-metric branch 2 times, most recently from 87ff96b to b9973df Compare May 20, 2026 23:13
@pkcll pkcll requested a review from jmank88 May 20, 2026 23:16
Comment thread pkg/chipingress/batch/client.go Outdated
4of9
4of9 previously approved these changes May 21, 2026
@pkcll pkcll force-pushed the chip-ingress-batching-split-metric branch 2 times, most recently from 72fb124 to 9e2725d Compare May 21, 2026 16:05
@pkcll pkcll force-pushed the chip-ingress-batching-split-metric branch from 9e2725d to abf7486 Compare May 21, 2026 16:09
@jmank88 jmank88 added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit 37abc9b May 21, 2026
32 of 33 checks passed
@jmank88 jmank88 deleted the chip-ingress-batching-split-metric branch May 21, 2026 19:35
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.

4 participants