public LiteralNameResolver(Path name) { this(name.getPath()); }
@Override public StringBuilder configString() { return group_name_.configString(); }
public default StringBuilder configString() { return new StringBuilder(getPathString()); }
@Override public Path apply(Path path) { final List<String> elems = path.getPath(); try { final List<String> result = Arrays.asList(elems.get(idx_to_abs_(idx_, elems))); return () -> result; } catch (IndexOutOfBoundsException ex) { return () -> Collections.EMPTY_LIST; } }
public default StringBuilder configString() { return new StringBuilder(getPathString()); }
@Override public Path apply(Path path) { final List<String> elems = path.getPath(); try { final List<String> result = elems.subList(idx_to_abs_(b_, elems).orElse(0), idx_to_abs_(e_, elems).orElseGet(elems::size)); return () -> result; } catch (IndexOutOfBoundsException ex) { return () -> Collections.EMPTY_LIST; } }
@Override public List<PathMatcher.IdentifierMatch> asLiteral() { return group_name_.getPath().stream() .map(PathMatcher.LiteralNameMatch::new) .collect(Collectors.toList()); }
public default String getPathString() { return String.join(".", getPath().stream() .map(ConfigSupport::maybeQuoteIdentifier) .map(StringBuilder::toString) .collect(Collectors.toList())); } }
public default String getPathString() { return String.join(".", getPath().stream() .map(ConfigSupport::maybeQuoteIdentifier) .map(StringBuilder::toString) .collect(Collectors.toList())); } }
private static MetricValue pathAsMetricValue(Path path) { final List<String> pathElems = path.getPath(); if (pathElems.size() == 1) return strAsMetricValue(pathElems.get(0)); return MetricValue.fromStrValue(String.join(".", pathElems)); }
@Override public Optional<Path> apply(Context<?> ctx) { return ctx.getAliasFromIdentifier(Path.class, identifier_) .map(path -> sub_select_.map(s -> s.apply(path)).orElseGet(() -> SimpleGroupPath.valueOf(path.getPath()))); }
@Override public TimeSeriesMetricDeltaSet apply(Context ctx) { return metric_.apply(ctx) .map(p -> MetricName.valueOf(p.getPath())) .map(group_.getTSDelta(ctx)::findMetric) .orElseGet(TimeSeriesMetricDeltaSet::new); }
private TimeSeriesCollection transform_(Context<MutableTimeSeriesCollectionPair> ctx) { final MutableTimeSeriesCollection ts_data = ctx.getTSData().getCurrentCollection(); final Map<MetricName, MetricValue> metrics = metrics_.entrySet().stream() .map(name_value -> { return name_value.getKey().apply(ctx).map(name -> SimpleMapEntry.create(name, name_value.getValue())); }) .flatMap(opt -> opt.map(Stream::of).orElseGet(Stream::empty)) .map(path_value -> SimpleMapEntry.create(MetricName.valueOf(path_value.getKey().getPath()), path_value.getValue())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); group_.getTSDelta(ctx).stream() .map(TimeSeriesValue::getGroup) .forEach((grp) -> ts_data.addMetrics(grp, metrics)); return ts_data; }
@Override public TimeSeriesValueSet getTSDelta(Context ctx) { return name_.apply(ctx) .map(path -> SimpleGroupPath.valueOf(path.getPath())) .map(name -> ctx.getTSData().getTSValue(name)) .orElse(TimeSeriesValueSet.EMPTY); }
@Override public void transform(Context ctx) { final SimpleGroupPath group_name = getGroup().apply(ctx) .map(path -> SimpleGroupPath.valueOf(path.getPath())) .orElseThrow(() -> new IllegalArgumentException("unable to resolve group name")); final TagData tagData = new TagData(ctx, tags); resolveMapping(ctx, mapping, name -> resolveMetricName(ctx, name)) .forEach(metric_expr -> { final MetricName metric = metric_expr.getKey(); metric_expr.getValue().streamAsMap() .forEach((Map.Entry<Tags, MetricValue> resolvedMetric) -> addMetricMappingToCtx(ctx, group_name, metric, tagData, resolvedMetric)); }); }
@Override public void transform(Context ctx) { final MutableContext m_ctx = (MutableContext)ctx; final TimeSeriesCollectionPair ts_data = ctx.getTSData(); m_ctx.putGroupAlias(identifier_, group_.apply(ctx).map(path -> SimpleGroupPath.valueOf(path.getPath()))); }
public Stream<Alert> create_alert_(Context ctx) { final TimeSeriesCollectionPair ts_data = ctx.getTSData(); final Map<String, Any2<TimeSeriesMetricDeltaSet, List<TimeSeriesMetricDeltaSet>>> attr_map = calculate_attributes_(ctx); return alert_defn_.getName().apply(ctx) .map(path -> SimpleGroupPath.valueOf(path.getPath())) .map((name) -> { return alert_defn_.getPredicate().apply(ctx) .streamAsMap() .map((tag_val) -> SimpleMapEntry.create(tag_val.getKey(), tag_val.getValue().asBool())) .map((tag_bool) -> { final GroupName alert_name = GroupName.valueOf(name, tag_bool.getKey()); final Optional<Boolean> triggering = tag_bool.getValue(); Map<String, Any2<MetricValue, List<MetricValue>>> attrs = lookup_attributes_(alert_name.getTags(), attr_map); return new Alert(ts_data.getCurrentCollection().getTimestamp(), alert_name, alert_defn_::configString, triggering, alert_defn_.getFireDuration(), alert_defn_.getMessage(), attrs); }); }) .orElseGet(Stream::empty); }