|
12 | 12 | import java.util.Map.Entry; |
13 | 13 | import java.util.concurrent.TimeUnit; |
14 | 14 | import java.util.concurrent.atomic.AtomicLong; |
| 15 | +import java.util.logging.Logger; |
15 | 16 | import java.util.stream.Collectors; |
16 | 17 | import org.phoebus.channelfinder.repository.ChannelRepository; |
17 | 18 | import org.phoebus.channelfinder.repository.PropertyRepository; |
18 | 19 | import org.phoebus.channelfinder.repository.TagRepository; |
19 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 21 | import org.springframework.beans.factory.annotation.Value; |
21 | | -import org.springframework.context.annotation.PropertySource; |
22 | 22 | import org.springframework.scheduling.annotation.Scheduled; |
23 | 23 | import org.springframework.stereotype.Service; |
24 | 24 | import org.springframework.util.LinkedMultiValueMap; |
25 | 25 | import org.springframework.util.MultiValueMap; |
26 | 26 |
|
27 | 27 | @Service |
28 | | -@PropertySource(value = "classpath:application.properties") |
29 | 28 | public class MetricsService { |
| 29 | + private static final Logger logger = Logger.getLogger(MetricsService.class.getName()); |
30 | 30 |
|
31 | 31 | public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count"; |
32 | 32 | public static final String CF_PROPERTY_COUNT = "cf.property.count"; |
@@ -60,7 +60,7 @@ public class MetricsService { |
60 | 60 |
|
61 | 61 | Map<String, List<String>> parseProperties() { |
62 | 62 | if (metricProperties == null || metricProperties.isEmpty()) { |
63 | | - return new LinkedMultiValueMap<>(); |
| 63 | + return Map.of(); |
64 | 64 | } |
65 | 65 | return Arrays.stream(metricProperties.split(";")) |
66 | 66 | .map( |
@@ -121,9 +121,7 @@ public static List<MultiValueMap<String, String>> generateAllMultiValueMaps( |
121 | 121 | List<MultiValueMap<String, String>> allMultiValueMaps = new ArrayList<>(); |
122 | 122 |
|
123 | 123 | 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(); |
127 | 125 | } |
128 | 126 |
|
129 | 127 | List<Entry<String, List<String>>> entries = new ArrayList<>(properties.entrySet()); |
@@ -211,7 +209,12 @@ private void updatePropertyMetrics() { |
211 | 209 |
|
212 | 210 | @Scheduled(fixedRateString = "${metrics.updateInterval}", timeUnit = TimeUnit.SECONDS) |
213 | 211 | 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 | + } |
216 | 219 | } |
217 | 220 | } |
0 commit comments