Reduce excessive exception logging
This commit is contained in:
parent
74a8de1a99
commit
c413975aa9
|
|
@ -18,15 +18,16 @@
|
|||
|
||||
package org.apache.atlas.authorize.simple;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.atlas.AtlasClient;
|
||||
import org.apache.atlas.authorize.AtlasActionTypes;
|
||||
import org.apache.atlas.authorize.AtlasResourceTypes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
public class AtlasAuthorizationUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AtlasAuthorizationUtils.class);
|
||||
private static boolean isDebugEnabled = LOG.isDebugEnabled();
|
||||
|
|
@ -47,7 +48,13 @@ public class AtlasAuthorizationUtils {
|
|||
String[] split = contextPath.split("/", 3);
|
||||
String api = split[0];
|
||||
if (split.length > 1) {
|
||||
return (!api.equals("v1")) ? api : String.format("v1/%s", split[1]);
|
||||
if (Objects.equals(api, "v1")) {
|
||||
return String.format("v1/%s", split[1]);
|
||||
} else if (Objects.equals(api, "v2")) {
|
||||
return String.format("v2/%s", split[1]);
|
||||
} else {
|
||||
return api;
|
||||
}
|
||||
} else {
|
||||
return api;
|
||||
}
|
||||
|
|
@ -101,14 +108,15 @@ public class AtlasAuthorizationUtils {
|
|||
LOG.debug("==> getAtlasResourceType for " + contextPath);
|
||||
}
|
||||
String api = getApi(contextPath);
|
||||
if (api.startsWith("types")) {
|
||||
if (api.startsWith("types") || api.startsWith("v2/types")) {
|
||||
resourceTypes.add(AtlasResourceTypes.TYPE);
|
||||
} else if (api.startsWith("admin") && (contextPath.contains("/session") || contextPath.contains("/version"))) {
|
||||
resourceTypes.add(AtlasResourceTypes.UNKNOWN);
|
||||
} else if ((api.startsWith("discovery") && contextPath.contains("/gremlin")) || api.startsWith("admin")
|
||||
|| api.startsWith("graph")) {
|
||||
resourceTypes.add(AtlasResourceTypes.OPERATION);
|
||||
} else if (api.startsWith("entities") || api.startsWith("lineage") || api.startsWith("discovery")) {
|
||||
} else if (api.startsWith("entities") || api.startsWith("lineage") ||
|
||||
api.startsWith("discovery") || api.startsWith("v2/entity")) {
|
||||
resourceTypes.add(AtlasResourceTypes.ENTITY);
|
||||
} else if (api.startsWith("v1/taxonomies")) {
|
||||
resourceTypes.add(AtlasResourceTypes.TAXONOMY);
|
||||
|
|
@ -117,7 +125,7 @@ public class AtlasAuthorizationUtils {
|
|||
if (contextPath.contains("/terms")) {
|
||||
resourceTypes.add(AtlasResourceTypes.TERM);
|
||||
}
|
||||
} else if (api.startsWith("v1/entities")) {
|
||||
} else if (api.startsWith("v1/entities") || api.startsWith("v2/entities")) {
|
||||
resourceTypes.add(AtlasResourceTypes.ENTITY);
|
||||
} else {
|
||||
LOG.error("Unable to find Atlas Resource corresponding to : " + api + "\nSetting "
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
|
|||
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
|
||||
|
||||
ALL CHANGES:
|
||||
ATLAS-1349 Reduce excessive exception logging (apoorvnaik via svimal2106)
|
||||
ATLAS-1343 CTAS query is not captured by Atlas with Hive2 (svimal2106)
|
||||
ATLAS-1337 fixed FalconHookIT (ayubpathan via mneethiraj)
|
||||
ATLAS-1338 fix SqoopHookIT (ayubpathan via mneethiraj)
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ package org.apache.atlas;
|
|||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.repository.graph.AtlasGraphProvider;
|
||||
import org.apache.atlas.repository.graphdb.AtlasGraph;
|
||||
import org.apache.atlas.typesystem.exception.EntityNotFoundException;
|
||||
import org.apache.atlas.typesystem.exception.SchemaNotFoundException;
|
||||
import org.apache.atlas.typesystem.exception.NotFoundException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -79,10 +80,9 @@ public class GraphTransactionInterceptor implements MethodInterceptor {
|
|||
}
|
||||
|
||||
boolean logException(Throwable t) {
|
||||
if ((t instanceof SchemaNotFoundException) || (t instanceof EntityNotFoundException)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !(t instanceof NotFoundException) &&
|
||||
((t instanceof AtlasBaseException) &&
|
||||
((AtlasBaseException) t).getAtlasErrorCode().getHttpCode() != Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
public static abstract class PostTransactionHook {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,10 @@
|
|||
|
||||
package org.apache.atlas.typesystem.exception;
|
||||
|
||||
import org.apache.atlas.AtlasException;
|
||||
|
||||
/**
|
||||
* A simple wrapper for 404.
|
||||
*/
|
||||
public class EntityNotFoundException extends AtlasException {
|
||||
public class EntityNotFoundException extends NotFoundException {
|
||||
public EntityNotFoundException() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.atlas.typesystem.exception;
|
||||
|
||||
import org.apache.atlas.AtlasException;
|
||||
|
||||
/**
|
||||
* A simple wrapper for 404.
|
||||
*/
|
||||
public class NotFoundException extends AtlasException {
|
||||
public NotFoundException() {
|
||||
}
|
||||
|
||||
public NotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public NotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public NotFoundException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,9 +17,7 @@
|
|||
*/
|
||||
package org.apache.atlas.typesystem.exception;
|
||||
|
||||
import org.apache.atlas.AtlasException;
|
||||
|
||||
public class SchemaNotFoundException extends AtlasException {
|
||||
public class SchemaNotFoundException extends NotFoundException {
|
||||
public SchemaNotFoundException() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,13 +17,12 @@
|
|||
*/
|
||||
|
||||
package org.apache.atlas.typesystem.exception;
|
||||
import org.apache.atlas.AtlasException;
|
||||
|
||||
/**
|
||||
* A simple wrapper for 404.
|
||||
* Thrown when a requested trait can not be found.
|
||||
*/
|
||||
public class TraitNotFoundException extends AtlasException{
|
||||
public class TraitNotFoundException extends NotFoundException {
|
||||
public TraitNotFoundException() {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,34 +21,31 @@ package org.apache.atlas.web.errors;
|
|||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Exception mapper for Jersey.
|
||||
* @param <E>
|
||||
* AtlasBaseException mapper for Jersey.
|
||||
*/
|
||||
@Provider
|
||||
@Singleton
|
||||
public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseException> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AtlasBaseExceptionMapper.class);
|
||||
|
||||
@Override
|
||||
public Response toResponse(AtlasBaseException exception) {
|
||||
final long id = ThreadLocalRandom.current().nextLong();
|
||||
|
||||
// Log the response and use the error codes from the Exception
|
||||
logException(id, exception);
|
||||
return buildAtlasBaseExceptionResponse((AtlasBaseException) exception);
|
||||
// Only log the exception is there's an internal error
|
||||
if (exception.getAtlasErrorCode().getHttpCode() == Response.Status.INTERNAL_SERVER_ERROR) {
|
||||
ExceptionMapperUtil.logException(id, exception);
|
||||
}
|
||||
return buildAtlasBaseExceptionResponse(exception);
|
||||
}
|
||||
|
||||
protected Response buildAtlasBaseExceptionResponse(AtlasBaseException baseException) {
|
||||
|
|
@ -64,19 +61,4 @@ public class AtlasBaseExceptionMapper implements ExceptionMapper<AtlasBaseExcept
|
|||
}
|
||||
return responseBuilder.build();
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected String formatErrorMessage(long id, AtlasBaseException exception) {
|
||||
return String.format("There was an error processing your request. It has been logged (ID %016x).", id);
|
||||
}
|
||||
|
||||
protected void logException(long id, AtlasBaseException exception) {
|
||||
LOGGER.error(formatLogMessage(id, exception), exception);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnusedParameters")
|
||||
protected String formatLogMessage(long id, Throwable exception) {
|
||||
return String.format("Error handling a request: %016x", id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
package org.apache.atlas.web.errors;
|
||||
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.atlas.web.errors;
|
||||
|
||||
import org.apache.atlas.typesystem.exception.NotFoundException;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@Provider
|
||||
@Singleton
|
||||
public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
|
||||
@Override
|
||||
public Response toResponse(NotFoundException e) {
|
||||
final long id = ThreadLocalRandom.current().nextLong();
|
||||
return Response
|
||||
.status(Response.Status.NOT_FOUND)
|
||||
.entity(ExceptionMapperUtil.formatErrorMessage(id, e))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue