Skip to content

Commit

Permalink
#8 Exclude whole stack
Browse files Browse the repository at this point in the history
  • Loading branch information
mjok committed Jun 26, 2020
1 parent e7d5c37 commit eeaca7e
Show file tree
Hide file tree
Showing 41 changed files with 123 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(ApacheHttpClientAdvice.class, thiz, method, route, request)) {
if (!intercept(ApacheHttpClientAdvice.class, thiz, method, logging ? logger : null, route, request)) {
return;
}
ed = getEntryDefinition(ed, ApacheHttpClientAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -189,7 +189,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(ApacheHttpClientAdvice.class, obj, method, arguments)) {
if (!intercept(ApacheHttpClientAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(ApacheLegacyHttpClientAdvice.class, thiz, method, route, request)) {
if (!intercept(ApacheLegacyHttpClientAdvice.class, thiz, method, logging ? logger : null, route, request)) {
return;
}
ed = getEntryDefinition(ed, ApacheHttpClientAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -149,7 +149,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(ApacheLegacyHttpClientAdvice.class, obj, method, arguments)) {
if (!intercept(ApacheLegacyHttpClientAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(${adviceClassName}Advice.class, thiz, method, arguments)) {
if (!intercept(${adviceClassName}Advice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, ${adviceClassName}Advice.class, logging ? logger : null);;
Expand Down Expand Up @@ -138,7 +138,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(${adviceClassName}Advice.class, thiz, method, arguments)) {
if (!intercept(${adviceClassName}Advice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.jkoolcloud.remora.RemoraConfig;
import com.jkoolcloud.remora.core.CallStack;
import com.jkoolcloud.remora.core.EntryDefinition;
import com.jkoolcloud.remora.core.FilteredOutEntryStack;
import com.jkoolcloud.remora.core.output.OutputManager;
import com.jkoolcloud.remora.filters.AdviceFilter;

Expand Down Expand Up @@ -149,7 +150,7 @@ public static void fillDefaultValuesAfter(EntryDefinition entryDefinition, long
entryDefinition.addProperty("PARENT", lastEntryDefinition.getId());
}
}
if (!entryDefinition.isTransparent()) {
if (!entryDefinition.isTransparent() && !(stackThreadLocal.get() instanceof FilteredOutEntryStack)) {
OutputManager.send(entryDefinition);
}
}
Expand Down Expand Up @@ -200,7 +201,7 @@ public static long fillDefaultValuesBefore(EntryDefinition entryDefinition,
if (getAdviceInstance(entryDefinition.getAdviceClassClass()).sendStackTrace) {
entryDefinition.setStackTrace(getStackTrace());
}
if (!entryDefinition.isTransparent()) {
if (!entryDefinition.isTransparent() || !(stackThreadLocal.get() instanceof FilteredOutEntryStack)) {
OutputManager.send(entryDefinition);
}
} catch (Throwable t) {
Expand Down Expand Up @@ -393,12 +394,17 @@ private static <T extends BaseTransformers> T getAdviceInstance(Class<T> tClass)
}

public static boolean intercept(Class<? extends BaseTransformers> tClass, Object thiz, Method method,
Object... arguments) {
TaggedLogger logger, Object... arguments) {
if (!getAdviceInstance(tClass).enabled) {
return false;
}
for (AdviceFilter filter : getAdviceInstance(tClass).filters) {
if (!filter.intercept(thiz, method, arguments)) {
if (filter.excludeWholeStack()) {
if (stackThreadLocal.get() == null || stackThreadLocal.get().isEmpty()) {
stackThreadLocal.set(new FilteredOutEntryStack(logger, callStackLimit));
}
}
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ public void setServer(String server) {
entryDefinition.setServer(server);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,11 @@ public enum Mode {
public enum ResourceType {
GENERIC, USER, APPL, PROCESS, APPSERVER, SERVER, RUNTIME, VIRTUAL, NETWORK, DEVICE, NETADDR, GEOADDR, DATACENTER, DATASTORE, CACHE, SERVICE, QUEUE, FILE, TOPIC, DATABASE, HTTP
}

public static class DummyEntryDefinition extends EntryDefinition {

public DummyEntryDefinition() {
super(BaseTransformers.class, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2019-2020 NASTEL TECHNOLOGIES, INC.
*
* Licensed 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 com.jkoolcloud.remora.core;

import org.tinylog.TaggedLogger;

public class FilteredOutEntryStack extends CallStack {
public FilteredOutEntryStack(TaggedLogger logger, int limit) {
super(logger, limit);
push(new EntryDefinition.DummyEntryDefinition());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface AdviceFilter {

void countInvoked();

boolean excludeWholeStack();

boolean maches(Object thiz, Method method, Object... arguments);

Mode getMode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class ClassNameFilter extends StatisticEnabledFilter {
@RemoraConfig.Configurable
public boolean regex = false;

@Override
public boolean excludeWholeStack() {
return false;
}

@Override
public boolean maches(Object thiz, Method method, Object... arguments) {
if (regex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public class LimitingFilter extends StatisticEnabledFilter {
@RemoraConfig.Configurable
public Mode mode = Mode.EXCLUDE;

@RemoraConfig.Configurable
public boolean shouldExcludeWholeStack = true;

@Override
public boolean excludeWholeStack() {
return shouldExcludeWholeStack;
}

@Override
public boolean maches(Object thiz, Method method, Object... arguments) {
if (everyNth <= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(EjbRemoteAdvice.class, thiz, method, arguments)) {
if (!intercept(EjbRemoteAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, EjbRemoteAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -149,7 +149,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(EjbRemoteAdvice.class, obj, method, arguments)) {
if (!intercept(EjbRemoteAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void before(@Advice.This HttpURLConnection thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(HttpUrlConnectionAdvice.class, thiz, method, arguments)) {
if (!intercept(HttpUrlConnectionAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, HttpUrlConnectionAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -141,7 +141,7 @@ public static void after(@Advice.This HttpURLConnection obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(HttpUrlConnectionAdvice.class, obj, method, arguments)) {
if (!intercept(HttpUrlConnectionAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public AgentBuilder.Transformer getAdvice() {
public static void after(@Advice.This InputStream thiz, //
@Advice.Origin Method method //
) {
if (!intercept(InputStreamCloseAdvice.class, thiz, method)) {
if (!intercept(InputStreamCloseAdvice.class, thiz, method, logging ? logger : null)) {
return;
}
if (logging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static void before(@Advice.This InputStream thiz, //
@Advice.Origin Method method//
) {
try {
if (!intercept(InputStreamReadAdvice.class, thiz, method, arguments)) {
if (!intercept(InputStreamReadAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
StreamStats streamStats = StreamsManager.INSTANCE.get(thiz, logging ? logger : null, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public AgentBuilder.Transformer getAdvice() {
public static void after(@Advice.This OutputStream thiz, //
@Advice.Origin Method method //
) {
if (!intercept(OutputStreamCloseAdvice.class, thiz, method)) {
if (!intercept(OutputStreamCloseAdvice.class, thiz, method, logging ? logger : null)) {
return;
}
if (logging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void before(@Advice.This OutputStream thiz, //
@Advice.Origin Method method//
) {
try {
if (!intercept(OutputStreamWriteAdvice.class, thiz, method, arguments)) {
if (!intercept(OutputStreamWriteAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
StreamsManager.INSTANCE.get(thiz, logging ? logger : null, method).advanceCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static void before(@Advice.This Object thiz, //
// @Advice.Local("remoraLogger") Logger logger) //
{
try {
if (!intercept(JavaxServletAdvice.class, thiz, method, req, resp)) {
if (!intercept(JavaxServletAdvice.class, thiz, method, logging ? logger : null, req, resp)) {
return;
}
if (logging) {
Expand Down Expand Up @@ -232,7 +232,7 @@ public static void after(@Advice.This Object obj, //
{
boolean doFinally = true;
try {
if (!intercept(JavaxServletAdvice.class, obj, method, req, resp)) {
if (!intercept(JavaxServletAdvice.class, obj, method, logging ? logger : null, req, resp)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(JBossAdvice.class, thiz, method, arguments)) {
if (!intercept(JBossAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, JBossAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -141,7 +141,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(JBossAdvice.class, obj, method, req, resp)) {
if (!intercept(JBossAdvice.class, obj, method, logging ? logger : null, req, resp)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void before(@Advice.This Object thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(JBossServletAdvice.class, thiz, method, arguments)) {
if (!intercept(JBossServletAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, JBossServletAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -125,7 +125,7 @@ public static void after(@Advice.This Object obj, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(JBossServletAdvice.class, obj, method, arguments)) {
if (!intercept(JBossServletAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public static void before(@Advice.This Statement thiz, //
@Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(JDBCCallableStatementAdvice.class, thiz, method, parameterName, parameterValue)) {
if (!intercept(JDBCCallableStatementAdvice.class, thiz, method, logging ? logger : null, parameterName,
parameterValue)) {
return;
}
if (logging) {
Expand Down Expand Up @@ -141,7 +142,7 @@ public static void after(@Advice.This Statement thiz, //
@Advice.Thrown Throwable exception, @Advice.Local("ed") EntryDefinition ed, //
@Advice.Local("startTime") long startTime) {
try {
if (!intercept(JDBCCallableStatementAdvice.class, thiz, method)) {
if (!intercept(JDBCCallableStatementAdvice.class, thiz, method, logging ? logger : null)) {
return;
}
stackThreadLocal.get().pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void before(@Advice.This Statement thiz, //
// if (isChainedClassInterception(JDBCStatementAdvice.class, logging ? logger : null)) {
// return;
// }
if (!intercept(JDBCStatementAdvice.class, thiz, method, arguments)) {
if (!intercept(JDBCStatementAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
ed = getEntryDefinition(ed, JDBCStatementAdvice.class, logging ? logger : null);
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void after(@Advice.This Statement thiz, //
@Advice.Local("startTime") long startTime) {
boolean doFinally = true;
try {
if (!intercept(JDBCStatementAdvice.class, thiz, method)) {
if (!intercept(JDBCStatementAdvice.class, thiz, method, logging ? logger : null)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void before(@Advice.This ConnectionFactory thiz, //
// @Advice.Local("remoraLogger") Logger logger) //
{
try {
if (!intercept(JMSCreateConnectionAdvice.class, thiz, method, arguments)) {
if (!intercept(JMSCreateConnectionAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
if (logging) {
Expand Down Expand Up @@ -157,7 +157,7 @@ public static void after(@Advice.This ConnectionFactory obj, //
{
boolean doFinally = true;
try {
if (!intercept(JMSCreateConnectionAdvice.class, obj, method, arguments)) {
if (!intercept(JMSCreateConnectionAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) { // ed expected to be null if not created by entry, that's for duplicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void before(@Advice.This MessageConsumer thiz, //
// @Advice.Local("remoraLogger") Logger logger) // ) //
{
try {
if (!intercept(JMSReceiveAdvice.class, thiz, method, arguments)) {
if (!intercept(JMSReceiveAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
if (logging) {
Expand Down Expand Up @@ -159,7 +159,7 @@ public static void after(@Advice.This MessageConsumer obj, //
{
boolean doFinnaly = true;
try {
if (!intercept(JMSReceiveAdvice.class, obj, method, arguments)) {
if (!intercept(JMSReceiveAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (logging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static void before(@Advice.This MessageProducer thiz, //
// @Advice.Local("remoraLogger") Logger logger) //
{
try {
if (!intercept(JMSSendAdvice.class, thiz, method, arguments)) {
if (!intercept(JMSSendAdvice.class, thiz, method, logging ? logger : null, arguments)) {
return;
}
if (logging) {
Expand Down Expand Up @@ -147,7 +147,7 @@ public static void after(@Advice.This MessageProducer obj, //
) {
boolean doFinally = true;
try {
if (!intercept(JMSSendAdvice.class, obj, method, arguments)) {
if (!intercept(JMSSendAdvice.class, obj, method, logging ? logger : null, arguments)) {
return;
}
if (ed == null) // noinspection Duplicates
Expand Down
Loading

0 comments on commit eeaca7e

Please sign in to comment.