Skip to content

Commit

Permalink
Merge pull request #447 from scouter-project/develop
Browse files Browse the repository at this point in the history
v1.8.4
  • Loading branch information
gunlee01 committed Apr 3, 2018
2 parents 4c61316 + f15e274 commit 36d95f8
Show file tree
Hide file tree
Showing 65 changed files with 2,521 additions and 218 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.github.scouter-project</groupId>
<artifactId>scouter-parent</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
<packaging>pom</packaging>

<name>SCOUTER APM</name>
Expand Down Expand Up @@ -43,7 +43,7 @@
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file:///${project.basedir}/local-maven-repo</url>
<url>file:///${project.basedir}/../local-maven-repo</url>
</repository>
<repository>
<id>redhat.com</id>
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.github.scouter-project</groupId>
<artifactId>scouter-parent</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</parent>

<artifactId>scouter-agent-batch</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.host/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.scouter-project</groupId>
<artifactId>scouter-parent</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</parent>

<artifactId>scouter-agent-host</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scouter.agent.java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.scouter-project</groupId>
<artifactId>scouter-parent</artifactId>
<version>1.8.3</version>
<version>1.8.4</version>
</parent>

<artifactId>scouter-agent-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import scouter.agent.asm.IASM;
import scouter.agent.asm.InitialContextASM;
import scouter.agent.asm.JDBCConnectionOpenASM;
import scouter.agent.asm.JDBCGetConnectionASM;
import scouter.agent.asm.JDBCDriverASM;
import scouter.agent.asm.JDBCPreparedStatementASM;
import scouter.agent.asm.JDBCResultSetASM;
Expand All @@ -48,6 +49,9 @@
import scouter.agent.asm.asyncsupport.RequestStartAsyncASM;
import scouter.agent.asm.asyncsupport.executor.ExecutorServiceASM;
import scouter.agent.asm.asyncsupport.spring.SpringAsyncExecutionASM;
import scouter.agent.asm.redis.JedisConnectionASM;
import scouter.agent.asm.redis.RedisCacheKeyASM;
import scouter.agent.asm.redis.RedisKeyASM;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.util.AsyncRunner;
import scouter.lang.conf.ConfObserver;
Expand Down Expand Up @@ -102,7 +106,7 @@ public static void reload() {
temp.add(new JDBCStatementASM());
temp.add(new SqlMapASM());
temp.add(new UserTxASM());

temp.add(new JDBCGetConnectionASM());
temp.add(new JDBCConnectionOpenASM());
temp.add(new JDBCDriverASM());
temp.add(new InitialContextASM());
Expand All @@ -118,6 +122,9 @@ public static void reload() {
temp.add(new SpringAsyncExecutionASM());
temp.add(new CallRunnableASM());
temp.add(new ExecutorServiceASM());
temp.add(new RedisKeyASM());
temp.add(new RedisCacheKeyASM());
temp.add(new JedisConnectionASM());

temp.add(new SpringReqMapASM());
temp.add(new HystrixCommandASM());
Expand Down
38 changes: 34 additions & 4 deletions scouter.agent.java/src/main/java/scouter/agent/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ public final static synchronized Configure getInstance() {
public boolean profile_fullstack_sql_commit_enabled = false;
@ConfigDesc("Stack profile in occurrence of sql error")
public boolean profile_fullstack_hooked_exception_enabled = false;

@ConfigDesc("Stack profile in occurrence of redis error")
public boolean profile_fullstack_redis_error_enabled = false;
@ConfigDesc("make unknown redis key stringify by force. (using new String(byte[])")
public boolean profile_redis_key_forcibly_stringify_enabled = false;

@ConfigDesc("Number of stack profile lines in occurrence of error")
public int profile_fullstack_max_lines = 0;

Expand Down Expand Up @@ -310,6 +316,8 @@ public final static synchronized Configure getInstance() {
public boolean xlog_error_on_sqlexception_enabled = true;
@ConfigDesc("mark as error on xlog flag if Api call errors are occured.")
public boolean xlog_error_on_apicall_exception_enabled = true;
@ConfigDesc("mark as error on xlog flag if redis error is occured.")
public boolean xlog_error_on_redis_exception_enabled = true;

//XLog hard sampling options
@ConfigDesc("XLog hard sampling mode enabled\n - for the best performance but it affects all statistics data")
Expand Down Expand Up @@ -418,6 +426,11 @@ public final static synchronized Configure getInstance() {
@ConfigValueType(ValueType.COMMA_SEPARATED_VALUE)
public String hook_connection_open_patterns = "";

@ConfigDesc("Method set for getconnection hooking")
@ConfigValueType(ValueType.COMMA_SEPARATED_VALUE)
public String hook_get_connection_patterns = "";


@ConfigDesc("IntialContext Class Set")
@ConfigValueType(ValueType.COMMA_SEPARATED_VALUE)
public String hook_context_classes = "javax/naming/InitialContext";
Expand Down Expand Up @@ -526,6 +539,10 @@ public final static synchronized Configure getInstance() {
@ConfigValueType(ValueType.COMMA_SEPARATED_VALUE)
public String hook_async_callrunnable_scan_package_prefixes = "";

@ConfigDesc("redis key setting patterns.\n refer to org.springframework.data.redis.core.AbstractOperations#rawKey")
@ConfigValueType(ValueType.COMMA_SEPARATED_VALUE)
public String _hook_redis_set_key_patterns = "";

@ConfigDesc("PRE-released option before stable release!\nhook threadpool executor for tracing async processing.")
public boolean hook_async_thread_pool_executor_enabled = false;

Expand Down Expand Up @@ -553,9 +570,13 @@ public final static synchronized Configure getInstance() {
@ConfigDesc("")
public boolean _hook_usertx_enabled = true;
@ConfigDesc("")
public String _hook_direct_patch_classes = "";
@ConfigDesc("")
public boolean _hook_spring_rest_enabled = true;
@ConfigDesc("")
public boolean _hook_redis_enabled = true;

@ConfigDesc("")
public String _hook_direct_patch_classes = "";

@ConfigDesc("")
public String _hook_boot_prefix = null;
@ConfigDesc("for warning a big Map type object that have a lot of entities.\n It may increase system load. be careful to enable this option.")
Expand Down Expand Up @@ -794,7 +815,8 @@ private void apply() {
this.hook_return_patterns = getValue("hook_return_patterns", "");
this.hook_constructor_patterns = getValue("hook_constructor_patterns", "");
this.hook_connection_open_patterns = getValue("hook_connection_open_patterns", "");

this.hook_get_connection_patterns = getValue("hook_get_connection_patterns","");

this._log_datasource_lookup_enabled = getBoolean("_log_datasource_lookup_enabled", true);
this.profile_connection_open_enabled = getBoolean("profile_connection_open_enabled", true);
this._summary_connection_leak_fullstack_enabled = getBoolean("_summary_connection_leak_fullstack_enabled", false);
Expand Down Expand Up @@ -853,6 +875,8 @@ private void apply() {

this.hook_async_callrunnable_scan_package_prefixes = getValue("hook_async_callrunnable_scan_package_prefixes", "");

this._hook_redis_set_key_patterns = getValue("_hook_redis_set_key_patterns", "");

this.hook_async_thread_pool_executor_enabled = getBoolean("hook_async_thread_pool_executor_enabled", false);

this.hook_lambda_instrumentation_strategy_enabled = getBoolean("hook_lambda_instrumentation_strategy_enabled", false);
Expand Down Expand Up @@ -885,6 +909,8 @@ private void apply() {
this.profile_fullstack_sql_error_enabled = getBoolean("profile_fullstack_sql_error_enabled", false);
this.profile_fullstack_sql_commit_enabled = getBoolean("profile_fullstack_sql_commit_enabled", false);
this.profile_fullstack_hooked_exception_enabled = getBoolean("profile_fullstack_hooked_exception_enabled", false);
this.profile_fullstack_redis_error_enabled = getBoolean("profile_fullstack_redis_error_enabled", false);
this.profile_redis_key_forcibly_stringify_enabled = getBoolean("profile_redis_key_forcibly_stringify_enabled", false);

this.profile_fullstack_max_lines = getInt("profile_fullstack_max_lines", 0);
this.profile_fullstack_rs_leak_enabled = getBoolean("profile_fullstack_rs_leak_enabled", false);
Expand Down Expand Up @@ -916,7 +942,11 @@ private void apply() {
this._hook_async_enabled = getBoolean("_hook_async_enabled", true);
this.trace_db2_enabled = getBoolean("trace_db2_enabled", true);
this._hook_usertx_enabled = getBoolean("_hook_usertx_enabled", true);
this._hook_spring_rest_enabled = getBoolean("_hook_spring_rest_enabled", true);
this._hook_redis_enabled = getBoolean("_hook_redis_enabled", true);

this._hook_direct_patch_classes = getValue("_hook_direct_patch_classes", "");

this._hook_boot_prefix = getValue("_hook_boot_prefix");
this._hook_map_impl_enabled = getBoolean("_hook_map_impl_enabled", false);
this._hook_map_impl_warning_size = getInt("_hook_map_impl_warning_size", 50000);
Expand Down Expand Up @@ -969,14 +999,14 @@ private void apply() {
this.__ip_dummy_test = getBoolean("__ip_dummy_test", false);

this.alert_perm_warning_pct = getInt("alert_perm_warning_pct", 90);
this._hook_spring_rest_enabled = getBoolean("_hook_spring_rest_enabled", true);
this.alert_message_length = getInt("alert_message_length", 3000);
this.alert_send_interval_ms = getInt("alert_send_interval_ms", 10000);

this.xlog_error_jdbc_fetch_max = getInt("xlog_error_jdbc_fetch_max", 10000);
this.xlog_error_sql_time_max_ms = getInt("xlog_error_sql_time_max_ms", 30000);
this.xlog_error_on_sqlexception_enabled = getBoolean("xlog_error_on_sqlexception_enabled", true);
this.xlog_error_on_apicall_exception_enabled = getBoolean("xlog_error_on_apicall_exception_enabled", true);
this.xlog_error_on_redis_exception_enabled = getBoolean("xlog_error_on_redis_exception_enabled", true);

this._log_asm_enabled = getBoolean("_log_asm_enabled", false);
this.obj_type_inherit_to_child_enabled = getBoolean("obj_type_inherit_to_child_enabled", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* 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.
*/

package scouter.agent.asm;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import scouter.agent.ClassDesc;
import scouter.agent.Configure;
import scouter.agent.Logger;
import scouter.agent.asm.util.AsmUtil;
import scouter.agent.asm.util.HookingSet;
import scouter.agent.trace.TraceSQL;
import scouter.org.objectweb.asm.ClassVisitor;
import scouter.org.objectweb.asm.MethodVisitor;
import scouter.org.objectweb.asm.Opcodes;
import scouter.org.objectweb.asm.Type;
import scouter.org.objectweb.asm.commons.LocalVariablesSorter;

public class JDBCGetConnectionASM implements IASM, Opcodes {
private List<HookingSet> target = HookingSet.getHookingMethodSet(Configure.getInstance().hook_get_connection_patterns);
private Map<String, HookingSet> reserved = new HashMap<String, HookingSet>();

public JDBCGetConnectionASM() {
//AsmUtil.add(reserved, "weblogic/jdbc/common/internal/RmiDataSource", "getConnection()Ljava/sql/Connection;");

}

public ClassVisitor transform(ClassVisitor cv, String className, ClassDesc classDesc) {
if (Configure.getInstance()._hook_dbsql_enabled == false) {
return cv;
}

HookingSet mset = reserved.get(className);
if (mset != null)
return new DataSourceCV(cv, mset, className);

for (int i = 0; i < target.size(); i++) {
mset = target.get(i);
if (mset.classMatch.include(className)) {
return new DataSourceCV(cv, mset, className);
}
}
return cv;
}
}

class DataSourceCV extends ClassVisitor implements Opcodes {

public String className;
private HookingSet mset;

public DataSourceCV(ClassVisitor cv, HookingSet mset, String className) {
super(ASM5, cv);
this.mset = mset;
this.className = className;

}

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
if (mv == null || mset.isA(name, desc) == false) {
return mv;
}
if (AsmUtil.isSpecial(name)) {
return mv;
}
return new DataSourceMV(access, desc, mv, className,name);
}
}

// ///////////////////////////////////////////////////////////////////////////
class DataSourceMV extends LocalVariablesSorter implements Opcodes {
private static final String TRACE_SQL = TraceSQL.class.getName().replace('.', '/');
private final static String METHOD = "getConnection";
private static final String SIGNATURE = "(Ljava/sql/Connection;)Ljava/sql/Connection;";

private Type returnType;
private String className;
private String methodName;
private String methodDesc;

public DataSourceMV(int access, String desc, MethodVisitor mv, String className, String methodName) {
super(ASM5,access, desc, mv);
this.returnType = Type.getReturnType(desc);
this.className = className;
this.methodName = methodName;
this.methodDesc = desc;
}


@Override
public void visitInsn(int opcode) {
if ((opcode >= IRETURN && opcode <= RETURN)) {
int i = newLocal(this.returnType);
mv.visitVarInsn(ASTORE, i);
mv.visitVarInsn(Opcodes.ALOAD, i);
AsmUtil.PUSH(mv, className);
AsmUtil.PUSH(mv, methodName);
AsmUtil.PUSH(mv, methodDesc);
mv.visitVarInsn(Opcodes.ALOAD, 0);

mv.visitVarInsn(Opcodes.ALOAD, i);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACE_SQL, METHOD, SIGNATURE,false);

}
mv.visitInsn(opcode);
}


}
Loading

0 comments on commit 36d95f8

Please sign in to comment.