Skip to content

Commit

Permalink
Merge pull request #1710 from murgatroid99/grpc-js-xds_lrs_initial_ca…
Browse files Browse the repository at this point in the history
…ll_fix

grpc-js-xds: Fix sending stats when reestablishing LRS stream
  • Loading branch information
murgatroid99 committed Mar 9, 2021
2 parents 5b362be + 2aec366 commit b374a83
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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

0 comments on commit b374a83

Please sign in to comment.