From 7d6e01b5b654e2842d59b5996457f8f1f7add008 Mon Sep 17 00:00:00 2001 From: thji Date: Mon, 28 Oct 2024 11:33:59 +0800 Subject: [PATCH] feat: optimize operation filter --- .../inst/httpservlet/ServletAdviceHelper.java | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/arex-instrumentation/servlet/arex-httpservlet/src/main/java/io/arex/inst/httpservlet/ServletAdviceHelper.java b/arex-instrumentation/servlet/arex-httpservlet/src/main/java/io/arex/inst/httpservlet/ServletAdviceHelper.java index 81e3b7742..b6d743767 100644 --- a/arex-instrumentation/servlet/arex-httpservlet/src/main/java/io/arex/inst/httpservlet/ServletAdviceHelper.java +++ b/arex-instrumentation/servlet/arex-httpservlet/src/main/java/io/arex/inst/httpservlet/ServletAdviceHelper.java @@ -109,6 +109,11 @@ public static Pair onServiceEnter( return null; } + // skip operation for excludeServiceOperations、includeServiceOperations + if (shouldSkipOperation(adapter, httpServletRequest)) { + CaseEventDispatcher.onEvent(CaseEvent.ofEnterEvent()); + return null; + } // 302 Redirect request String redirectRecordId = getRedirectRecordId(adapter, httpServletRequest); if (StringUtil.isNotEmpty(redirectRecordId)) { @@ -237,17 +242,6 @@ private static boolean shouldSkip(ServletAdapter adapter return false; } String pattern = adapter.getPattern(httpServletRequest); - // As long as one parameter is hit in includeServiceOperations, the operation will not be skipped - if (CollectionUtil.isNotEmpty(Config.get().getIncludeServiceOperations()) && - !(IgnoreUtils.includeOperation(pattern) || - IgnoreUtils.includeOperation(requestURI))) { - return true; - } - // As long as one parameter is hit in excludeServiceOperations, the operation will be skipped - if (IgnoreUtils.excludeOperation(pattern) || - IgnoreUtils.excludeOperation(requestURI)) { - return true; - } // Filter invalid servlet path suffix if (FILTERED_GET_URL_SUFFIX.stream().anyMatch(requestURI::endsWith)) { @@ -263,6 +257,38 @@ private static boolean shouldSkip(ServletAdapter adapter return Config.get().invalidRecord(pattern); } + private static boolean shouldSkipOperation(ServletAdapter adapter, + TRequest httpServletRequest) { + String caseId = adapter.getRequestHeader(httpServletRequest, ArexConstants.RECORD_ID); + // Replay scene + if (StringUtil.isNotEmpty(caseId)) { + return Config.get().getBoolean(ConfigConstants.DISABLE_REPLAY, false); + } + + String forceRecord = adapter.getRequestHeader(httpServletRequest, + ArexConstants.FORCE_RECORD, ArexConstants.HEADER_X_PREFIX); + // Do not skip if header with arex-force-record=true + if (Boolean.parseBoolean(forceRecord)) { + return false; + } + + String requestURI = adapter.getRequestURI(httpServletRequest); + if (StringUtil.isEmpty(requestURI)) { + return false; + } + + String pattern = adapter.getPattern(httpServletRequest); + // As long as one parameter is hit in includeServiceOperations, the operation will not be skipped + if (CollectionUtil.isNotEmpty(Config.get().getIncludeServiceOperations()) && + !(IgnoreUtils.includeOperation(pattern) || + IgnoreUtils.includeOperation(requestURI))) { + return true; + } + // As long as one parameter is hit in excludeServiceOperations, the operation will be skipped + return IgnoreUtils.excludeOperation(pattern) || + IgnoreUtils.excludeOperation(requestURI); + } + private static String getRedirectRecordId(ServletAdapter adapter, TRequest httpServletRequest) { String redirectRecordId = adapter.getParameterFromQueryString(httpServletRequest, ArexConstants.RECORD_ID);