Skip to content

Commit acc50f1

Browse files
committed
Only fetch tag and property metrics if set
1 parent 8a9b347 commit acc50f1

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/main/java/org/phoebus/channelfinder/service/MetricsService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
import java.util.Map.Entry;
1313
import java.util.concurrent.TimeUnit;
1414
import java.util.concurrent.atomic.AtomicLong;
15+
import java.util.logging.Logger;
1516
import java.util.stream.Collectors;
1617
import org.phoebus.channelfinder.repository.ChannelRepository;
1718
import org.phoebus.channelfinder.repository.PropertyRepository;
1819
import org.phoebus.channelfinder.repository.TagRepository;
1920
import org.springframework.beans.factory.annotation.Autowired;
2021
import org.springframework.beans.factory.annotation.Value;
21-
import org.springframework.context.annotation.PropertySource;
2222
import org.springframework.scheduling.annotation.Scheduled;
2323
import org.springframework.stereotype.Service;
2424
import org.springframework.util.LinkedMultiValueMap;
2525
import org.springframework.util.MultiValueMap;
2626

2727
@Service
28-
@PropertySource(value = "classpath:application.properties")
2928
public class MetricsService {
30-
3129
public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count";
3230
public static final String CF_PROPERTY_COUNT = "cf.property.count";
3331
public static final String CF_TAG_COUNT = "cf.tag.count";
@@ -60,7 +58,7 @@ public class MetricsService {
6058

6159
Map<String, List<String>> parseProperties() {
6260
if (metricProperties == null || metricProperties.isEmpty()) {
63-
return new LinkedMultiValueMap<>();
61+
return Map.of();
6462
}
6563
return Arrays.stream(metricProperties.split(";"))
6664
.map(
@@ -121,9 +119,7 @@ public static List<MultiValueMap<String, String>> generateAllMultiValueMaps(
121119
List<MultiValueMap<String, String>> allMultiValueMaps = new ArrayList<>();
122120

123121
if (properties.isEmpty()) {
124-
allMultiValueMaps.add(
125-
new LinkedMultiValueMap<>()); // Add an empty map for the case where all are null
126-
return allMultiValueMaps;
122+
return List.of();
127123
}
128124

129125
List<Entry<String, List<String>>> entries = new ArrayList<>(properties.entrySet());
@@ -211,7 +207,11 @@ private void updatePropertyMetrics() {
211207

212208
@Scheduled(fixedRateString = "${metrics.updateInterval}", timeUnit = TimeUnit.SECONDS)
213209
public void updateMetrics() {
214-
updateTagMetrics();
215-
updatePropertyMetrics();
210+
if (tagMetrics != null && !tagMetrics.isEmpty()) {
211+
updateTagMetrics();
212+
}
213+
if (propertyMetrics != null && !propertyMetrics.isEmpty()) {
214+
updatePropertyMetrics();
215+
}
216216
}
217217
}

0 commit comments

Comments
 (0)