Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc-js: Limit the number of retained channelz trace events #1943

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/grpc-js/package.json
@@ -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
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