From c461f9b722b4f8f6be01c56aceead0d9bb812806 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Fri, 16 Oct 2020 08:31:13 +0900 Subject: [PATCH 1/7] [agent.java] anonymous class hook option --- pom.xml | 2 +- scouter.agent.batch/pom.xml | 2 +- scouter.agent.host/pom.xml | 2 +- scouter.agent.java/pom.xml | 2 +- .../main/java/scouter/agent/Configure.java | 6 +++++ .../java/scouter/agent/asm/MethodASM.java | 13 +++++++++++ .../main/java/scouter/agent/util/Tuple.java | 22 +++++++++++++++++++ scouter.common/pom.xml | 2 +- scouter.deploy/pom.xml | 2 +- scouter.server.boot/pom.xml | 2 +- scouter.server/pom.xml | 2 +- scouter.webapp/pom.xml | 2 +- 12 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java diff --git a/pom.xml b/pom.xml index 6a0c4c272..d5e14440f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT pom SCOUTER APM diff --git a/scouter.agent.batch/pom.xml b/scouter.agent.batch/pom.xml index 0b3148738..4e6d26fc2 100644 --- a/scouter.agent.batch/pom.xml +++ b/scouter.agent.batch/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-agent-batch diff --git a/scouter.agent.host/pom.xml b/scouter.agent.host/pom.xml index 2340be0e7..41e1c53d4 100644 --- a/scouter.agent.host/pom.xml +++ b/scouter.agent.host/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-agent-host diff --git a/scouter.agent.java/pom.xml b/scouter.agent.java/pom.xml index 53bb75e73..b9774eda2 100644 --- a/scouter.agent.java/pom.xml +++ b/scouter.agent.java/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-agent-java diff --git a/scouter.agent.java/src/main/java/scouter/agent/Configure.java b/scouter.agent.java/src/main/java/scouter/agent/Configure.java index 28c676ba0..0c49cc7dd 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/Configure.java +++ b/scouter.agent.java/src/main/java/scouter/agent/Configure.java @@ -198,6 +198,8 @@ public static final Configure getInstance() { @ConfigDesc("profile reactor's important checkpoint") public boolean profile_reactor_checkpoint_enabled = true; + @ConfigDesc("reactor's important checkpoint scan depth") + public int profile_reactor_checkpoint_search_depth = 5; @ConfigDesc("profile reactor's another checkpoints") public boolean profile_reactor_more_checkpoint_enabled = false; @@ -597,6 +599,8 @@ public static final Configure getInstance() { public boolean hook_method_access_none_enabled = false; @ConfigDesc("Activating lambda Method hooking") public boolean hook_method_lambda_enable = true; + @ConfigDesc("Activating anonymous Method hooking") + public boolean hook_method_anonymous_enable = true; @ConfigDesc("Method set for service hooking") @ConfigValueType(ValueType.COMMA_SEPARATED_VALUE) @@ -989,6 +993,7 @@ private void apply() { this.hook_method_access_private_enabled = getBoolean("hook_method_access_private_enabled", false); this.hook_method_access_none_enabled = getBoolean("hook_method_access_none_enabled", false); this.hook_method_lambda_enable = getBoolean("hook_method_lambda_enable", true); + this.hook_method_anonymous_enable = getBoolean("hook_method_anonymous_enable", true); this.hook_method_ignore_prefixes = StringUtil.removeWhitespace(getValue("hook_method_ignore_prefixes", "get,set")); this._hook_method_ignore_prefix = StringUtil.split(this.hook_method_ignore_prefixes, ","); @@ -1087,6 +1092,7 @@ private void apply() { this.profile_elasticsearch_full_query_enabled = getBoolean("profile_elasticsearch_full_query_enabled", false); this.profile_reactor_checkpoint_enabled = getBoolean("profile_reactor_checkpoint_enabled", true); + this.profile_reactor_checkpoint_search_depth = getInt("profile_reactor_checkpoint_search_depth", 5); this.profile_reactor_more_checkpoint_enabled = getBoolean("profile_reactor_more_checkpoint_enabled", false); this.net_udp_collection_interval_ms = getInt("net_udp_collection_interval_ms", 100); diff --git a/scouter.agent.java/src/main/java/scouter/agent/asm/MethodASM.java b/scouter.agent.java/src/main/java/scouter/agent/asm/MethodASM.java index 52a8e84ae..ff38ff170 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/asm/MethodASM.java +++ b/scouter.agent.java/src/main/java/scouter/agent/asm/MethodASM.java @@ -74,6 +74,10 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class if (conf.isIgnoreMethodClass(className)) return cv; + if (!conf.hook_method_anonymous_enable && classIsAnnon(className)) { + return cv; + } + for (int i = 0; i < target.size(); i++) { HookingSet mset = target.get(i); if (mset.classMatch.include(className)) { @@ -82,6 +86,15 @@ public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc class } return cv; } + + private boolean classIsAnnon(String className) { + int spIndex = className.lastIndexOf('$'); + if (spIndex > 0 && spIndex < className.length() - 1) { + char dig = className.charAt(spIndex + 1); + return dig >= 48 && dig <= 57; + } + return false; + } } class MethodCV extends ClassVisitor implements Opcodes { diff --git a/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java b/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java new file mode 100644 index 000000000..f915098b9 --- /dev/null +++ b/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java @@ -0,0 +1,22 @@ +package scouter.agent.util; +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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. + */ + +/** + * Created by Gun Lee(gunlee01@gmail.com) on 2020/10/15 + */public class Tuple { +} diff --git a/scouter.common/pom.xml b/scouter.common/pom.xml index 6588e4ea0..53e1a6b3e 100644 --- a/scouter.common/pom.xml +++ b/scouter.common/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-common diff --git a/scouter.deploy/pom.xml b/scouter.deploy/pom.xml index dfdac6321..c6bcd11e3 100644 --- a/scouter.deploy/pom.xml +++ b/scouter.deploy/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-deploy diff --git a/scouter.server.boot/pom.xml b/scouter.server.boot/pom.xml index 13e08bac4..84c2ef393 100644 --- a/scouter.server.boot/pom.xml +++ b/scouter.server.boot/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-server-boot diff --git a/scouter.server/pom.xml b/scouter.server/pom.xml index 1867ec9d9..9485030ce 100644 --- a/scouter.server/pom.xml +++ b/scouter.server/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT scouter-server diff --git a/scouter.webapp/pom.xml b/scouter.webapp/pom.xml index a773b76ce..5ea4c0e37 100644 --- a/scouter.webapp/pom.xml +++ b/scouter.webapp/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.10.0 + 2.10.1-SNAPSHOT 4.0.0 From 56bb6a2b3018bde330c9c2d9998c5be7267d0154 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Fri, 16 Oct 2020 08:33:41 +0900 Subject: [PATCH 2/7] [agent.java] fix some webflux filter is separated from controller in xlogs. more enhancement of reactor checkpoint profiling. --- .../ScouterOptimizableOperatorProxy.java | 51 ++++++++++++------- .../scouter/agent/proxy/HttpTraceFactory.java | 3 ++ .../java/scouter/agent/proxy/IHttpTrace.java | 1 + .../scouter/agent/trace/TraceContext.java | 1 + .../java/scouter/agent/trace/TraceMain.java | 11 ++-- .../main/java/scouter/agent/util/Tuple.java | 21 ++++++-- .../java/scouter/xtra/http/HttpTrace.java | 5 ++ .../scouter/xtra/http/WebfluxHttpTrace.java | 6 +++ .../xtra/reactive/ReactiveSupport.java | 11 ++-- 9 files changed, 80 insertions(+), 30 deletions(-) diff --git a/scouter.agent.java/src/main/java/reactor/core/publisher/ScouterOptimizableOperatorProxy.java b/scouter.agent.java/src/main/java/reactor/core/publisher/ScouterOptimizableOperatorProxy.java index 77c61b493..069ef24ac 100644 --- a/scouter.agent.java/src/main/java/reactor/core/publisher/ScouterOptimizableOperatorProxy.java +++ b/scouter.agent.java/src/main/java/reactor/core/publisher/ScouterOptimizableOperatorProxy.java @@ -19,6 +19,7 @@ package reactor.core.publisher; import scouter.agent.Logger; +import scouter.agent.util.Tuple; /** * @author Gun Lee (gunlee01@gmail.com) on 2020/08/08 @@ -26,10 +27,11 @@ public class ScouterOptimizableOperatorProxy { public static final String EMPTY = ""; + public static final Tuple.StringLongPair EMPTYOBJ = new Tuple.StringLongPair("", 0); public static boolean accessible = false; public static boolean first = true; - public static String nameOnCheckpoint(Object candidate) { + public static Tuple.StringLongPair nameOnCheckpoint(Object candidate, int maxScanDepth) { try { if (!accessible && first) { try { @@ -42,34 +44,47 @@ public static String nameOnCheckpoint(Object candidate) { first = false; } if (!accessible) { - return EMPTY; + return EMPTYOBJ; } if (candidate instanceof OptimizableOperator) { - OptimizableOperator operator = ((OptimizableOperator) candidate).nextOptimizableSource(); - if (operator == null) { - return EMPTY; + OptimizableOperator closeAssembly = findCloseAssembly((OptimizableOperator) candidate, maxScanDepth); + if (closeAssembly == null) { + return EMPTYOBJ; } - if (operator instanceof MonoOnAssembly) { - FluxOnAssembly.AssemblySnapshot snapshot = ((MonoOnAssembly) operator).stacktrace; + if (closeAssembly instanceof MonoOnAssembly) { + FluxOnAssembly.AssemblySnapshot snapshot = ((MonoOnAssembly) closeAssembly).stacktrace; if (snapshot != null && snapshot.checkpointed) { - return snapshot.cached; + return new Tuple.StringLongPair(snapshot.cached, snapshot.hashCode()); } - } else if (operator instanceof FluxOnAssembly) { - FluxOnAssembly.AssemblySnapshot snapshot = ((FluxOnAssembly) operator).snapshotStack; + } else if (closeAssembly instanceof FluxOnAssembly) { + FluxOnAssembly.AssemblySnapshot snapshot = ((FluxOnAssembly) closeAssembly).snapshotStack; if (snapshot != null && snapshot.checkpointed) { - return snapshot.cached; + return new Tuple.StringLongPair(snapshot.cached, snapshot.hashCode()); } } } - return EMPTY; + return EMPTYOBJ; } catch (Throwable e) { - return EMPTY; + return EMPTYOBJ; } } - public static void appendSources4Dump(Object candidate, StringBuilder builder) { + public static OptimizableOperator findCloseAssembly(OptimizableOperator candidate, int maxScanDepth) { + OptimizableOperator operator = candidate; + for (int i = 0; i < maxScanDepth; i++) { + operator = operator.nextOptimizableSource(); + if (operator == null) { + return null; + } else if (operator instanceof MonoOnAssembly || operator instanceof FluxOnAssembly) { + return operator; + } + } + return null; + } + + public static void appendSources4Dump(Object candidate, StringBuilder builder, int maxScanDepth) { try { if (!accessible && first) { try { @@ -86,14 +101,14 @@ public static void appendSources4Dump(Object candidate, StringBuilder builder) { } if (candidate instanceof OptimizableOperator) { - OptimizableOperator operator = ((OptimizableOperator) candidate).nextOptimizableSource(); - if (operator == null) { + OptimizableOperator closeAssembly = findCloseAssembly((OptimizableOperator) candidate, maxScanDepth); + if (closeAssembly == null) { return; } - String p1 = operator.toString(); + String p1 = closeAssembly.toString(); builder.append(" (<-) ").append(p1); if (p1.startsWith("checkpoint")) { - OptimizableOperator operator2 = operator.nextOptimizableSource(); + OptimizableOperator operator2 = closeAssembly.nextOptimizableSource(); if (operator2 != null) { builder.append(" (<-) ").append(operator2.toString()); } diff --git a/scouter.agent.java/src/main/java/scouter/agent/proxy/HttpTraceFactory.java b/scouter.agent.java/src/main/java/scouter/agent/proxy/HttpTraceFactory.java index c5eec330e..b440d3950 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/proxy/HttpTraceFactory.java +++ b/scouter.agent.java/src/main/java/scouter/agent/proxy/HttpTraceFactory.java @@ -40,6 +40,9 @@ public String getCookie(Object req, String key) { public String getRequestURI(Object req) { return null; } + public String getRequestId(Object req) { + return null; + } public String getRemoteAddr(Object req) { return null; } diff --git a/scouter.agent.java/src/main/java/scouter/agent/proxy/IHttpTrace.java b/scouter.agent.java/src/main/java/scouter/agent/proxy/IHttpTrace.java index b24759784..4de54b612 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/proxy/IHttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/agent/proxy/IHttpTrace.java @@ -35,6 +35,7 @@ public interface IHttpTrace { String getHeader(Object req, String key); String getCookie(Object req, String key); String getRequestURI(Object req); + String getRequestId(Object req); String getRemoteAddr(Object req); String getMethod(Object req); String getQueryString(Object req); diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java index 72e775fd9..482afca3b 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java @@ -57,6 +57,7 @@ public enum GetBy { public boolean isReactiveStarted; public boolean isReactiveTxidMarked; public long exchangeHashCode; + public String serverReqId; public boolean isCoroutineStarted; public boolean isOnCoroutineIdUpdating; diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java index 7c01d6ff2..d22afd899 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java @@ -160,8 +160,15 @@ public static void startReactiveHttpService(Object exchange) { try { Object req = AbstractPlugin.invokeMethod(exchange, "getRequest"); Object res = AbstractPlugin.invokeMethod(exchange, "getResponse"); + if (reactiveHttp == null) { + initReactiveHttp(req); + } + String serverReqId = reactiveHttp.getRequestId(req); TraceContext ctx = TraceContextManager.getContext(); + if (ctx != null && serverReqId != null && ctx.serverReqId == serverReqId) { + return; + } if (ctx != null && ctx.exchangeHashCode != exchange.hashCode()) { //Logger.trace("exchange hash is different on context : " + exchange.hashCode() + " : " + ctx.exchangeHashCode); ctx = null; @@ -287,9 +294,6 @@ private static void addHttpServiceName(TraceContext ctx, Object req) { private static Object lock = new Object(); private static Object startReactiveHttp(Object req, Object res, Object exchange) { - if (reactiveHttp == null) { - initReactiveHttp(req); - } return startHttp(req, res, reactiveHttp, true, exchange); } @@ -307,6 +311,7 @@ private static Object startHttp(Object req, Object res, IHttpTrace http0, boolea ctx.initScannables(); ctx.isReactiveStarted = true; ctx.exchangeHashCode = exchange.hashCode(); + ctx.serverReqId = reactiveHttp.getRequestId(req); } ctx.thread = Thread.currentThread(); ctx.threadId = ctx.thread.getId(); diff --git a/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java b/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java index f915098b9..2c44bd1d6 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java +++ b/scouter.agent.java/src/main/java/scouter/agent/util/Tuple.java @@ -1,9 +1,9 @@ package scouter.agent.util; /* - * Copyright 2015 the original author or authors. + * Copyright 2015 the original author or authors. * @https://github.com/scouter-project/scouter * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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 * @@ -13,10 +13,21 @@ * 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. + * limitations under the License. */ - + /** * Created by Gun Lee(gunlee01@gmail.com) on 2020/10/15 - */public class Tuple { + */ +public class Tuple { + + public static class StringLongPair { + public String aString; + public long aLong; + + public StringLongPair(String aString, long aLong) { + this.aString = aString; + this.aLong = aLong; + } + } } diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java index 6bd2f2560..e3b4a886b 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java @@ -159,6 +159,11 @@ public String getRequestURI(Object req) { return getRequestURI(request); } + @Override + public String getRequestId(Object req) { + return null; + } + @Override public String getRemoteAddr(Object req) { HttpServletRequest request = (HttpServletRequest) req; diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java index bed41e85b..efc5ebad8 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java @@ -156,6 +156,12 @@ public String getRequestURI(Object req) { return getRequestURI((ServerHttpRequest) req); } + @Override + public String getRequestId(Object req) { + ServerHttpRequest request = (ServerHttpRequest) req; + return request.getId(); + } + @Override public String getRemoteAddr(Object req) { return getRemoteAddr((ServerHttpRequest) req); diff --git a/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java index 474ae2989..0a7918e54 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/reactive/ReactiveSupport.java @@ -40,6 +40,7 @@ import scouter.agent.trace.TraceContext; import scouter.agent.trace.TraceContextManager; import scouter.agent.trace.TraceMain; +import scouter.agent.util.Tuple; import scouter.lang.enumeration.ParameterizedMessageLevel; import scouter.lang.step.ParameterizedMessageStep; import scouter.util.StringUtil; @@ -176,7 +177,10 @@ public TxidLifter(CoreSubscriber coreSubscriber, Scannable scannable, Publish this.publisher = publisher; this.traceContext = traceContext; - checkpointDesc = ScouterOptimizableOperatorProxy.nameOnCheckpoint(scannable); + Tuple.StringLongPair checkpointPair = ScouterOptimizableOperatorProxy + .nameOnCheckpoint(scannable, configure.profile_reactor_checkpoint_search_depth); + checkpointDesc = checkpointPair.aString; + Integer parentDepth = context.getOrDefault(SubscribeDepth.class, 0); depth = (!"".equals(checkpointDesc)) ? parentDepth + 1 : parentDepth; this.ctx = context.put(SubscribeDepth.class, depth); @@ -301,7 +305,7 @@ private void profileCheckPoint(Scannable scannable, TraceContext traceContext, R } String message = messageBuilder.append(scannable.name()) - .append("] close checkpoint -> ") + .append("] near-cp -> ") .append(checkpointDesc).toString(); ParameterizedMessageStep step = new ParameterizedMessageStep(); @@ -320,7 +324,6 @@ private void profileCheckPoint(Scannable scannable, TraceContext traceContext, R } public String dumpScannable(TraceContext traceContext, TraceContext.TimedScannable timedScannable, long now) { - if (traceContext == null || timedScannable == null) { return null; } @@ -329,7 +332,7 @@ public String dumpScannable(TraceContext traceContext, TraceContext.TimedScannab StringBuilder builder = new StringBuilder(1000) .append(scannable.name()).append(" ").append(duration).append("ms"); - ScouterOptimizableOperatorProxy.appendSources4Dump(scannable, builder); + ScouterOptimizableOperatorProxy.appendSources4Dump(scannable, builder, configure.profile_reactor_checkpoint_search_depth); return builder.toString(); } } From 687380e8c8ddf9375c9930ccee4df337cef6329e Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Fri, 16 Oct 2020 08:40:40 +0900 Subject: [PATCH 3/7] [agent.java] fix the elastic search profiling bug when the option profile_elasticsearch_full_query_enabled is true. --- .../java/scouter/xtra/java8/ElasticSearchTracer.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/xtra/java8/ElasticSearchTracer.java b/scouter.agent.java/src/main/java/scouter/xtra/java8/ElasticSearchTracer.java index 83aed6e04..d00c905dd 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/java8/ElasticSearchTracer.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/java8/ElasticSearchTracer.java @@ -70,7 +70,13 @@ private String getRequestDescription0(Object httpRequestBase0, boolean cut) { return StringUtil.limiting(url, 45); } HttpEntity entity = requestBase.getEntity(); + if (entity == null) { + return StringUtil.limiting(url, 45); + } try { + if (err) { + return StringUtil.limiting(url, 45); + } Class clazz = entity.getClass(); Field field = fieldMap.get(clazz); if (field == null) { @@ -79,7 +85,7 @@ private String getRequestDescription0(Object httpRequestBase0, boolean cut) { } Object entityDesc = field.get(entity); if (entityDesc == null) { - return url; + return StringUtil.limiting(url, 45); } else { String append = entityDesc instanceof byte[] ? new String((byte[]) entityDesc) : entityDesc.toString(); @@ -88,12 +94,12 @@ private String getRequestDescription0(Object httpRequestBase0, boolean cut) { } catch (Exception e) { err = true; Logger.println("G177p", "error, so skip it later.", e); - return "No info"; + return StringUtil.limiting(url, 45); } } else { String url = httpRequestBase0.toString(); - if (!conf.profile_elasticsearch_full_query_enabled) { + if (cut) { return StringUtil.limiting(url, 45); } return url; From 3cb60d7b47ded650b5ea8cd482ecfe6a9b8e9f3c Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Tue, 10 Nov 2020 10:39:12 +0900 Subject: [PATCH 4/7] [agent.java] release req, res in context --- .../java/scouter/agent/trace/TraceContext.java | 4 ++-- .../scouter/agent/trace/TraceContextManager.java | 2 ++ .../main/java/scouter/agent/trace/TraceMain.java | 14 +++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java index 482afca3b..e08d8ef6d 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContext.java @@ -78,8 +78,8 @@ public void initScannables() { scannables.setMax(10000); } - public Object req; - public Object res; + public Object _req; + public Object _res; public IHttpTrace http; public TraceContext parent; diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java index 5dd4a901a..fd4c8bf3c 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceContextManager.java @@ -262,6 +262,8 @@ public static void completeDeferred(TraceContext o) { } public static void clearAllContext(TraceContext o) { + o._req = null; + o._res = null; local.set(null); coroutineDebuggingLocal.clear(); //it should be prev of txidLocal clear diff --git a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java index d22afd899..b1d428c10 100644 --- a/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java +++ b/scouter.agent.java/src/main/java/scouter/agent/trace/TraceMain.java @@ -328,8 +328,8 @@ private static Object startHttp(Object req, Object res, IHttpTrace http0, boolea ctx.profile.add(step); http0.start(ctx, req, res); - ctx.req = req; - ctx.res = res; + ctx._req = req; + ctx._res = res; ctx.http = http0; if (ctx.isFullyDiscardService) { @@ -387,7 +387,7 @@ public static void endReactiveHttpService() { if (context == null) { return; } - Stat stat = new Stat(context, context.req, context.res); + Stat stat = new Stat(context, context._req, context._res); endHttpService(stat, null); } @@ -401,7 +401,7 @@ public static void endCanceledHttpService(TraceContext traceContext) { step.start_time = (int) (System.currentTimeMillis() - traceContext.startTime); traceContext.profile.add(step); - endHttpService(new Stat(traceContext), null); + endHttpService(new Stat(traceContext, traceContext._req, traceContext._res), null); } } @@ -423,7 +423,11 @@ public static void endHttpService(Object stat, Throwable thr) { //wait on async servlet completion if (!ctx.asyncServletStarted) { - endHttpServiceFinal(ctx, ctx.req, ctx.res, thr); + Object req = ctx._req; + Object res = ctx._res; + ctx._req = null; + ctx._res = null; + endHttpServiceFinal(ctx, req, res, thr); } else { HashedMessageStep step = new HashedMessageStep(); step.time = -1; From d13dd59c6d97937a9ad9998f72af4e4894d245d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EA=B2=BD=EC=9A=B1?= Date: Tue, 24 Nov 2020 10:45:46 +0900 Subject: [PATCH 5/7] NPE resolve [Z101] check propergation: null --- .../src/main/java/scouter/xtra/http/HttpTrace.java | 6 +++++- .../src/main/java/scouter/xtra/http/WebfluxHttpTrace.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java index e3b4a886b..7950bfef8 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/HttpTrace.java @@ -307,7 +307,11 @@ public void start(TraceContext ctx, Object req, Object res) { if (b3ModeValid) { ctx.gxid = HexCodec.lowerHexToUnsignedLong(b3TraceId); ctx.txid = HexCodec.lowerHexToUnsignedLong(request.getHeader(B3Constant.B3_HEADER_SPANID)); - ctx.caller = HexCodec.lowerHexToUnsignedLong(request.getHeader(B3Constant.B3_HEADER_PARENTSPANID)); + String caller = request.getHeader(B3Constant.B3_HEADER_PARENTSPANID); + if (caller != null) { + ctx.caller = HexCodec.lowerHexToUnsignedLong(caller); + ctx.is_child_tx = true; + } ctx.b3Mode = true; ctx.b3Traceid = b3TraceId; diff --git a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java index efc5ebad8..5ed3e982f 100644 --- a/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java +++ b/scouter.agent.java/src/main/java/scouter/xtra/http/WebfluxHttpTrace.java @@ -278,7 +278,11 @@ public void start(TraceContext ctx, Object req, Object res) { if (b3ModeValid) { ctx.gxid = HexCodec.lowerHexToUnsignedLong(b3TraceId); ctx.txid = HexCodec.lowerHexToUnsignedLong(getHeader(request, B3Constant.B3_HEADER_SPANID)); - ctx.caller = HexCodec.lowerHexToUnsignedLong(getHeader(request, B3Constant.B3_HEADER_PARENTSPANID)); + String caller = getHeader(request, B3Constant.B3_HEADER_PARENTSPANID); + if (caller != null) { + ctx.caller = HexCodec.lowerHexToUnsignedLong(caller); + ctx.is_child_tx = true; + } ctx.b3Mode = true; ctx.b3Traceid = b3TraceId; From 4969135ada20ed18d3396e53df1b2b2aebd6edf2 Mon Sep 17 00:00:00 2001 From: bill23 Date: Fri, 18 Dec 2020 16:37:41 +0900 Subject: [PATCH 6/7] add IS_CONTAINER field --- .../src/main/java/scouter/util/SystemUtil.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scouter.common/src/main/java/scouter/util/SystemUtil.java b/scouter.common/src/main/java/scouter/util/SystemUtil.java index ff9370680..3ee386fa3 100644 --- a/scouter.common/src/main/java/scouter/util/SystemUtil.java +++ b/scouter.common/src/main/java/scouter/util/SystemUtil.java @@ -21,6 +21,8 @@ * */package scouter.util; +import java.io.File; + public class SystemUtil { public static final String USER_NAME = System.getProperty("user.name"); @@ -45,6 +47,15 @@ public class SystemUtil { public static final boolean IS_MAC_OSX = OS_NAME.startsWith("Mac OS X"); public static final boolean IS_WINDOWS = OS_NAME.indexOf("Windows") >= 0; + public static boolean IS_CONTAINER = false; + + static { + try { + File file = new File("/.dockerenv"); + IS_CONTAINER = file.exists() || System.getenv("KUBERNETES_SERVICE_HOST") != null; + } catch (Throwable e) {} + } + public static void main(String[] args) { System.out.println(OS_NAME); } From de5903813a7cfc88b8d21bfbe46619a4f1977b28 Mon Sep 17 00:00:00 2001 From: Gun Lee Date: Sat, 19 Dec 2020 10:36:12 +0900 Subject: [PATCH 7/7] version v2.10.2 --- README.md | 2 +- README_kr.md | 2 +- pom.xml | 2 +- scouter.agent.batch/pom.xml | 2 +- scouter.agent.host/pom.xml | 2 +- scouter.agent.java/pom.xml | 2 +- scouter.common/pom.xml | 2 +- scouter.deploy/pom.xml | 2 +- scouter.server.boot/pom.xml | 2 +- scouter.server/pom.xml | 2 +- scouter.webapp/pom.xml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e64f98bcd..2471171d5 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ SCOUTER can help you. - **Server (Collector)** : save the performance metrics from scouter agents or telegraf. The data is streamed to scouter client. -- **Client (Viewer)** : client program based on RCP. +- **Client (Viewer)** : client program based on RCP. (not support OSX Big Sur.) - **Web API (Since @1.8.0)** : scouter web apis to get counters, XLogs, profiles and another performance metrics via HTTP protocol. - [Web API Guide](./scouter.document/tech/Web-API-Guide.md) diff --git a/README_kr.md b/README_kr.md index 8a29036bd..400ad0f84 100644 --- a/README_kr.md +++ b/README_kr.md @@ -56,7 +56,7 @@ - **Server (Collector)** : Agent가 전송한 데이터를 저장하고 Client 요청시 Client에게 적절한 데이터를 전송 -- **Client (Viewer)** : 수집된 데이터를 보기 위한 RCP 기반 Client 프로그램 +- **Client (Viewer)** : 수집된 데이터를 보기 위한 RCP 기반 Client 프로그램. (OSX Big Sur 미지원) - **Web API (Since @1.8.0)** : 성능 카운터, XLog, 프로파일등의 정보를 HTTP 프로토콜을 통해 제공 - [Web API Guide](./scouter.document/tech/Web-API-Guide_kr.md) diff --git a/pom.xml b/pom.xml index d5e14440f..474692dec 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 pom SCOUTER APM diff --git a/scouter.agent.batch/pom.xml b/scouter.agent.batch/pom.xml index 4e6d26fc2..2de342a19 100644 --- a/scouter.agent.batch/pom.xml +++ b/scouter.agent.batch/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-agent-batch diff --git a/scouter.agent.host/pom.xml b/scouter.agent.host/pom.xml index 41e1c53d4..7c466db45 100644 --- a/scouter.agent.host/pom.xml +++ b/scouter.agent.host/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-agent-host diff --git a/scouter.agent.java/pom.xml b/scouter.agent.java/pom.xml index b9774eda2..167bed022 100644 --- a/scouter.agent.java/pom.xml +++ b/scouter.agent.java/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-agent-java diff --git a/scouter.common/pom.xml b/scouter.common/pom.xml index 53e1a6b3e..b75daa9b5 100644 --- a/scouter.common/pom.xml +++ b/scouter.common/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-common diff --git a/scouter.deploy/pom.xml b/scouter.deploy/pom.xml index c6bcd11e3..2ab4145be 100644 --- a/scouter.deploy/pom.xml +++ b/scouter.deploy/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-deploy diff --git a/scouter.server.boot/pom.xml b/scouter.server.boot/pom.xml index 84c2ef393..735cdbad8 100644 --- a/scouter.server.boot/pom.xml +++ b/scouter.server.boot/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-server-boot diff --git a/scouter.server/pom.xml b/scouter.server/pom.xml index 9485030ce..876b4caf6 100644 --- a/scouter.server/pom.xml +++ b/scouter.server/pom.xml @@ -4,7 +4,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 scouter-server diff --git a/scouter.webapp/pom.xml b/scouter.webapp/pom.xml index 5ea4c0e37..d45ef255a 100644 --- a/scouter.webapp/pom.xml +++ b/scouter.webapp/pom.xml @@ -5,7 +5,7 @@ io.github.scouter-project scouter-parent - 2.10.1-SNAPSHOT + 2.10.2 4.0.0