private static double getValue(Service service, String fieldName) { ServiceStat serviceStat = service.getStat(fieldName); if (serviceStat == null) { return 0; } return serviceStat.latestValue; } }
private static ServiceStat getOrCreateStat(Service service, String name, boolean createHistogram, Supplier<TimeSeriesStats> timeSeriesStatsSupplier) { if (!service.hasOption(ServiceOption.INSTRUMENTATION)) { return null; } ServiceStat stat = service.getStat(name); synchronized (stat) { if (stat.logHistogram == null && createHistogram) { stat.logHistogram = new ServiceStatLogHistogram(); } if (stat.timeSeriesStats == null && timeSeriesStatsSupplier != null) { stat.timeSeriesStats = timeSeriesStatsSupplier.get(); } } return stat; } }
private static void doHandlePeriodicMaintenanceImpl(Service s, Operation post) { ServiceMaintenanceRequest request = post.getBody(ServiceMaintenanceRequest.class); if (!request.reasons.contains( ServiceMaintenanceRequest.MaintenanceReason.PERIODIC_SCHEDULE)) { post.fail(new IllegalArgumentException("expected PERIODIC_SCHEDULE reason")); return; } post.complete(); ServiceStat stat = s.getStat(STAT_NAME_HANDLE_PERIODIC_MAINTENANCE); s.adjustStat(stat, 1); if (stat.latestValue >= PERIODIC_MAINTENANCE_MAX) { s.toggleOption(ServiceOption.PERIODIC_MAINTENANCE, false); } }
private static void doHandlePeriodicMaintenanceImpl(Service s, Operation post) { ServiceMaintenanceRequest request = post.getBody(ServiceMaintenanceRequest.class); if (!request.reasons.contains( ServiceMaintenanceRequest.MaintenanceReason.PERIODIC_SCHEDULE)) { post.fail(new IllegalArgumentException("expected PERIODIC_SCHEDULE reason")); return; } post.complete(); ServiceStat stat = s.getStat(STAT_NAME_HANDLE_PERIODIC_MAINTENANCE); s.adjustStat(stat, 1); if (stat.latestValue >= PERIODIC_MAINTENANCE_MAX) { s.toggleOption(ServiceOption.PERIODIC_MAINTENANCE, false); } }
private void doCheckPeriodicMaintenance(Service s) throws Throwable { // Start service Service service = this.host.startServiceAndWait(s, UUID.randomUUID().toString(), null); int expectedMaintCount = PERIODIC_MAINTENANCE_MAX; if (!s.hasOption(ServiceOption.PERIODIC_MAINTENANCE)) { this.host.log("Toggling %s on", ServiceOption.PERIODIC_MAINTENANCE); this.host.toggleServiceOptions(s.getUri(), EnumSet.of(ServiceOption.PERIODIC_MAINTENANCE), null); expectedMaintCount = 1; } this.host.log("waiting for maintenance stat increment, expecting %d repeats", expectedMaintCount); final int limit = expectedMaintCount; this.host.waitFor("maint. count incorrect", () -> { ServiceStat stat = service.getStat(STAT_NAME_HANDLE_PERIODIC_MAINTENANCE); if (stat.latestValue < limit) { return false; } return true; }); }
private void doCheckPeriodicMaintenance(Service s) throws Throwable { // Start service Service service = this.host.startServiceAndWait(s, UUID.randomUUID().toString(), null); int expectedMaintCount = PERIODIC_MAINTENANCE_MAX; if (!s.hasOption(ServiceOption.PERIODIC_MAINTENANCE)) { this.host.log("Toggling %s on", ServiceOption.PERIODIC_MAINTENANCE); this.host.toggleServiceOptions(s.getUri(), EnumSet.of(ServiceOption.PERIODIC_MAINTENANCE), null); expectedMaintCount = 1; } this.host.log("waiting for maintenance stat increment, expecting %d repeats", expectedMaintCount); final int limit = expectedMaintCount; this.host.waitFor("maint. count incorrect", () -> { ServiceStat stat = service.getStat(STAT_NAME_HANDLE_PERIODIC_MAINTENANCE); if (stat.latestValue < limit) { return false; } return true; }); }
private void verifyStatCreationAttemptAfterGet() throws Throwable { // Create a stat without a log histogram or time series, then try to recreate with // the extra features and make sure its updated List<Service> services = this.host.doThroughputServiceStart( 1, MinimalTestService.class, this.host.buildMinimalTestState(), EnumSet.of(ServiceOption.INSTRUMENTATION), null); final String statName = "foo"; for (Service service : services) { service.setStat(statName, 1.0); ServiceStat st = service.getStat(statName); assertTrue(st.timeSeriesStats == null); assertTrue(st.logHistogram == null); ServiceStat stNew = new ServiceStat(); stNew.name = statName; stNew.logHistogram = new ServiceStatLogHistogram(); stNew.timeSeriesStats = new TimeSeriesStats(60, TimeUnit.MINUTES.toMillis(1), EnumSet.of(AggregationType.AVG)); service.setStat(stNew, 11.0); st = service.getStat(statName); assertTrue(st.timeSeriesStats != null); assertTrue(st.logHistogram != null); } }
private void verifyStatCreationAttemptAfterGet() throws Throwable { // Create a stat without a log histogram or time series, then try to recreate with // the extra features and make sure its updated List<Service> services = this.host.doThroughputServiceStart( 1, MinimalTestService.class, this.host.buildMinimalTestState(), EnumSet.of(ServiceOption.INSTRUMENTATION), null); final String statName = "foo"; for (Service service : services) { service.setStat(statName, 1.0); ServiceStat st = service.getStat(statName); assertTrue(st.timeSeriesStats == null); assertTrue(st.logHistogram == null); ServiceStat stNew = new ServiceStat(); stNew.name = statName; stNew.logHistogram = new ServiceStatLogHistogram(); stNew.timeSeriesStats = new TimeSeriesStats(60, TimeUnit.MINUTES.toMillis(1), EnumSet.of(AggregationType.AVG)); service.setStat(stNew, 11.0); st = service.getStat(statName); assertTrue(st.timeSeriesStats != null); assertTrue(st.logHistogram != null); } }
s.toggleOption(ServiceOption.INSTRUMENTATION, true); s.adjustStat(Service.STAT_NAME_NODE_GROUP_SYNCH_DELAYED_COUNT, 1); ServiceStat st = s.getStat(Service.STAT_NAME_NODE_GROUP_SYNCH_DELAYED_COUNT); if (st != null && st.latestValue % 10 == 0) { shouldLog = true;