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-xds: Fix sending stats when reestablishing LRS stream #1710

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-xds/package.json
@@ -1,6 +1,6 @@
{
"name": "@grpc/grpc-js-xds",
"version": "1.2.3",
"version": "1.2.4",
"description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
"main": "build/src/index.js",
"scripts": {
Expand Down
14 changes: 11 additions & 3 deletions packages/grpc-js-xds/src/xds-client.ts
Expand Up @@ -1020,12 +1020,14 @@ export class XdsClient {

this.lrsBackoff.runOnce();
this.lrsCall = this.lrsClient.streamLoadStats();
let receivedSettingsForThisStream = false;
this.lrsCall.on('data', (message: LoadStatsResponse__Output) => {
/* Once we get any response from the server, we assume that the stream is
* in a good state, so we can reset the backoff timer. */
this.lrsBackoff.stop();
this.lrsBackoff.reset();
if (
!receivedSettingsForThisStream ||
message.load_reporting_interval?.seconds !==
this.latestLrsSettings?.load_reporting_interval?.seconds ||
message.load_reporting_interval?.nanos !==
Expand All @@ -1045,13 +1047,13 @@ export class XdsClient {
}, loadReportingIntervalMs);
}
this.latestLrsSettings = message;
receivedSettingsForThisStream = true;
});
this.lrsCall.on('error', (error: ServiceError) => {
trace(
'LRS stream ended. code=' + error.code + ' details= ' + error.details
);
this.lrsCall = null;
this.latestLrsSettings = null;
clearInterval(this.statsTimer);
/* If the backoff timer is no longer running, we do not need to wait any
* more to start the new call. */
Expand All @@ -1068,14 +1070,20 @@ export class XdsClient {
if (!this.lrsCall) {
return;
}
if (!this.latestLrsSettings) {
this.lrsCall.write({
node: this.lrsNode!,
});
return;
}
const clusterStats: ClusterStats[] = [];
for (const [
{ clusterName, edsServiceName },
stats,
] of this.clusterStatsMap.entries()) {
if (
this.latestLrsSettings!.send_all_clusters ||
this.latestLrsSettings!.clusters.indexOf(clusterName) > 0
this.latestLrsSettings.send_all_clusters ||
this.latestLrsSettings.clusters.indexOf(clusterName) > 0
) {
const upstreamLocalityStats: UpstreamLocalityStats[] = [];
for (const localityStats of stats.localityStats) {
Expand Down