Skip to content

Commit fa2ffe3

Browse files
committed
SonarQube fixes
1 parent 8005e80 commit fa2ffe3

File tree

7 files changed

+37
-35
lines changed

7 files changed

+37
-35
lines changed

api/src/main/java/io/kafbat/ui/service/KafkaClusterFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,4 @@ private ReactiveFailover<KsqlApiClient> ksqlClient(ClustersProperties.Cluster cl
249249
private List<String> parseUrlList(String url) {
250250
return Stream.of(url.split(",")).map(String::trim).filter(s -> !s.isBlank()).toList();
251251
}
252-
253-
private boolean metricsConfigured(ClustersProperties.Cluster clusterProperties) {
254-
return clusterProperties.getMetrics() != null;
255-
}
256-
257252
}

api/src/main/java/io/kafbat/ui/service/KafkaConnectService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import javax.annotation.Nullable;
3434
import lombok.RequiredArgsConstructor;
3535
import lombok.extern.slf4j.Slf4j;
36-
import org.apache.commons.lang3.StringUtils;
3736
import org.springframework.stereotype.Service;
3837
import org.springframework.web.reactive.function.client.WebClientResponseException;
3938
import reactor.core.publisher.Flux;

api/src/main/java/io/kafbat/ui/service/metrics/SummarizedMetrics.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import java.util.stream.Stream;
2222
import lombok.RequiredArgsConstructor;
2323

24+
/**
25+
* Will be replaced in the next versions.
26+
* @deprecated Since 1.4.0
27+
**/
2428
@Deprecated(forRemoval = true, since = "1.4.0") //used for api backward-compatibility
2529
@RequiredArgsConstructor
2630
public class SummarizedMetrics {

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

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.List;
1515
import java.util.Map;
1616
import java.util.Optional;
17+
import java.util.function.Function;
1718
import java.util.stream.Collectors;
1819
import lombok.Builder;
1920
import lombok.RequiredArgsConstructor;
@@ -123,41 +124,41 @@ public static Mono<ScrapedClusterState> scrape(ClusterDescription clusterDescrip
123124
create(
124125
clusterDescription,
125126
phase1.getT1(),
126-
phase1.getT3(),
127-
phase1.getT4(),
128-
phase2.getT1(),
129-
phase2.getT2(),
127+
topicStateMap(phase1.getT1(), phase1.getT3(), phase1.getT4(), phase2.getT1(), phase2.getT2()),
130128
phase2.getT3(),
131129
phase2.getT4()
132130
)));
133131
}
134132

133+
private static Map<String, TopicState> topicStateMap(
134+
InternalLogDirStats segmentStats,
135+
Map<String, TopicDescription> topicDescriptions,
136+
Map<String, List<ConfigEntry>> topicConfigs,
137+
Map<TopicPartition, Long> latestOffsets,
138+
Map<TopicPartition, Long> earliestOffsets) {
139+
140+
return topicDescriptions.entrySet().stream().map(entry -> new TopicState(
141+
entry.getKey(),
142+
entry.getValue(),
143+
topicConfigs.getOrDefault(entry.getKey(), List.of()),
144+
filterTopic(entry.getKey(), earliestOffsets),
145+
filterTopic(entry.getKey(), latestOffsets),
146+
segmentStats.getTopicStats().get(entry.getKey()),
147+
Optional.ofNullable(segmentStats.getPartitionsStats())
148+
.map(topicForFilter -> filterTopic(entry.getKey(), topicForFilter))
149+
.orElse(null)
150+
)).collect(Collectors.toMap(
151+
TopicState::name,
152+
Function.identity()
153+
));
154+
}
155+
135156
private static ScrapedClusterState create(ClusterDescription clusterDescription,
136157
InternalLogDirStats segmentStats,
137-
Map<String, TopicDescription> topicDescriptions,
138-
Map<String, List<ConfigEntry>> topicConfigs,
139-
Map<TopicPartition, Long> latestOffsets,
140-
Map<TopicPartition, Long> earliestOffsets,
158+
Map<String, TopicState> topicStates,
141159
Map<String, ConsumerGroupDescription> consumerDescriptions,
142160
Table<String, TopicPartition, Long> consumerOffsets) {
143161

144-
145-
Map<String, TopicState> topicStates = new HashMap<>();
146-
topicDescriptions.forEach((name, desc) ->
147-
topicStates.put(
148-
name,
149-
new TopicState(
150-
name,
151-
desc,
152-
topicConfigs.getOrDefault(name, List.of()),
153-
filterTopic(name, earliestOffsets),
154-
filterTopic(name, latestOffsets),
155-
segmentStats.getTopicStats().get(name),
156-
Optional.ofNullable(segmentStats.getPartitionsStats())
157-
.map(topicForFilter -> filterTopic(name, topicForFilter))
158-
.orElse(null)
159-
)));
160-
161162
Map<String, ConsumerGroupState> consumerGroupsStates = new HashMap<>();
162163
consumerDescriptions.forEach((name, desc) ->
163164
consumerGroupsStates.put(

api/src/main/java/io/kafbat/ui/service/metrics/scrape/inferred/InferredMetricsScraper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static void fillConsumerGroupsMetrics(MetricsRegistry registry, ScrapedC
226226
"Current Approximate Lag of a ConsumerGroup at Topic/Partition",
227227
List.of("consumergroup", TOPIC_TAG, PARTITION_TAG),
228228
List.of(groupName, tp.topic(), String.valueOf(tp.partition())),
229-
endOffset - committedOffset //TODO: check +-1
229+
endOffset - committedOffset
230230
));
231231

232232
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public class JmxMetricsFormatter {
2121
"([^,=:\\*\\?]+)=(\"(?:\\\\.|[^\\\\\"])*\"|[^,=:\"]*)"
2222
);
2323

24+
private JmxMetricsFormatter() {
25+
}
26+
2427
public static List<RawMetric> constructMetricsList(ObjectName jmxMetric,
25-
MBeanAttributeInfo[] attributes,
26-
Object[] attrValues) {
28+
MBeanAttributeInfo[] attributes,
29+
Object[] attrValues) {
2730
String domain = fixIllegalChars(jmxMetric.getDomain());
2831
LinkedHashMap<String, String> labels = getLabelsMap(jmxMetric);
2932
String firstLabel = labels.keySet().iterator().next();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class PrometheusTextFormatParser {
4343
+ "(?:\\{([^}]*)\\})?" // Optional labels (content in group 2)
4444
+ "\\s+"
4545
+ "(-?(?:Inf|NaN|(?:\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)))" // Value (group 3)
46-
+ "(?:\\s+([0-9]+))?$"); // Group 4: Optional timestamp
46+
+ "(?:\\s+(\\d+))?$"); // Group 4: Optional timestamp
4747

4848

4949
private static final Pattern HELP_PATTERN =

0 commit comments

Comments
 (0)