Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize BlockException log #2853

Merged
merged 2 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
public abstract class AbstractRule implements Rule {

/**
* rule id.
*/
private Long id;

/**
* Resource name.
*/
Expand All @@ -39,6 +44,15 @@ public abstract class AbstractRule implements Rule {
*/
private String limitApp;

public Long getId() {
return id;
}

public AbstractRule setId(Long id) {
this.id = id;
return this;
}

@Override
public String getResource() {
return resource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.alibaba.csp.sentinel.eagleeye.EagleEye;
import com.alibaba.csp.sentinel.eagleeye.StatLogger;
import com.alibaba.csp.sentinel.log.LogBase;
import com.alibaba.csp.sentinel.util.StringUtil;

public class EagleEyeLogUtil {

Expand All @@ -40,7 +41,11 @@ public class EagleEyeLogUtil {
.buildSingleton();
}

public static void log(String resource, String exceptionName, String ruleLimitApp, String origin, int count) {
statLogger.stat(resource, exceptionName, ruleLimitApp, origin).count(count);
public static void log(String resource, String exceptionName, String ruleLimitApp, String origin, Long ruleId, int count) {
String ruleIdString = StringUtil.EMPTY;
if (ruleId != null) {
ruleIdString = String.valueOf(ruleId);
}
statLogger.stat(resource, exceptionName, ruleLimitApp, origin, ruleIdString).count(count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode
fireEntry(context, resourceWrapper, obj, count, prioritized, args);
} catch (BlockException e) {
EagleEyeLogUtil.log(resourceWrapper.getName(), e.getClass().getSimpleName(), e.getRuleLimitApp(),
context.getOrigin(), count);
context.getOrigin(), e.getRule().getId(), count);
throw e;
} catch (Throwable e) {
RecordLog.warn("Unexpected entry exception", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EagleEyeLogUtilTest {

@Test
public void testWriteLog() throws Exception {
EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1);
EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1L,1);

final File file = new File(LogBase.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME);
await().timeout(2, TimeUnit.SECONDS)
Expand All @@ -39,7 +39,7 @@ public void testChangeLogBase() throws Exception {
String newLogBase = userHome + File.separator + "tmpLogDir" + System.currentTimeMillis();
System.setProperty(LogBase.LOG_DIR, newLogBase);

EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 1);
EagleEyeLogUtil.log("resourceName", "BlockException", "app1", "origin", 2L,1);


final File file = new File(LogBase.getLogBaseDir() + EagleEyeLogUtil.FILE_NAME);
Expand Down