Skip to content

Commit

Permalink
Merge pull request #738 from youngclown/master
Browse files Browse the repository at this point in the history
[agent.java] SCOUTER Cookie 의 maxAge 설정이 가능한 옵션 추가.
  • Loading branch information
gunlee01 authored Aug 27, 2020
2 parents 9dccf39 + cf46a14 commit fab908a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ public static final Configure getInstance() {
public boolean profile_fullstack_stmt_leak_enabled = false;

//Trace
@ConfigDesc("User ID based(0 : Remote Address, 1 : Cookie, 2 : Scouter Cookie, 2 : Header) \n - able to set value for 1.Cookie and 3.Header \n - refer to 'trace_user_session_key'")
@ConfigDesc("User ID based(0 : Remote IP Address, 1 : Cookie(JSESSIONID), 2 : Cookie(SCOUTER), 3 : Header) \n - able to set value for 1.Cookie and 3.Header \n - refer to 'trace_user_session_key'")
public int trace_user_mode = 2; // 0:Remote IP, 1:JSessionID, 2:Scouter Cookie, 3:Header
@ConfigDesc("Setting a cookie expired time for SCOUTER cookie when trace_user_mode is 2")
public int trace_scouter_cookie_max_age = Integer.MAX_VALUE;
@ConfigDesc("Setting a cookie path for SCOUTER cookie when trace_user_mode is 2")
public String trace_user_cookie_path = "/";

Expand Down Expand Up @@ -1069,6 +1071,7 @@ private void apply() {
this.profile_connection_open_fullstack_enabled = getBoolean("profile_connection_open_fullstack_enabled", false);
this.profile_connection_autocommit_status_enabled = getBoolean("profile_connection_autocommit_status_enabled", false);
this.trace_user_mode = getInt("trace_user_mode", 2);
this.trace_scouter_cookie_max_age = getInt("trace_scouter_cookie_max_age", Integer.MAX_VALUE);
this.trace_user_cookie_path = getValue("trace_user_cookie_path", "/");
this.trace_user_session_key = getValue("trace_user_session_key", "JSESSIONID");
this._trace_auto_service_enabled = getBoolean("_trace_auto_service_enabled", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ public void start(TraceContext ctx, Object req, Object res) {
try {
switch (conf.trace_user_mode) {
case 3:
ctx.userid = UseridUtil.getUseridFromHeader(request, response, conf.trace_user_session_key);
ctx.userid = UseridUtil.getUseridFromHeader(request, conf.trace_user_session_key);
if (ctx.userid == 0 && ctx.remoteIp != null) {
ctx.userid = HashUtil.hash(ctx.remoteIp);
}
break;
case 2:
ctx.userid = UseridUtil.getUserid(request, response, conf.trace_user_cookie_path);
ctx.userid = UseridUtil.getUserid(request, response, conf.trace_user_cookie_path, conf.trace_scouter_cookie_max_age);
break;
case 1:
ctx.userid = UseridUtil.getUseridCustom(request, response, conf.trace_user_session_key);
ctx.userid = UseridUtil.getUseridCustom(request, conf.trace_user_session_key);
if (ctx.userid == 0 && ctx.remoteIp != null) {
ctx.userid = HashUtil.hash(ctx.remoteIp);
}
Expand Down Expand Up @@ -271,7 +271,7 @@ public void start(TraceContext ctx, Object req, Object res) {
if (startTime != null) {
int t = startTime.indexOf("t=");
int ts = startTime.indexOf("ts=");
long startMillis = 0l;
long startMillis = 0L;
if (t >= 0) {
startMillis = Long.parseLong(startTime.substring(t + 2).trim())/1000;
} else if (ts >= 0) {
Expand All @@ -288,7 +288,7 @@ public void start(TraceContext ctx, Object req, Object res) {
if (startTime != null) {
int t = startTime.indexOf("t=");
int ts = startTime.indexOf("ts=");
long startMillis = 0l;
long startMillis = 0L;
if (t >= 0) {
startMillis = Long.parseLong(startTime.substring(t + 2).trim())/1000;
} else if (ts >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import javax.servlet.http.HttpServletResponse;
public class UseridUtil {
private static final String SCOUTE_R = "SCOUTER";
public static long getUserid(HttpServletRequest req, HttpServletResponse res, String cookiePath) {
public static long getUserid(HttpServletRequest req, HttpServletResponse res, String cookiePath, int maxAge) {
try {
String cookie = req.getHeader("Cookie");
if (cookie != null) {
Expand All @@ -48,14 +48,14 @@ public static long getUserid(HttpServletRequest req, HttpServletResponse res, St
if ( cookiePath != null && cookiePath.trim().length() > 0 ) {
c.setPath(cookiePath);
}
c.setMaxAge(Integer.MAX_VALUE);
c.setMaxAge(maxAge);
res.addCookie(c);
} catch (Throwable t) {
Logger.println("A153", t.toString());
}
return 0;
}
public static long getUseridCustom(HttpServletRequest req, HttpServletResponse res, String key) {
public static long getUseridCustom(HttpServletRequest req, String key) {
if (key == null || key.length() == 0)
return 0;
try {
Expand All @@ -81,7 +81,7 @@ public static long getUseridCustom(HttpServletRequest req, HttpServletResponse r
return 0;
}

public static long getUseridFromHeader(HttpServletRequest req, HttpServletResponse res, String key) {
public static long getUseridFromHeader(HttpServletRequest req, String key) {
if (key == null || key.length() == 0)
return 0;
try {
Expand Down
4 changes: 3 additions & 1 deletion scouter.document/main/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,10 @@
public boolean profile_fullstack_stmt_leak_enabled = false;

//Trace
@ConfigDesc("User ID based(0 : Remote Address, 1 : Cookie, 2 : Scouter Cookie, 2 : Header) \n - able to set value for 1.Cookie and 3.Header \n - refer to 'trace_user_session_key'")
@ConfigDesc("User ID based(0 : Remote IP Address, 1 : Cookie(JSESSIONID), 2 : Cookie(SCOUTER), 3 : Header) \n - able to set value for 1.Cookie and 3.Header \n - refer to 'trace_user_session_key'")
public int trace_user_mode = 2; // 0:Remote IP, 1:JSessionID, 2:Scouter Cookie, 3:Header
@ConfigDesc("Setting a cookie expired time for SCOUTER cookie when trace_user_mode is 2")
public int trace_scouter_cookie_max_age = Integer.MAX_VALUE;
@ConfigDesc("Setting a cookie path for SCOUTER cookie when trace_user_mode is 2")
public String trace_user_cookie_path = "/";

Expand Down
8 changes: 5 additions & 3 deletions scouter.document/main/Configuration_kr.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,11 @@ public boolean sfa_dump_enabled = false;
@ConfigDesc("SFA thread dump Interval(ms)")
public int sfa_dump_interval_ms = 10000;

//miscellaneous
@ConfigDesc("User ID based(0 : Remote Address, 1 : JSessionID, 2 : Scouter Cookie)")
public int trace_user_mode = 2; // 0:Remote IP, 1:JSessionID, 2:SetCookie
//Trace
@ConfigDesc("User ID based(0 : Remote IP Address, 1 : Cookie(JSESSIONID), 2 : Cookie(SCOUTER), 3 : Header) \n - able to set value for 1.Cookie and 3.Header \n - refer to 'trace_user_session_key'")
public int trace_user_mode = 2; // 0:Remote IP, 1:JSessionID, 2:Scouter Cookie, 3:Header
@ConfigDesc("Setting a cookie expired time for SCOUTER cookie when trace_user_mode is 2")
public int trace_scouter_cookie_max_age = Integer.MAX_VALUE;
@ConfigDesc("Setting a cookie path for SCOUTER cookie when trace_user_mode is 2")
public String trace_user_cookie_path = "/";

Expand Down

0 comments on commit fab908a

Please sign in to comment.