Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GEODE-10231 : Add configuration for suppressing FunctionException logging #7584

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import java.util.concurrent.TimeUnit;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import org.apache.geode.InternalGemFireException;
import org.apache.geode.SystemFailure;
import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.internal.MakeNotStatic;
import org.apache.geode.cache.LowMemoryException;
import org.apache.geode.cache.TransactionException;
Expand Down Expand Up @@ -55,6 +58,9 @@
*/
public abstract class AbstractExecution implements InternalExecution {
private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

public static final int DEFAULT_CLIENT_FUNCTION_TIMEOUT = 0;
private static final String CLIENT_FUNCTION_TIMEOUT_SYSTEM_PROPERTY =
Expand Down Expand Up @@ -504,7 +510,8 @@ private void handleException(Throwable functionException, final Function fn,
((InternalResultSender) sender).setException(functionException);
}
} else {
logger.warn("Exception occurred on local node while executing Function:",
logger.warn(functionException instanceof FunctionException ? functionExceptionMarker : null,
"Exception occurred on local node while executing Function:",
functionException);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
package org.apache.geode.internal.cache.execute;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultCollector;
Expand All @@ -29,6 +32,9 @@
public class DistributedRegionFunctionResultSender implements InternalResultSender {

private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

DistributedRegionFunctionStreamingMessage msg = null;

Expand Down Expand Up @@ -224,7 +230,8 @@ public void setException(Throwable exception) {
} else {
((LocalResultCollector) rc).setException(exception);
// this.lastResult(exception);
logger.info("Unexpected exception during function execution on local node Distributed Region",
logger.info(exception instanceof FunctionException ? functionExceptionMarker : null,
"Unexpected exception during function execution on local node Distributed Region",
exception);
}
rc.endResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package org.apache.geode.internal.cache.execute;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultCollector;
Expand All @@ -31,6 +34,9 @@
public class MemberFunctionResultSender implements InternalResultSender {

private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

MemberFunctionStreamingMessage msg = null;

Expand Down Expand Up @@ -232,7 +238,8 @@ public void sendException(Throwable exception) {
public void setException(Throwable exception) {
((LocalResultCollector) rc).setException(exception);
// this.lastResult(exception);
logger.info("Unexpected exception during function execution local member",
logger.info(exception instanceof FunctionException ? functionExceptionMarker : null,
"Unexpected exception during function execution local member",
exception);
rc.endResults();
localLastResultReceived = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@


import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultCollector;
Expand All @@ -42,6 +45,9 @@
public class PartitionedRegionFunctionResultSender implements InternalResultSender {

private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

PartitionedRegionFunctionStreamingMessage msg = null;

Expand Down Expand Up @@ -390,7 +396,8 @@ public void setException(Throwable exception) {
serverSender.setException(exception);
} else {
((LocalResultCollector) rc).setException(exception);
logger.info("Unexpected exception during function execution on local node Partitioned Region",
logger.info(exception instanceof FunctionException ? functionExceptionMarker : null,
"Unexpected exception during function execution on local node Partitioned Region",
exception);
}
rc.endResults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultSender;
Expand All @@ -37,6 +40,9 @@

public class ServerToClientFunctionResultSender implements ResultSender {
private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

protected ChunkedMessage msg = null;

Expand Down Expand Up @@ -321,9 +327,9 @@ public synchronized void setException(Throwable exception) {
}
String exceptionMessage = exception.getMessage() != null ? exception.getMessage()
: "Exception occurred during function execution";
logger.warn(String.format("Exception on server while executing function : %s",
fn),
exception);
logger.warn(exception instanceof FunctionException ? functionExceptionMarker : null,
"Exception on server while executing function : {}", fn, exception);

if (logger.isDebugEnabled()) {
logger.debug("ServerToClientFunctionResultSender sending Function Exception : ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.regex.Pattern;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -88,6 +90,9 @@

public abstract class BaseCommand implements Command {
protected static final Logger logger = LogService.getLogger();
@Immutable
protected static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

@Immutable
private static final byte[] OK_BYTES = new byte[] {0};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ private void executeFunctionLocally(final Function fn, final FunctionContext cx,
if (logger.isDebugEnabled()) {
logger.debug("Exception on server while executing function: {}", fn, e);
}
} catch (FunctionException e) {
stats.endFunctionExecutionWithException(startExecution, fn.hasResult());
logger.warn(functionExceptionMarker, "Exception on server while executing function: {}",
fn, e);
} catch (Exception e) {
stats.endFunctionExecutionWithException(startExecution, fn.hasResult());
logger.warn("Exception on server while executing function: {}", fn, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ public void cmdExecute(final @NotNull Message clientMessage,
resultSender.setException(fe);
} else {
if (setLastResultReceived(resultSender)) {
logger.warn(String.format("Exception on server while executing function : %s",
function),
fe);
logger.warn(functionExceptionMarker,
"Exception on server while executing function : {}",
function, fe);
sendException(hasResult, clientMessage, message, serverConnection, fe);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See [Authorization of Function Execution](../../managing/security/implementing_a
- For partitioned regions, the `PartitionRegionHelper` provides access to additional information and data for the region. For single regions, use `getLocalDataForContext`. For colocated regions, use `getLocalColocatedRegions`.
**Note:**
When you use `PartitionRegionHelper.getLocalDataForContext`, `putIfAbsent` may not return expected results if you are working on local data set instead of the region.
4. To propagate an error condition or exception back to the caller of the function, throw a FunctionException from the `execute` method. <%=vars.product_name%> transmits the exception back to the caller as if it had been thrown on the calling side. See the Java API documentation for [FunctionException](/releases/latest/javadoc/org/apache/geode/cache/execute/FunctionException.html) for more information.
4. To propagate an error condition or exception back to the caller of the function, throw a FunctionException from the `execute` method. <%=vars.product_name%> transmits the exception back to the caller as if it had been thrown on the calling side. See the Java API documentation for [FunctionException](/releases/latest/javadoc/org/apache/geode/cache/execute/FunctionException.html) for more information. Note, FunctionException logging on server side can be disabled by the Log4j filter for marker FUNCTION\_EXCEPTION\_MARKER. See [Advanced Users—Configuring Log4j 2 for <%=vars.product_name%>](../../managing/logging/configuring_log4j2.html) for more details.

Example function code:

Expand Down
5 changes: 5 additions & 0 deletions geode-docs/managing/logging/configuring_log4j2.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ Custom Log4j 2 configuration in <%=vars.product_name%> comes with some caveats a

You can enable the GEODE\_VERBOSE log statements by changing `onMatch="DENY"` to `onMatch="ACCEPT"`. Typically, it's more useful to simply enable DEBUG or TRACE on certain classes or packages instead of for the entire <%=vars.product_name%> product. However, this setting can be used for internal debugging purposes if all other debugging methods fail.
- The usage of filters can have an impact on performance. <%=vars.product_name%> has some logging optimizations that are deactivated when filters are used (except for the GEODE_VERBOSE marker mentioned previously).
- The FUNCTION\_EXCEPTION\_MARKER marker (Log4J2 Marker) can be used to disable FunctionException logs on server side during function execution. For example <%=vars.product_name%> `log4j2.xml` filter disables FunctionException logs with this line:

``` pre
<MarkerFilter marker="FUNCTION_EXCEPTION_MARKER" onMatch="DENY" onMismatch="NEUTRAL"/>
```

- Geode's custom Log4j 2 Appenders can be used in a custom log4j2.xml. This requires:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
import java.util.stream.Collectors;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.shiro.subject.Subject;

import org.apache.geode.annotations.Immutable;
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.ResultCollector;
import org.apache.geode.cache.query.RegionNotFoundException;
Expand All @@ -55,6 +59,10 @@
public class UserFunctionExecution implements InternalFunction<Object[]> {
private static final long serialVersionUID = 1L;
private static final Logger logger = LogService.getLogger();
@Immutable
private static final Marker functionExceptionMarker =
MarkerManager.getMarker("FUNCTION_EXCEPTION_MARKER");

protected static final String ID =
"org.apache.geode.management.internal.cli.functions.UserFunctionExecution";

Expand Down Expand Up @@ -244,6 +252,10 @@ public void execute(FunctionContext<Object[]> context) {
CliStrings.format(
CliStrings.EXECUTE_FUNCTION__MSG__RESULT_COLLECTOR_0_NOT_FOUND_ERROR_1,
resultCollectorName, e.getMessage())));
} catch (FunctionException e) {
logger.error(functionExceptionMarker, "error executing function {}", functionId, e);
context.getResultSender().lastResult(
new CliFunctionResult(context.getMemberName(), ERROR, "Exception: " + e.getMessage()));
} catch (Exception e) {
logger.error("error executing function " + functionId, e);
context.getResultSender().lastResult(
Expand Down