private static GroupName calculate_new_name_(GroupName oldname, Map<String, MetricValue> tagged_values) { return GroupName.valueOf(oldname.getPath(), Stream.concat( oldname.getTags().stream().filter((Map.Entry<String, MetricValue> entry) -> !tagged_values.keySet().contains(entry.getKey())), tagged_values.entrySet().stream())); }
@Override public String toString() { return configString().toString(); }
public StringBuilder configString() { final StringBuilder result = new StringBuilder(getPathString()); String tag_string = tags_.getTagString(); if (!tag_string.isEmpty()) result.append('{').append(tag_string).append('}'); return result; }
private Optional<MutableTimeSeriesValue> remove_(GroupName name) { final SimpleGroupPath path = name.getPath(); final Optional<MutableTimeSeriesValue> removed = Optional.ofNullable(data_.remove(name)); removed.ifPresent(r -> { Set<MutableTimeSeriesValue> set = data_by_path_.get(path); final boolean is_removed = set.remove(r); assert (is_removed); if (set.isEmpty()) data_by_path_.remove(path); }); return removed; }
public static GroupName valueOf(SimpleGroupPath path) { return valueOf(path, emptyMap()); }
@Override public default Tags getTags() { return getGroup().getTags(); }
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); }
.map(old_name -> { Map<String, MetricValue> new_tags = new HashMap<>(); vectors.getOrDefault(old_name.getTags(), Collections.<Map.Entry<String, MetricValue>>emptyList()) .forEach(entry -> new_tags.put(entry.getKey(), entry.getValue())); scalars return SimpleMapEntry.create(old_name, calculate_new_name_(old_name, new_tags)); }) .filter(entry -> !entry.getKey().equals(entry.getValue())) // Filter out noop renames. .collect(Collectors.toList());
@Override public default int compareTo(TimeSeriesValue other) { return getGroup().compareTo(other.getGroup()); } }
@Override public Set<SimpleGroupPath> getGroupPaths(Predicate<? super SimpleGroupPath> filter) { return tsvSet.entrySet().stream() .filter(entry -> filter.test(entry.getKey().getPath())) .collect(Collectors.groupingBy(entry -> entry.getKey().getPath())).entrySet().stream() .filter(listing -> listing.getValue().stream().map(Map.Entry::getValue).anyMatch(Optional::isPresent)) .map(Map.Entry::getKey) .collect(Collectors.toSet()); }
public static GroupName valueOf(SimpleGroupPath path) { return valueOf(path, emptyMap()); }
public Tags getTags() { return getGroup().getTags(); } }
@Override public default int compareTo(TimeSeriesValue other) { return getGroup().compareTo(other.getGroup()); } }
@Override public TimeSeriesValueSet get(Predicate<? super SimpleGroupPath> pathFilter, Predicate<? super GroupName> groupFilter) { return new TimeSeriesValueSet(groupMap.entrySet().stream() .filter(entry -> pathFilter.test(entry.getKey().getPath())) .filter(entry -> groupFilter.test(entry.getKey())) .map(Map.Entry::getValue)); } }
public static GroupName valueOf(String... path) { return valueOf(SimpleGroupPath.valueOf(path)); }
@Override public default Tags getTags() { return getGroup().getTags(); }
@Override public String toString() { return configString().toString(); }
public StringBuilder configString() { final StringBuilder result = new StringBuilder(getPathString()); String tag_string = tags_.getTagString(); if (!tag_string.isEmpty()) result.append('{').append(tag_string).append('}'); return result; }