Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,24 @@ public async Task<MetricListResponse> GetMetricsAsync(string resourceId, string
{
MetricFilter filter = MetricFilterExpressionParser.Parse(filterString);

// Filter definitions by timegrain
var timegraindefinitions = from d in definitions
where d.MetricAvailabilities.Count > 0
&& d.MetricAvailabilities[0].TimeGrain == filter.TimeGrain
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work for metrics with multiple allowed timegrains, for which the query specifies one other than the first. It needs to be able to select the appropriate availability based on the requested timegrain.

select d;

// Group definitions by location so we can make one request to each location
Dictionary<MetricAvailability, MetricFilter> groups =
definitions.GroupBy(d => d.MetricAvailabilities.First(a => a.TimeGrain == filter.TimeGrain),
new SasMetricRetriever.AvailabilityComparer()).ToDictionary(g => g.Key, g => new MetricFilter()
{
TimeGrain = filter.TimeGrain,
StartTime = filter.StartTime,
EndTime = filter.EndTime,
DimensionFilters = g.Select(d =>
filter.DimensionFilters.FirstOrDefault(df => string.Equals(df.Name, d.Name.Value, StringComparison.OrdinalIgnoreCase))
?? new MetricDimension() {Name = d.Name.Value})
});
timegraindefinitions.GroupBy(d => d.MetricAvailabilities[0]).ToDictionary(g => g.Key, g => new MetricFilter()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe, this call to GroupBy should include the EqualityComaparer for the Availability objects (SasMetricRetriever.AvailabilityComparer).

{
TimeGrain = filter.TimeGrain,
StartTime = filter.StartTime,
EndTime = filter.EndTime,
DimensionFilters = g.Select(d =>
filter.DimensionFilters.FirstOrDefault(df => string.Equals(df.Name, d.Name.Value, StringComparison.OrdinalIgnoreCase))
?? new MetricDimension() {Name = d.Name.Value})
});


// Verify all groups represent shoebox metrics
if (groups.Any(g => g.Key.Location == null))
Expand Down