Skip to content

Commit 14a11e3

Browse files
committed
Fixed sonar errors
1 parent db1f493 commit 14a11e3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ 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+
"([^,=:\\*\\?]+)=(\"(?>[^\\\\\"]*(?:\\\\.)?)*\"|[^,=:\"]*)"
22+
);
2223

2324
public static List<RawMetric> constructMetricsList(ObjectName jmxMetric,
2425
MBeanAttributeInfo[] attributes,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public class PrometheusTextFormatParser {
3939
// Regex to capture metric name, optional labels, value, and optional timestamp.
4040
// Groups: 1=name, 2=labels (content), 3=value, 4=timestamp
4141
private static final Pattern METRIC_LINE_PATTERN = Pattern.compile(
42-
"^([a-zA-Z_:][a-zA-Z0-9_:]*)" // Metric name
43-
+ "(?:\\{([^}]*)\\})?" // Optional labels (content in group 2)
42+
"^([a-zA-Z_:][a-zA-Z0-9_:]*)" // Group 1: Metric name
43+
+ "(?:\\{(?>[^}]*)\\})?" // Group 2: Atomic label content
4444
+ "\\s+"
45-
+ "(-?(?:Inf|NaN|(?:\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)))" // Value (group 3)
46-
+ "(?:\\s+([0-9]+))?$"); // Optional timestamp (group 4)
45+
+ "(-?(?:Inf|NaN|(?:\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)))" // Group 3: Value
46+
+ "(?:\\s+([0-9]+))?$"); // Group 4: Optional timestamp
47+
4748

4849
private static final Pattern HELP_PATTERN =
4950
Pattern.compile("^# HELP ([a-zA-Z_:][a-zA-Z0-9_:]*) (.*)");

0 commit comments

Comments
 (0)