Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing "sequence contains no elements" when querying storage #2015

Closed
wants to merge 1 commit into from
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
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
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