Skip to content

Commit 9e4f180

Browse files
committed
SonarQube fixes
1 parent fa2ffe3 commit 9e4f180

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

api/src/main/java/io/kafbat/ui/service/metrics/scrape/jmx/JmxMetricsFormatter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class JmxMetricsFormatter {
1818

1919
// copied from https://github.com/prometheus/jmx_exporter/blob/b6b811b4aae994e812e902b26dd41f29364c0e2b/collector/src/main/java/io/prometheus/jmx/JmxMBeanPropertyCache.java#L15
2020
private static final Pattern PROPERTY_PATTERN = Pattern.compile(
21-
"([^,=:\\*\\?]+)=(\"(?:\\\\.|[^\\\\\"])*\"|[^,=:\"]*)"
21+
"([^,=:\\*\\?]+)=(\"(?:[^\\\\\"]*(?:\\\\.)?)*\"|[^,=:\"]*)"
2222
);
2323

2424
private JmxMetricsFormatter() {
@@ -73,6 +73,11 @@ private static Optional<BigDecimal> convertNumericValue(Object value) {
7373
private static LinkedHashMap<String, String> getLabelsMap(ObjectName mbeanName) {
7474
LinkedHashMap<String, String> keyProperties = new LinkedHashMap<>();
7575
String properties = mbeanName.getKeyPropertyListString();
76+
77+
if (properties.length() > 1024) {
78+
throw new IllegalArgumentException("MBean key property list too long: " + properties);
79+
}
80+
7681
Matcher match = PROPERTY_PATTERN.matcher(properties);
7782
while (match.lookingAt()) {
7883
String labelName = fixIllegalChars(match.group(1)); // label names should be fixed

api/src/main/java/io/kafbat/ui/service/metrics/scrape/prometheus/PrometheusTextFormatParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ public class PrometheusTextFormatParser {
4040
// Groups: 1=name, 2=labels (content), 3=value, 4=timestamp
4141
private static final Pattern METRIC_LINE_PATTERN = Pattern.compile(
4242
"^([a-zA-Z_:][a-zA-Z0-9_:]*)" // Metric name
43-
+ "(?:\\{([^}]*)\\})?" // Optional labels (content in group 2)
43+
+ "(?:\\{([^}]*)})?" // Optional labels (content in group 2)
4444
+ "\\s+"
45-
+ "(-?(?:Inf|NaN|(?:\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)))" // Value (group 3)
45+
+ "(-?(?:Inf|NaN|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?))" // Value (group 3)
4646
+ "(?:\\s+(\\d+))?$"); // Group 4: Optional timestamp
4747

4848

0 commit comments

Comments
 (0)