Merge pull request #1710 from murgatroid99/grpc-js-xds_lrs_initial_call_fix

grpc-js-xds: Fix sending stats when reestablishing LRS stream
This commit is contained in:
Michael Lumish 2021-03-09 13:14:40 -08:00 committed by GitHub
commit b374a83a71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@grpc/grpc-js-xds", "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.", "description": "Plugin for @grpc/grpc-js. Adds the xds:// URL scheme and associated features.",
"main": "build/src/index.js", "main": "build/src/index.js",
"scripts": { "scripts": {

View File

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