From 6e1f47ceb1185d3ce7520886eb205d8763fe3878 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Mon, 21 Mar 2022 09:42:21 +0800 Subject: [PATCH 1/5] Add logs to CentralConfig 3xx and 4xx responses. So the client will have logs on why Central Config fails. --- index.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index f56fb3b..2660b2b 100644 --- a/index.js +++ b/index.js @@ -389,11 +389,21 @@ Client.prototype._pollConfig = function () { this._scheduleNextConfigPoll(getMaxAge(res)) - if ( - res.statusCode === 304 || // No new config since last time - res.statusCode === 403 || // Central config not enabled in APM Server - res.statusCode === 404 // Old APM Server that doesn't support central config - ) { + if (req.statusCode === 304) { + this._log.debug(`[_pollConfig] statusCode: 304, message: No new config since last time`) + res.resume() + return + } + + if ([403, 404].includes(res.statusCode)) { + // something is wrong on the Central Config server. + switch (res.statusCode) { + case 403: + this._log.warn(`[_pollConfig] statusCode: 403, message: Central config not enabled in APM Server`) + case 404: + this._log.warn(`[_pollConfig] statusCode: 404, message: Old APM Server that doesn't support central config`) + } + res.resume() return } From 942957e1ea62c2ec73f74b7f3c7b82a2c6423b16 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Mon, 21 Mar 2022 09:56:18 +0800 Subject: [PATCH 2/5] Fixes pollConfig prints wrong logs for 403 error. --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 2660b2b..a28b5c1 100644 --- a/index.js +++ b/index.js @@ -400,8 +400,10 @@ Client.prototype._pollConfig = function () { switch (res.statusCode) { case 403: this._log.warn(`[_pollConfig] statusCode: 403, message: Central config not enabled in APM Server`) + break; case 404: this._log.warn(`[_pollConfig] statusCode: 404, message: Old APM Server that doesn't support central config`) + break; } res.resume() From 6066c5c5d058e41f7557b651b9aefd03098c5148 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Tue, 22 Mar 2022 07:51:21 +0800 Subject: [PATCH 3/5] Fixes coding style. --- index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index a28b5c1..4b4b148 100644 --- a/index.js +++ b/index.js @@ -390,7 +390,7 @@ Client.prototype._pollConfig = function () { this._scheduleNextConfigPoll(getMaxAge(res)) if (req.statusCode === 304) { - this._log.debug(`[_pollConfig] statusCode: 304, message: No new config since last time`) + this._log.debug('[_pollConfig] statusCode: 304, message: No new config since last time') res.resume() return } @@ -399,11 +399,11 @@ Client.prototype._pollConfig = function () { // something is wrong on the Central Config server. switch (res.statusCode) { case 403: - this._log.warn(`[_pollConfig] statusCode: 403, message: Central config not enabled in APM Server`) - break; + this._log.warn('[_pollConfig] statusCode: 403, message: Central config not enabled in APM Server') + break case 404: - this._log.warn(`[_pollConfig] statusCode: 404, message: Old APM Server that doesn't support central config`) - break; + this._log.warn('[_pollConfig] statusCode: 404, message: Old APM Server that doesn't support central config') + break } res.resume() From 882315df80b50d599f067b078e39690c9c015812 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Tue, 22 Mar 2022 09:01:06 +0800 Subject: [PATCH 4/5] Fixes typo again. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4b4b148..9273c81 100644 --- a/index.js +++ b/index.js @@ -402,7 +402,7 @@ Client.prototype._pollConfig = function () { this._log.warn('[_pollConfig] statusCode: 403, message: Central config not enabled in APM Server') break case 404: - this._log.warn('[_pollConfig] statusCode: 404, message: Old APM Server that doesn't support central config') + this._log.warn('[_pollConfig] statusCode: 404, message: Old APM Server that does not support central config') break } From e8bcc84457002b1567138b83cded8adb0ba525c7 Mon Sep 17 00:00:00 2001 From: Jun Lin Date: Tue, 22 Mar 2022 09:05:11 +0800 Subject: [PATCH 5/5] The checking on `304` should be on `res`. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9273c81..bfefce1 100644 --- a/index.js +++ b/index.js @@ -389,7 +389,7 @@ Client.prototype._pollConfig = function () { this._scheduleNextConfigPoll(getMaxAge(res)) - if (req.statusCode === 304) { + if (res.statusCode === 304) { this._log.debug('[_pollConfig] statusCode: 304, message: No new config since last time') res.resume() return