@Test public void testRun() throws Exception { fixtures.appConfigMocks() .enableAlerts() .runOnce() .checkMeter("RefocusLoadFailureWARN", 999.0) .checkMeter("RefocusLoadFailureERR", 999.0); try { fixtures.enableLatches() .realSystemStatus() .oneArgusToRefocusConfiguration() .callRealRefocusLoadProcessor() .initializeFixtures() .returnMockedTransformationResultFromAllExtractProcessors(); SystemStatusConsumer systemStatusConsumer = fixtures.statusConsumer(); ConfigurationUpdateManager manager = fixtures.configurationManager(); manager.run(); AppBootstrapLatches.holdOffBeforeExtractProcessorStarts().countDown(); AppBootstrapLatches.holdOffBeforeLoadProcessorStarts().countDown(); fixtures.awaitUntilAllTasksHaveBeenProcessed(true); fixtures.systemStatus().run(); @SuppressWarnings("unchecked") ArgumentCaptor<List<StatusMessage>> argumentCaptor = ArgumentCaptor.forClass(List.class); verify(fixtures.systemStatus(), atLeastOnce()).meter("Refocus", MeterType.LoadFailure); verify(fixtures.systemStatus(), atLeastOnce()).timer("Refocus", "upsert-samples-bulk." + AppBootstrapFixtures.MOCK_CONNECTOR_NAME); verify(systemStatusConsumer, atLeastOnce()).accept(argumentCaptor.capture()); List<StatusMessage> messages = argumentCaptor.getValue(); assertThat("Expecting one message, status=OK", messages, hasSize(1)); assertThat("The status should be OK", messages.get(0).level(), is(StatusCode.OK)); ArgumentCaptor<StatusMessage> timerMessageCaptor = ArgumentCaptor.forClass(StatusMessage.class); verify(fixtures.systemStatus(), atLeastOnce()).logStatusMessage(timerMessageCaptor.capture()); List<String> timerMessages = timerMessageCaptor.getAllValues().stream().map(Object::toString).collect(Collectors.toList()); assertThat("AppBootstrapFixtures should report timing data for the Refocus Load processor", timerMessages, hasItem(containsString("Refocus.upsert-samples-bulk." + AppBootstrapFixtures.MOCK_CONNECTOR_NAME))); } finally { AppBootstrapLatches.release(); } }
@Override public void run() { final List<StatusMessage> messages = new ArrayList<>(); for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { String meterName = entry.getKey(); double meterValue = entry.getValue().getCount(); registry.remove(meterName); Optional<StatusMessage> errMessage = checkRateOfMeter(meterName, StatusCode.CRIT, meterValue); Optional<StatusMessage> warnMessage = checkRateOfMeter(meterName, StatusCode.WARN, meterValue); if (errMessage.isPresent()) { messages.add(errMessage.get()); } else if (warnMessage.isPresent()) { messages.add(warnMessage.get()); } } if (messages.isEmpty()) { messages.add(new StatusMessage(StatusCode.OK, SYSTEM_STATUS + " " + StatusCode.OK.name())); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { String timerName = entry.getKey(); long percentileMillis = TimeUnit.NANOSECONDS.toMillis((long)entry.getValue().getSnapshot().get95thPercentile()); logStatusMessage(createTimerStatusMessage(SYSTEM_STATUS + " " + timerName, percentileMillis)); } consumers.parallelStream().forEach(consumer -> consumer.accept(messages)); }
SystemStatusRunnable implements SystemStatus { @Override public void run() { final List<StatusMessage> messages = new ArrayList<>(); for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { String meterName = entry.getKey(); double meterValue = entry.getValue().getCount(); registry.remove(meterName); Optional<StatusMessage> errMessage = checkRateOfMeter(meterName, StatusCode.CRIT, meterValue); Optional<StatusMessage> warnMessage = checkRateOfMeter(meterName, StatusCode.WARN, meterValue); if (errMessage.isPresent()) { messages.add(errMessage.get()); } else if (warnMessage.isPresent()) { messages.add(warnMessage.get()); } } if (messages.isEmpty()) { messages.add(new StatusMessage(StatusCode.OK, SYSTEM_STATUS + " " + StatusCode.OK.name())); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { String timerName = entry.getKey(); long percentileMillis = TimeUnit.NANOSECONDS.toMillis((long)entry.getValue().getSnapshot().get95thPercentile()); logStatusMessage(createTimerStatusMessage(SYSTEM_STATUS + " " + timerName, percentileMillis)); } consumers.parallelStream().forEach(consumer -> consumer.accept(messages)); } }
SystemStatusRunnable implements SystemStatus { @Override public void run() { final List<StatusMessage> messages = new ArrayList<>(); for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { String meterName = entry.getKey(); double meterValue = entry.getValue().getCount(); registry.remove(meterName); Optional<StatusMessage> errMessage = checkRateOfMeter(meterName, StatusCode.CRIT, meterValue); Optional<StatusMessage> warnMessage = checkRateOfMeter(meterName, StatusCode.WARN, meterValue); if (errMessage.isPresent()) { messages.add(errMessage.get()); } else if (warnMessage.isPresent()) { messages.add(warnMessage.get()); } } if (messages.isEmpty()) { messages.add(new StatusMessage(StatusCode.OK, SYSTEM_STATUS + " " + StatusCode.OK.name())); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { String timerName = entry.getKey(); long percentileMillis = TimeUnit.NANOSECONDS.toMillis((long)entry.getValue().getSnapshot().get95thPercentile()); logStatusMessage(createTimerStatusMessage(SYSTEM_STATUS + " " + timerName, percentileMillis)); } consumers.parallelStream().forEach(consumer -> consumer.accept(messages)); } @Inject  SystemStatusRunnable(AppConfig appConfig); }
SystemStatusRunnable implements SystemStatus { @Override public void run() { final List<StatusMessage> messages = new ArrayList<>(); for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { String meterName = entry.getKey(); double meterValue = entry.getValue().getCount(); registry.remove(meterName); Optional<StatusMessage> errMessage = checkRateOfMeter(meterName, StatusCode.CRIT, meterValue); Optional<StatusMessage> warnMessage = checkRateOfMeter(meterName, StatusCode.WARN, meterValue); if (errMessage.isPresent()) { messages.add(errMessage.get()); } else if (warnMessage.isPresent()) { messages.add(warnMessage.get()); } } if (messages.isEmpty()) { messages.add(new StatusMessage(StatusCode.OK, SYSTEM_STATUS + " " + StatusCode.OK.name())); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { String timerName = entry.getKey(); long percentileMillis = TimeUnit.NANOSECONDS.toMillis((long)entry.getValue().getSnapshot().get95thPercentile()); logStatusMessage(createTimerStatusMessage(SYSTEM_STATUS + " " + timerName, percentileMillis)); } consumers.parallelStream().forEach(consumer -> consumer.accept(messages)); } @Inject  SystemStatusRunnable(AppConfig appConfig); @Override Meter meter(String name, MeterType type); @Override Timer timer(String name, String method); @Inject void register(Set<SystemStatusConsumer> statusConsumers); @Override void run(); }
SystemStatusRunnable implements SystemStatus { @Override public void run() { final List<StatusMessage> messages = new ArrayList<>(); for (Map.Entry<String, Meter> entry : registry.getMeters().entrySet()) { String meterName = entry.getKey(); double meterValue = entry.getValue().getCount(); registry.remove(meterName); Optional<StatusMessage> errMessage = checkRateOfMeter(meterName, StatusCode.CRIT, meterValue); Optional<StatusMessage> warnMessage = checkRateOfMeter(meterName, StatusCode.WARN, meterValue); if (errMessage.isPresent()) { messages.add(errMessage.get()); } else if (warnMessage.isPresent()) { messages.add(warnMessage.get()); } } if (messages.isEmpty()) { messages.add(new StatusMessage(StatusCode.OK, SYSTEM_STATUS + " " + StatusCode.OK.name())); } for (Map.Entry<String, Timer> entry : registry.getTimers().entrySet()) { String timerName = entry.getKey(); long percentileMillis = TimeUnit.NANOSECONDS.toMillis((long)entry.getValue().getSnapshot().get95thPercentile()); logStatusMessage(createTimerStatusMessage(SYSTEM_STATUS + " " + timerName, percentileMillis)); } consumers.parallelStream().forEach(consumer -> consumer.accept(messages)); } @Inject  SystemStatusRunnable(AppConfig appConfig); @Override Meter meter(String name, MeterType type); @Override Timer timer(String name, String method); @Inject void register(Set<SystemStatusConsumer> statusConsumers); @Override void run();  }