mirror of
https://github.com/apache/druid.git
synced 2025-02-17 15:35:56 +00:00
Better logs for query errors (#13776)
* Better logs for query errors * checkstyle
This commit is contained in:
parent
f3e19f69bb
commit
f67abf2e99
@ -22,6 +22,7 @@ package org.apache.druid.query;
|
|||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.apache.druid.common.exception.SanitizableException;
|
import org.apache.druid.common.exception.SanitizableException;
|
||||||
|
import org.apache.druid.java.util.common.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
@ -224,4 +225,17 @@ public class QueryException extends RuntimeException implements SanitizableExcep
|
|||||||
{
|
{
|
||||||
return fromErrorCode(errorCode);
|
return fromErrorCode(errorCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return StringUtils.format(
|
||||||
|
"%s{msg=%s, code=%s, class=%s, host=%s}",
|
||||||
|
getClass().getSimpleName(),
|
||||||
|
getMessage(),
|
||||||
|
getErrorCode(),
|
||||||
|
getErrorClass(),
|
||||||
|
getHost()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +113,18 @@ public class QueryExceptionTest
|
|||||||
Assert.assertNull(exception.getMessage());
|
Assert.assertNull(exception.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToStringReturnsUsefulInformation()
|
||||||
|
{
|
||||||
|
QueryException queryException = new QueryException(ERROR_CODE, ERROR_MESSAGE_ORIGINAL, ERROR_CLASS, HOST);
|
||||||
|
String exceptionToString = queryException.toString();
|
||||||
|
Assert.assertTrue(exceptionToString.startsWith(QueryException.class.getSimpleName()));
|
||||||
|
Assert.assertTrue(exceptionToString.contains("msg=" + ERROR_MESSAGE_ORIGINAL));
|
||||||
|
Assert.assertTrue(exceptionToString.contains("code=" + ERROR_CODE));
|
||||||
|
Assert.assertTrue(exceptionToString.contains("class=" + ERROR_CLASS));
|
||||||
|
Assert.assertTrue(exceptionToString.contains("host=" + HOST));
|
||||||
|
}
|
||||||
|
|
||||||
private void expectFailTypeForCode(FailType expected, String code)
|
private void expectFailTypeForCode(FailType expected, String code)
|
||||||
{
|
{
|
||||||
QueryException exception = new QueryException(new Exception(), code, "java.lang.Exception", "test");
|
QueryException exception = new QueryException(new Exception(), code, "java.lang.Exception", "test");
|
||||||
|
@ -21,7 +21,6 @@ package org.apache.druid.query;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import org.apache.druid.java.util.common.StringUtils;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
@ -70,18 +69,6 @@ public class QueryInterruptedException extends QueryException
|
|||||||
super(cause, getErrorCodeFromThrowable(cause), getErrorClassFromThrowable(cause), host);
|
super(cause, getErrorCodeFromThrowable(cause), getErrorClassFromThrowable(cause), host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return StringUtils.format(
|
|
||||||
"QueryInterruptedException{msg=%s, code=%s, class=%s, host=%s}",
|
|
||||||
getMessage(),
|
|
||||||
getErrorCode(),
|
|
||||||
getErrorClass(),
|
|
||||||
getHost()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getErrorCodeFromThrowable(Throwable e)
|
private static String getErrorCodeFromThrowable(Throwable e)
|
||||||
{
|
{
|
||||||
if (e instanceof QueryInterruptedException) {
|
if (e instanceof QueryInterruptedException) {
|
||||||
|
@ -170,6 +170,24 @@ public class QueryInterruptedExceptionTest
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToStringShouldReturnUsefulInformation()
|
||||||
|
{
|
||||||
|
QueryInterruptedException exception = new QueryInterruptedException(
|
||||||
|
"error",
|
||||||
|
"error messagez",
|
||||||
|
"error class",
|
||||||
|
"host"
|
||||||
|
);
|
||||||
|
String exceptionString = exception.toString();
|
||||||
|
Assert.assertTrue(exceptionString.startsWith(QueryInterruptedException.class.getSimpleName()));
|
||||||
|
Assert.assertTrue(exceptionString.contains("code=" + "error"));
|
||||||
|
Assert.assertTrue(exceptionString.contains("msg=" + "error messagez"));
|
||||||
|
Assert.assertTrue(exceptionString.contains("class=" + "error class"));
|
||||||
|
Assert.assertTrue(exceptionString.contains("host=" + "host"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static QueryInterruptedException roundTrip(final QueryInterruptedException e)
|
private static QueryInterruptedException roundTrip(final QueryInterruptedException e)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user