Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	scouter.agent.java/src/main/java/scouter/xtra/http/UseridUtil.java
  • Loading branch information
gunlee01 committed Sep 14, 2020
2 parents 0802db2 + fab908a commit 2f61fc5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ public static final Configure getInstance() {
public boolean profile_reactor_more_checkpoint_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 @@ -1100,6 +1102,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 @@ -251,16 +251,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 @@ -378,7 +378,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 @@ -395,7 +395,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
@@ -1,8 +1,8 @@
/*
* 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
*
Expand All @@ -12,7 +12,7 @@
* 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.
*/
package scouter.xtra.http;

Expand All @@ -30,7 +30,7 @@
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 @@ -53,7 +53,7 @@ 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());
Expand Down Expand Up @@ -95,7 +95,7 @@ public static long getUserid(ServerHttpRequest req, ServerHttpResponse res, Stri
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 Down Expand Up @@ -147,7 +147,7 @@ public static long getUseridCustom(ServerHttpRequest req, ServerHttpResponse res
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 2f61fc5

Please sign in to comment.