Skip to content

Commit

Permalink
Merge pull request #1943 from murgatroid99/grpc-js_channelz_trace_limit
Browse files Browse the repository at this point in the history
grpc-js: Limit the number of retained channelz trace events
  • Loading branch information
murgatroid99 committed Oct 20, 2021
2 parents 832afbe + 5139b10 commit 356f937
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js",
"version": "1.4.1",
"version": "1.4.2",
"description": "gRPC Library for Node - pure JS implementation",
"homepage": "https://grpc.io/",
"repository": "https://github.com/grpc/grpc-node/tree/master/packages/grpc-js",
Expand Down
26 changes: 12 additions & 14 deletions packages/grpc-js/src/channelz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ interface TraceEvent {
childSubchannel?: SubchannelRef;
}

/**
* The loose upper bound on the number of events that should be retained in a
* trace. This may be exceeded by up to a factor of 2. Arbitrarily chosen as a
* number that should be large enough to contain the recent relevant
* information, but small enough to not use excessive memory.
*/
const TARGET_RETAINED_TRACES = 32;

export class ChannelzTrace {
events: TraceEvent[] = [];
creationTimestamp: Date;
Expand All @@ -131,6 +139,10 @@ export class ChannelzTrace {
childChannel: child?.kind === 'channel' ? child : undefined,
childSubchannel: child?.kind === 'subchannel' ? child : undefined
});
// Whenever the trace array gets too large, discard the first half
if (this.events.length >= TARGET_RETAINED_TRACES * 2) {
this.events = this.events.slice(TARGET_RETAINED_TRACES);
}
this.eventsLogged += 1;
}

Expand Down Expand Up @@ -380,20 +392,6 @@ export function unregisterChannelzRef(ref: ChannelRef | SubchannelRef | ServerRe
}
}

export interface ChannelzClientView {
updateState(connectivityState: ConnectivityState): void;
addTrace(severity: TraceSeverity, description: string, child?: ChannelRef | SubchannelRef): void;
addCallStarted(): void;
addCallSucceeded(): void;
addCallFailed(): void;
addChild(child: ChannelRef | SubchannelRef): void;
removeChild(child: ChannelRef | SubchannelRef): void;
}

export interface ChannelzSubchannelView extends ChannelzClientView {
getRef(): SubchannelRef;
}

/**
* Converts an IPv4 or IPv6 address from string representation to binary
* representation
Expand Down

0 comments on commit 356f937

Please sign in to comment.