Merge pull request #2495 from minhhoangvn/fix/update-service-name-grpc

Bug fix: gRPC check throws errors when response data size > 50 chars
This commit is contained in:
Louis Lam 2023-01-01 13:57:10 +08:00 committed by GitHub
commit 41a9f2ff8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 18 deletions

View File

@ -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;

View File

@ -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;

View File

@ -778,6 +778,7 @@ module.exports.grpcQuery = async (options) => {
cb);
}, false, false);
return new Promise((resolve, _) => {
try {
return grpcService[`${grpcMethod}`](JSON.parse(grpcBody), function (err, response) {
const responseData = JSON.stringify(response);
if (err) {
@ -787,7 +788,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: "",
@ -795,5 +796,13 @@ module.exports.grpcQuery = async (options) => {
});
}
});
} 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: ""
});
}
});
};