Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/grouped-batch-op-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@fluidframework/container-runtime": minor
"__section": feature
---
Add groupedOpCount to grouped batch metadata

A new `groupedOpCount` field on the metadata of grouped batch envelope messages exposes the number of inner ops in the batch. This lets wire-level consumers record batch sizes in telemetry without parsing the grouped batch contents.

The field is set on:
- The single envelope produced by grouping a batch (`OpGroupingManager.groupBatch`).
- The empty-grouped-batch placeholder used when a resubmitted batch becomes empty (`OpGroupingManager.createEmptyGroupedBatch`, value `0`).
- The final chunk of a chunked grouped batch (`OpSplitter.splitSingletonBatchMessage`), so the count survives chunking.

Compression preserves the metadata as-is, so compressed grouped batches carry the field through unchanged.
5 changes: 5 additions & 0 deletions packages/runtime/container-runtime/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export interface IBatchMetadata {
* Maybe set on first message of a batch, to the batchId generated when resubmitting (set/fixed on first resubmit)
*/
batchId?: BatchId;
/**
* Set on the envelope of a grouped batch op to the number of inner ops it contains.
* Exposed on the wire so consumers can record batch sizes in telemetry without parsing the grouped batch contents.
*/
groupedOpCount?: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class OpGroupingManager {
const serializedOp = JSON.stringify(emptyGroupedBatch);

const placeholderMessage: LocalEmptyBatchPlaceholder = {
metadata: { batchId: resubmittingBatchId },
metadata: { batchId: resubmittingBatchId, groupedOpCount: 0 },
localOpMetadata: { emptyBatch: true },
referenceSequenceNumber,
runtimeOp: emptyGroupedBatch,
Expand Down Expand Up @@ -169,7 +169,7 @@ export class OpGroupingManager {
...batch,
messages: [
{
metadata: { batchId: groupedBatchId },
metadata: { batchId: groupedBatchId, groupedOpCount: batch.messages.length },
referenceSequenceNumber: batch.messages[0].referenceSequenceNumber,
contents: serializedContent,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,16 @@ export class OpSplitter {
}

// The last chunk will be part of the new batch and needs to
// preserve the batch metadata of the original batch
// preserve the batch metadata of the original batch.
// groupedOpCount is surfaced here so wire-level telemetry can read it once
// per chunked grouped batch (mirroring where the batch flag is preserved).
const rawGroupedOpCount = firstMessage.metadata?.groupedOpCount;
const groupedOpCount =
typeof rawGroupedOpCount === "number" ? rawGroupedOpCount : undefined;
const lastChunk = chunkToBatchMessage(
chunks[chunks.length - 1],
Comment thread
anthony-murphy marked this conversation as resolved.
Comment thread
anthony-murphy marked this conversation as resolved.
batch.referenceSequenceNumber,
{ batch: firstMessage.metadata?.batch },
{ batch: firstMessage.metadata?.batch, groupedOpCount },
Comment thread
anthony-murphy marked this conversation as resolved.
Outdated
);

this.logger.sendPerformanceEvent({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("OpGroupingManager", () => {
{
contents:
'{"type":"groupedBatch","contents":[{"contents":0},{"contents":0},{"contents":0},{"contents":0},{"contents":0}]}',
metadata: { batchId: undefined },
metadata: { batchId: undefined, groupedOpCount: 5 },
referenceSequenceNumber: 0,
},
]);
Expand All @@ -90,6 +90,7 @@ describe("OpGroupingManager", () => {
).groupBatch(createBatch(5, false, false, batchId));
assert.strictEqual(result.messages.length, 1);
assert.strictEqual(result.messages[0].metadata?.batchId, batchId);
assert.strictEqual(result.messages[0].metadata?.groupedOpCount, 5);
});

it("empty grouped batching disabled", () => {
Expand All @@ -111,7 +112,7 @@ describe("OpGroupingManager", () => {
const batchId = "batchId";
const expectedOutboundMessage: OutboundBatchMessage = {
contents: '{"type":"groupedBatch","contents":[]}',
metadata: { batchId },
metadata: { batchId, groupedOpCount: 0 },
localOpMetadata: { emptyBatch: true },
referenceSequenceNumber: 0,
runtimeOp: undefined,
Expand All @@ -128,7 +129,7 @@ describe("OpGroupingManager", () => {

const expectedPlaceholderMessage: LocalEmptyBatchPlaceholder = {
runtimeOp: emptyGroupedBatch,
metadata: { batchId },
metadata: { batchId, groupedOpCount: 0 },
localOpMetadata: { emptyBatch: true },
referenceSequenceNumber: 0,
};
Expand Down
Loading