Source:
private void reload(final InputStream stream) { LOGGER.debug().setMessage("Received update, reloading alerts").log(); final BufferedInputStream bufferedStream = new BufferedInputStream( stream, BUFFER_SIZE ); final AlertGroup group; try { group = _objectMapper.readValue(bufferedStream, AlertGroup.class); } catch (final IOException e) { LOGGER.error() .setMessage("Could not load alert definitions") .setThrowable(e) .log(); return; } final ImmutableMap.Builder<UUID, Alert> mapBuilder = ImmutableMap.builder(); for (final SerializedAlert fsAlert : group.getAlerts()) { final StringArgGenerator uuidGen = Generators.nameBasedGenerator(_organization.getId()); final UUID uuid = fsAlert.getUUID().orElseGet(() -> computeUUID(uuidGen, fsAlert)); final MetricsQuery query; if (group.getVersion() == LATEST_SERIALIZATION_VERSION) { query = new DefaultMetricsQuery.Builder() .setQuery(fsAlert.getQuery()) .setFormat(MetricsQueryFormat.KAIROS_DB) .build(); } else { throw new IllegalArgumentException(String.format("Unhandled alert version %d", group.getVersion())); } final Alert alert = new DefaultAlert.Builder() .setId(uuid) .setName(fsAlert.getName()) .setDescription(fsAlert.getDescription()) .setEnabled(fsAlert.isEnabled()) .setOrganization(_organization) .setQuery(query) .setAdditionalMetadata(fsAlert.getAdditionalMetadata()) .build(); mapBuilder.put(uuid, alert); } _alerts = mapBuilder.build(); LOGGER.debug().setMessage("Alerts successfully reloaded") .addData("alertCount", _alerts.size()) .log(); }

Target:
private void reload(final InputStream stream) { LOGGER.debug().setMessage("Received update, reloading alerts").log(); final BufferedInputStream bufferedStream = new BufferedInputStream( stream, BUFFER_SIZE ); final AlertGroup group; try { group = _objectMapper.readValue(bufferedStream, AlertGroup.class); } catch (final IOException e) { LOGGER.error() .setMessage("Could not load alert definitions") .setThrowable(e) .log(); _periodicMetrics.recordCounter(RELOAD_SUCCESS_COUNTER, 0); return; } final ImmutableMap.Builder<UUID, Alert> mapBuilder = ImmutableMap.builder(); for (final SerializedAlert fsAlert : group.getAlerts()) { final StringArgGenerator uuidGen = Generators.nameBasedGenerator(_organization.getId()); final UUID uuid = fsAlert.getUUID().orElseGet(() -> computeUUID(uuidGen, fsAlert)); if (group.getVersion() != LATEST_SERIALIZATION_VERSION) { final Throwable e = new IllegalArgumentException(String.format("Unhandled alert version %d", group.getVersion())); LOGGER.error() .setMessage("Could not load alert definitions") .setThrowable(e) .log(); _periodicMetrics.recordCounter(RELOAD_SUCCESS_COUNTER, 0); return; } final MetricsQuery query = new DefaultMetricsQuery.Builder() .setQuery(fsAlert.getQuery()) .setFormat(MetricsQueryFormat.KAIROS_DB) .build(); final Alert alert = new DefaultAlert.Builder() .setId(uuid) .setName(fsAlert.getName()) .setDescription(fsAlert.getDescription()) .setEnabled(fsAlert.isEnabled()) .setOrganization(_organization) .setQuery(query) .setAdditionalMetadata(fsAlert.getAdditionalMetadata()) .build(); mapBuilder.put(uuid, alert); } _alerts = mapBuilder.build(); _periodicMetrics.recordCounter(RELOAD_SUCCESS_COUNTER, 1); _periodicMetrics.recordGauge(RELOAD_GAUGE, _alerts.size()); LOGGER.debug().setMessage("Alerts successfully reloaded") .addData("alertCount", _alerts.size()) .log(); }