Skip to content

Commit 4b7b911

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

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@
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 {
29+
private static final Logger logger = Logger.getLogger(MetricsService.class.getName());
3030

3131
public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count";
3232
public static final String CF_PROPERTY_COUNT = "cf.property.count";
@@ -60,7 +60,7 @@ public class MetricsService {
6060

6161
Map<String, List<String>> parseProperties() {
6262
if (metricProperties == null || metricProperties.isEmpty()) {
63-
return new LinkedMultiValueMap<>();
63+
return Map.of();
6464
}
6565
return Arrays.stream(metricProperties.split(";"))
6666
.map(
@@ -121,9 +121,7 @@ public static List<MultiValueMap<String, String>> generateAllMultiValueMaps(
121121
List<MultiValueMap<String, String>> allMultiValueMaps = new ArrayList<>();
122122

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

129127
List<Entry<String, List<String>>> entries = new ArrayList<>(properties.entrySet());
@@ -211,7 +209,12 @@ private void updatePropertyMetrics() {
211209

212210
@Scheduled(fixedRateString = "${metrics.updateInterval}", timeUnit = TimeUnit.SECONDS)
213211
public void updateMetrics() {
214-
updateTagMetrics();
215-
updatePropertyMetrics();
212+
if (tagMetrics != null && !tagMetrics.isEmpty()) {
213+
updateTagMetrics();
214+
}
215+
if (propertyMetrics != null && !propertyMetrics.isEmpty()) {
216+
logger.info("Updating property metrics " + propertyMetrics);
217+
updatePropertyMetrics();
218+
}
216219
}
217220
}

0 commit comments

Comments
 (0)