Skip to content

Commit

Permalink
fix(stackdriver): Use metric labels (#695)
Browse files Browse the repository at this point in the history
* fix(stackdriver): Use metric labels

Adding the metric labels as tags enables comparison of
individual time series when using "Group By"; it currently
only compares the last time series.

* Fix variable name

Co-authored-by: Justin Field <justin.field@armory.io>
  • Loading branch information
Aurelio Agundez and fieldju committed Apr 29, 2020
1 parent e8737fa commit 9247912
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,31 @@ public List<MetricSet> queryMetrics(
.stepMillis(alignmentPeriodSec * 1000)
.values(pointValues);

// TODO(duftler): Still not quite sure whether this is right or if we should use
// timeSeries.getMetric().getLabels() instead.
MonitoredResource monitoredResource = timeSeries.getResource();
Map<String, String> filteredLabels = new HashMap<>();

MonitoredResource monitoredResource = timeSeries.getResource();
if (monitoredResource != null) {
Map<String, String> labels = monitoredResource.getLabels();

if (labels != null) {
Map<String, String> prunedLabels = new HashMap<>(labels);
prunedLabels.remove("project_id");
metricSetBuilder.tags(prunedLabels);
filteredLabels.putAll(
labels.entrySet().stream()
.filter(entry -> entry.getKey() != "project_id")
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
}
}

Metric metric = timeSeries.getMetric();
if (metric != null) {
Map<String, String> labels = metric.getLabels();

if (labels != null) {
filteredLabels.putAll(labels);
}
}

metricSetBuilder.tags(filteredLabels);

metricSetBuilder.attribute("query", filter);
metricSetBuilder.attribute("crossSeriesReducer", crossSeriesReducer);
metricSetBuilder.attribute("perSeriesAligner", perSeriesAligner);
Expand Down

0 comments on commit 9247912

Please sign in to comment.