CloudEventReporter extends ControllerMaintainer { @Override protected boolean maintain() { int numberOfInfrastructureEvents = 0; for (var awsRegion : zonesByCloudNativeRegion.keySet()) { List<CloudEvent> events = eventFetcher.getEvents(awsRegion); for (var event : events) { log.info(String.format("Retrieved event %s, affecting the following instances: %s", event.instanceEventId, event.affectedInstances)); List<Node> needsManualIntervention = handleInstances(awsRegion, event); if (!needsManualIntervention.isEmpty()) { numberOfInfrastructureEvents += needsManualIntervention.size(); submitIssue(event); } } } metric.set(INFRASTRUCTURE_INSTANCE_EVENTS, numberOfInfrastructureEvents, metric.createContext(Collections.emptyMap())); return true; } CloudEventReporter(Controller controller, Duration interval, Metric metric);   }
@Test public void maintain() { setUpZones(); CloudEventReporter cloudEventReporter = new CloudEventReporter(tester.controller(), Duration.ofMinutes(15), metrics); assertEquals(Set.of("host1.com", "host2.com", "host3.com"), getHostnames(nonAwsZone.getId())); assertEquals(Set.of("host1.com", "host2.com", "host3.com"), getHostnames(awsZone1.getId())); assertEquals(Set.of("host4.com", "host5.com", "confighost.com"), getHostnames(awsZone2.getId())); mockEvents(); cloudEventReporter.maintain(); assertEquals(Set.of("host1.com", "host2.com", "host3.com"), getHostnames(nonAwsZone.getId())); assertEquals(Set.of("host3.com"), getHostnames(awsZone1.getId())); assertEquals(Set.of("host4.com", "confighost.com"), getHostnames(awsZone2.getId())); Map<IssueId, MockIssueHandler.MockIssue> createdIssues = tester.serviceRegistry().issueHandler().issues(); assertEquals(1, createdIssues.size()); String description = createdIssues.get(IssueId.from("1")).issue().description(); assertTrue(description.contains("confighost")); assertEquals(1, metrics.getMetric("infrastructure_instance_events")); }