From 4147a4c4040512670be065f9ad29b94d511b7248 Mon Sep 17 00:00:00 2001 From: minhhoang Date: Wed, 28 Dec 2022 22:31:33 +0700 Subject: [PATCH 1/2] fix: #2480 --- server/model/monitor.js | 2 +- server/server.js | 1 + server/util-server.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 186962b0..b6e95032 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -548,7 +548,7 @@ class Monitor extends BeanModel { log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); let responseData = response.data; if (responseData.length > 50) { - responseData = response.substring(0, 47) + "..."; + responseData = responseData.toString().substring(0, 47) + "..."; } if (response.code !== 1) { bean.status = DOWN; diff --git a/server/server.js b/server/server.js index 594c29b3..5473cecd 100644 --- a/server/server.js +++ b/server/server.js @@ -714,6 +714,7 @@ let needSetup = false; bean.authDomain = monitor.authDomain; bean.grpcUrl = monitor.grpcUrl; bean.grpcProtobuf = monitor.grpcProtobuf; + bean.grpcServiceName = monitor.grpcServiceName; bean.grpcMethod = monitor.grpcMethod; bean.grpcBody = monitor.grpcBody; bean.grpcMetadata = monitor.grpcMetadata; diff --git a/server/util-server.js b/server/util-server.js index 0bf69133..ffc3b3d9 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -787,7 +787,7 @@ module.exports.grpcQuery = async (options) => { data: "" }); } else { - log.debug("monitor:", `gRPC response: ${response}`); + log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); return resolve({ code: 1, errorMessage: "", From d111db0321fdd19886d107052c85b46ae77a1b9e Mon Sep 17 00:00:00 2001 From: minhhoang Date: Thu, 29 Dec 2022 08:10:58 +0700 Subject: [PATCH 2/2] fix: add accurate error message when user input invalid service name or method name --- server/util-server.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index ffc3b3d9..2ce6de3e 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -778,22 +778,31 @@ module.exports.grpcQuery = async (options) => { cb); }, false, false); return new Promise((resolve, _) => { - return grpcService[`${grpcMethod}`](JSON.parse(grpcBody), function (err, response) { - const responseData = JSON.stringify(response); - if (err) { - return resolve({ - code: err.code, - errorMessage: err.details, - data: "" - }); - } else { - log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); - return resolve({ - code: 1, - errorMessage: "", - data: responseData - }); - } - }); + try { + return grpcService[`${grpcMethod}`](JSON.parse(grpcBody), function (err, response) { + const responseData = JSON.stringify(response); + if (err) { + return resolve({ + code: err.code, + errorMessage: err.details, + data: "" + }); + } else { + log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); + return resolve({ + code: 1, + errorMessage: "", + data: responseData + }); + } + }); + } catch (err) { + return resolve({ + code: -1, + errorMessage: `Error ${err}. Please review your gRPC configuration option. The service name must not include package name value, and the method name must follow camelCase format`, + data: "" + }); + } + }); };