From d3d3097e22ef820b310227e6ab935b31df7c23dc Mon Sep 17 00:00:00 2001 From: ipatini Date: Wed, 17 Jan 2024 13:40:22 +0200 Subject: [PATCH] EMS Nebulous plugin changed to produce prediction events according to SLO Violation Detector Event Type III format Change-Id: I2578b37a73c42090370df21cd3700d0ae5d2bfe9 --- .../PredictionsPostTranslationPlugin.java | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/plugins/PredictionsPostTranslationPlugin.java b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/plugins/PredictionsPostTranslationPlugin.java index a981510..d46771d 100644 --- a/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/plugins/PredictionsPostTranslationPlugin.java +++ b/nebulous/ems-nebulous/src/main/java/eu/nebulous/ems/plugins/PredictionsPostTranslationPlugin.java @@ -182,7 +182,7 @@ public class PredictionsPostTranslationPlugin implements PostTranslationPlugin { } // Convert to Translator-to-Forecasting Methods event format - final long currVersion = topicBeacon.getModelVersion(); + /*final long currVersion = topicBeacon.getModelVersion(); final TopicBeaconProperties properties = topicBeacon.getProperties(); final ValueRange allowedPredictionRateRange = ValueRange.of(properties.getPredictionMinAllowedRate(), properties.getPredictionMaxAllowedRate()); @@ -198,12 +198,47 @@ public class PredictionsPostTranslationPlugin implements PostTranslationPlugin { : properties.getPredictionRate()); return map; }).collect(Collectors.toList()); - log.debug("Topic Beacon: Transmitting Prediction info: Metric Contexts in event format: {}", payload); + log.debug("PredictionsPostTranslationPlugin: Metric Contexts in event format: {}", payload); // Skip event sending if payload is empty if (payload.isEmpty()) { return null; - } + }*/ + + // Convert to SLO Severity-based Violation Detector Event Type III format + // See: https://158.39.75.54/projects/nebulous-collaboration-hub/wiki/slo-severity-based-violation-detector + HashMap payload = new HashMap<>(); + payload.put("name", "_" + _TC.getModelName()); + payload.put("version", topicBeacon.getModelVersion()); + payload.put("metric_list", + metricsOfTopLevelNodes.stream().map(mc -> { + HashMap map = new HashMap<>(); + map.put("name", NebulousEmsTranslator.nameNormalization.apply( mc.getName() )); + MetricTemplate template = mc.getMetric().getMetricTemplate(); + if (template!=null) { + switch (template.getValueType()) { + case FLOAT_TYPE, DOUBLE_TYPE, FloatType, DoubleType -> { + map.put("upper_bound", Double.toString(template.getUpperBound())); + map.put("lower_bound", Double.toString(template.getLowerBound())); + } + case INT_TYPE, IntType -> { + map.put("upper_bound", Integer.toString((int)template.getUpperBound())); + map.put("lower_bound", Integer.toString((int)template.getLowerBound())); + } + default -> { + log.warn("PredictionsPostTranslationPlugin: Metric Template type not supported. Will be ignored: type={}, metric={}", + template.getValueType(), mc.getMetric()); + return null; + } + } + } else { + map.put("upper_bound", Double.toString(Double.POSITIVE_INFINITY)); + map.put("lower_bound", Double.toString(Double.NEGATIVE_INFINITY)); + } + return map; + }) + .filter(Objects::nonNull) + .toList() ); // Serialize payload return topicBeacon.toJson(payload);