Skip to content

Commit 91a67dd

Browse files
authored
Merge pull request #7 from kenfinnigan/fixes
Add some additional debugging
2 parents 56c689c + fb98528 commit 91a67dd

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/main/java/com/redhat/MeterController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ PodWatcher getWatcher() {
259259
private MeterStatus constructStatus() {
260260
final String currentlyWatching = podWatcher != null ? "TRUE" : "FALSE";
261261
final String watchedPodCount = podWatcher != null ? podWatcher.watchedPods() : "UNKNOWN";
262+
// TODO remove
263+
System.out.println("WATCHED POD STATUS: " + watchedPodCount);
262264
final Resource<ServiceMonitor> serviceMonitor = serviceMonitor();
263265
final String serviceMonitorInstalled = serviceMonitor != null ? (serviceMonitor.get() != null ? "TRUE" : "FALSE") : "UNKNOWN";
264266
return new MeterStatus(currentlyWatching, watchedPodCount, serviceMonitorInstalled);

src/main/java/com/redhat/PodWatcher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.function.ToDoubleFunction;
1212
import java.util.stream.Collectors;
1313

14+
import org.jboss.logging.Logger;
15+
1416
import io.fabric8.kubernetes.api.model.Pod;
1517
import io.fabric8.kubernetes.api.model.PodList;
1618
import io.fabric8.kubernetes.api.model.Quantity;
@@ -24,6 +26,8 @@
2426
import io.micrometer.core.instrument.Tags;
2527

2628
class PodWatcher implements Watcher<Pod> {
29+
private static final Logger LOG = Logger.getLogger(PodWatcher.class);
30+
2731
private final KubernetesClient client;
2832
private final MeterRegistry meterRegistry;
2933
private final OperatorConfig config;
@@ -56,6 +60,7 @@ static Map<String, String> convertListToMap(List<String> productNameMapAsList) {
5660

5761
@Override
5862
public void eventReceived(Action action, Pod resource) {
63+
LOG.info("EVENT RECEIVED FOR POD: " + resource.getMetadata().getName());
5964
if (!shouldWatch(spec.getWatchNamespaces(), resource.getMetadata().getNamespace())) {
6065
// If we're not watching all namespaces or the event is from a namespace we're not watching, do nothing
6166
return;
@@ -113,7 +118,8 @@ public void onClose(WatcherException cause) {
113118
}
114119

115120
Boolean shouldWatch(Set<String> watchingNamespaces, String namespace) {
116-
return watchingNamespaces.isEmpty() || watchingNamespaces.contains(namespace);
121+
return watchingNamespaces.isEmpty() || watchingNamespaces.contains(namespace)
122+
|| watchingNamespaces.contains("");
117123
}
118124

119125
static Boolean isInfrastructure(OperatorConfig config, Map<String, String> podLabels) {
@@ -150,7 +156,7 @@ void updateSpec(MeterSpec newSpec) {
150156

151157
PodList pods = client.pods().inAnyNamespace().list();
152158
for (Pod pod : pods.getItems()) {
153-
if (!(newSpec.getWatchNamespaces().isEmpty() || newSpec.getWatchNamespaces().contains(pod.getMetadata().getNamespace()))) {
159+
if (!shouldWatch(newSpec.getWatchNamespaces(), pod.getMetadata().getNamespace())) {
154160
// If we're not watching all namespaces or the event is from a namespace we're not watching, do nothing
155161
continue;
156162
}
@@ -187,6 +193,8 @@ String watchedPods() {
187193
for (PodGroup podGroup : metrics.values()) {
188194
count += podGroup.pods.size();
189195
}
196+
//TODO remove
197+
System.out.println("NUMBER OF WATCHED PODS: " + count);
190198
return Integer.toString(count);
191199
}
192200

src/test/java/com/redhat/PodInclusionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ void testNamespaceWatchedWithEmptyWatches() {
4949
assertTrue(podWatcher.shouldWatch(Collections.emptySet(), "test"));
5050
}
5151

52+
@Test
53+
void testNamespaceWatchedWithEmptyWatch() {
54+
assertTrue(podWatcher.shouldWatch(Set.of(""), "test"));
55+
}
56+
5257
@Test
5358
void testNamespaceWatchedWithDefinedWatches() {
5459
assertTrue(podWatcher.shouldWatch(Set.of("another", "test"), "test"));

0 commit comments

Comments
 (0)