Skip to content

Commit

Permalink
Filter out all non-interesting tags, where the values do not vary acr…
Browse files Browse the repository at this point in the history
…oss responses (#79)
  • Loading branch information
Michael Graff committed Sep 7, 2017
1 parent c6d2074 commit 007648e
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Builder
@Slf4j
Expand Down Expand Up @@ -80,6 +81,15 @@ public List<MetricSet> queryMetrics(String accountName,
Map<String, AtlasResults> idToAtlasResultsMap = AtlasResultsHelper.merge(atlasResultsList);
List<MetricSet> metricSetList = new ArrayList<>();

// Gather a list of tags which have multiple values across all results.
// This is the set of keys we wish to keep.
List<String> interestingKeys = idToAtlasResultsMap.values()
.stream()
.flatMap(result -> result.getTags().entrySet().stream())
.collect(Collectors.groupingBy(Map.Entry::getKey))
.entrySet().stream().filter(stringListEntry -> stringListEntry.getValue().size() > 1)
.map(Map.Entry::getKey).collect(Collectors.toList());

for (AtlasResults atlasResults : idToAtlasResultsMap.values()) {
Instant responseStartTimeInstant = Instant.ofEpochMilli(atlasResults.getStart());
List<Double> timeSeriesList = atlasResults.getData().getValues();
Expand All @@ -99,7 +109,10 @@ public List<MetricSet> queryMetrics(String accountName,
Map<String, String> tags = atlasResults.getTags();

if (tags != null) {
metricSetBuilder.tags(tags);
Map<String, String> filteredTags = tags.entrySet().stream()
.filter(entry -> interestingKeys.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
metricSetBuilder.tags(filteredTags);
}

metricSetList.add(metricSetBuilder.build());
Expand Down

0 comments on commit 007648e

Please sign in to comment.