JsInvokeService - log js body on script failure to investigate easy
This commit is contained in:
parent
ddfb57db58
commit
1d33c09127
@ -120,11 +120,10 @@ public abstract class AbstractJsInvokeService implements JsInvokeService {
|
|||||||
|
|
||||||
protected abstract long getMaxBlacklistDuration();
|
protected abstract long getMaxBlacklistDuration();
|
||||||
|
|
||||||
protected void onScriptExecutionError(UUID scriptId, Throwable t) {
|
protected void onScriptExecutionError(UUID scriptId, Throwable t, String scriptBody) {
|
||||||
DisableListInfo disableListInfo = disabledFunctions.computeIfAbsent(scriptId, key -> new DisableListInfo());
|
DisableListInfo disableListInfo = disabledFunctions.computeIfAbsent(scriptId, key -> new DisableListInfo());
|
||||||
log.warn("Script has exception and will increment counter {} on disabledFunctions for id {}, exception {}, cause {}",
|
log.warn("Script has exception and will increment counter {} on disabledFunctions for id {}, exception {}, cause {}, scriptBody {}",
|
||||||
disableListInfo.get(), scriptId, t, t.getCause());
|
disableListInfo.get(), scriptId, t, t.getCause(), scriptBody);
|
||||||
log.error("onScriptExecutionError", t);
|
|
||||||
// if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
// if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
||||||
// log.warn("Script has TimeoutException and will increment counter {} on disabledFunctions for id {}", //TODO remove after test
|
// log.warn("Script has TimeoutException and will increment counter {} on disabledFunctions for id {}", //TODO remove after test
|
||||||
// disableListInfo.get(),
|
// disableListInfo.get(),
|
||||||
|
|||||||
@ -160,7 +160,7 @@ public abstract class AbstractNashornJsInvokeService extends AbstractJsInvokeSer
|
|||||||
return ((Invocable) engine).invokeFunction(functionName, args);
|
return ((Invocable) engine).invokeFunction(functionName, args);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
onScriptExecutionError(scriptId, e);
|
onScriptExecutionError(scriptId, e, functionName);
|
||||||
throw new ExecutionException(e);
|
throw new ExecutionException(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -18,7 +18,6 @@ package org.thingsboard.server.service.script;
|
|||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -161,7 +160,8 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ListenableFuture<Object> doInvokeFunction(UUID scriptId, String functionName, Object[] args) {
|
protected ListenableFuture<Object> doInvokeFunction(UUID scriptId, String functionName, Object[] args) {
|
||||||
String scriptBody = scriptIdToBodysMap.get(scriptId);
|
log.trace("doInvokeFunction js-request for uuid {} with timeout {}ms", scriptId, maxRequestsTimeout);
|
||||||
|
final String scriptBody = scriptIdToBodysMap.get(scriptId);
|
||||||
if (scriptBody == null) {
|
if (scriptBody == null) {
|
||||||
return Futures.immediateFailedFuture(new RuntimeException("No script body found for scriptId: [" + scriptId + "]!"));
|
return Futures.immediateFailedFuture(new RuntimeException("No script body found for scriptId: [" + scriptId + "]!"));
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
|||||||
.setScriptIdLSB(scriptId.getLeastSignificantBits())
|
.setScriptIdLSB(scriptId.getLeastSignificantBits())
|
||||||
.setFunctionName(functionName)
|
.setFunctionName(functionName)
|
||||||
.setTimeout((int) maxRequestsTimeout)
|
.setTimeout((int) maxRequestsTimeout)
|
||||||
.setScriptBody(scriptIdToBodysMap.get(scriptId));
|
.setScriptBody(scriptBody);
|
||||||
|
|
||||||
for (Object arg : args) {
|
for (Object arg : args) {
|
||||||
jsRequestBuilder.addArgs(arg.toString());
|
jsRequestBuilder.addArgs(arg.toString());
|
||||||
@ -193,7 +193,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable t) {
|
public void onFailure(Throwable t) {
|
||||||
onScriptExecutionError(scriptId, t);
|
onScriptExecutionError(scriptId, t, scriptBody);
|
||||||
if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
if (t instanceof TimeoutException || (t.getCause() != null && t.getCause() instanceof TimeoutException)) {
|
||||||
queueTimeoutMsgs.incrementAndGet();
|
queueTimeoutMsgs.incrementAndGet();
|
||||||
}
|
}
|
||||||
@ -206,7 +206,7 @@ public class RemoteJsInvokeService extends AbstractJsInvokeService {
|
|||||||
return invokeResult.getResult();
|
return invokeResult.getResult();
|
||||||
} else {
|
} else {
|
||||||
final RuntimeException e = new RuntimeException(invokeResult.getErrorDetails());
|
final RuntimeException e = new RuntimeException(invokeResult.getErrorDetails());
|
||||||
onScriptExecutionError(scriptId, e);
|
onScriptExecutionError(scriptId, e, scriptBody);
|
||||||
log.debug("[{}] Failed to compile script due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
|
log.debug("[{}] Failed to compile script due to [{}]: {}", scriptId, invokeResult.getErrorCode().name(), invokeResult.getErrorDetails());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user