Skip to content

Commit 3f1f98f

Browse files
committed
updated documentation and improve logger
Signed-off-by: Luiz Oliveira <luiz.oliveira@ibm.com>
1 parent 92850a3 commit 3f1f98f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ req.setAttribute("error-info", "Page not found");
176176

177177
###### Improving error messages
178178

179-
It is possible to filter the error message to avoid long messages or personal info exposed in the metrics. To do it, three params may be used: `error-info-regex`, `error-info-regex-index`, and `error-info-max-size`. The first will set the regex to apply in the message, with `^([a-zA-z0-9 ]{0,120})` as the default value. The second, `error-info-regex-index`, selects the group of the regex's result with `0` as the default value. The last one, `error-info-max-size`, defines the max size of the message to be truncated and has `120` as the default value.
179+
It is possible to filter the error message to avoid long messages or personal info exposed in the metrics. To do it, two params may be used: `error-info-regex` and `error-info-max-size`. The first will set the regex to apply in the message, with `[^A-zÀ-ú .,]+` as the default value. The second, `error-info-max-size`, defines the max size of the message to be truncated and has `50` as the default value.
180180

181181
#### Setting application version
182182

src/main/java/br/com/labbs/monitor/filter/MetricsCollectorFilter.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Properties;
2020
import java.util.regex.Matcher;
2121
import java.util.regex.Pattern;
22+
import java.util.logging.Level;
23+
import java.util.logging.Logger;
2224
/**
2325
* The MetricsFilter class provides a high-level filter that enables collection of (latency, amount and response
2426
* size metrics) for Servlet performance, based on schema, status code, HTTP method and URI path.
@@ -61,8 +63,8 @@ public class MetricsCollectorFilter implements Filter {
6163
private static final String DEFAULT_FILTER_REGEX = "[^A-zÀ-ú .,]+";
6264
private static final String FILTER_REGEX_PARAM = "error-info-regex";
6365
private static final String FILTER_MAX_SIZE_PARAM = "error-info-max-size";
66+
private static final Logger LOGGER = Logger.getLogger(MetricsCollectorFilter.class.getName());
6467
private final List<String> exclusions = new ArrayList<String>();
65-
private int filter_group_index = 0;
6668
private int filter_max_size = 50;
6769
private String filter_regex = "";
6870

@@ -224,8 +226,8 @@ private boolean isErrorStatus(int status) {
224226
* If error message is null, sets the string to empty string.
225227
* If a regex is defined, use it to filter message
226228
*
227-
* Default regex: ^([a-zA-z0-9 ]{0,120})
228-
* Default max size: 120
229+
* Default regex: [^A-zÀ-ú .,]+
230+
* Default max size: 50
229231
*
230232
* @param httpRequest request
231233
* @return string with the error message or empty string if error message not found.
@@ -250,6 +252,7 @@ private String getErrorMessage(HttpServletRequest httpRequest) {
250252
} catch (Exception e) {
251253
// avoid invalid regex or invalid matcher group index
252254
result = "";
255+
LOGGER.warning("Invalid regex: " + e.getMessage());
253256
}
254257
return result;
255258
}

0 commit comments

Comments
 (0)