Skip to content

Commit

Permalink
return empty series if empty series given
Browse files Browse the repository at this point in the history
don't try to compute overlap if empty
  • Loading branch information
chungg authored and pastamaker[bot] committed Oct 27, 2017
1 parent d4eed32 commit 1cefef0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
29 changes: 15 additions & 14 deletions gnocchi/rest/aggregates/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,21 @@ def aggregated(refs_and_timeseries, operations, from_timestamp=None,
if overlap.size == 0 and needed_percent_of_overlap > 0:
raise exceptions.UnAggregableTimeseries(references[key],
'No overlap')
# if no boundary set, use first/last timestamp which overlap
if to_timestamp is None and overlap.size:
times = times[:overlap[-1] + 1]
values = values[:overlap[-1] + 1]
if from_timestamp is None and overlap.size:
times = times[overlap[0]:]
values = values[overlap[0]:]
percent_of_overlap = overlap.size * 100.0 / times.size
if percent_of_overlap < needed_percent_of_overlap:
raise exceptions.UnAggregableTimeseries(
references[key],
'Less than %f%% of datapoints overlap in this '
'timespan (%.2f%%)' % (needed_percent_of_overlap,
percent_of_overlap))
if times.size:
# if no boundary set, use first/last timestamp which overlap
if to_timestamp is None and overlap.size:
times = times[:overlap[-1] + 1]
values = values[:overlap[-1] + 1]
if from_timestamp is None and overlap.size:
times = times[overlap[0]:]
values = values[overlap[0]:]
percent_of_overlap = overlap.size * 100.0 / times.size
if percent_of_overlap < needed_percent_of_overlap:
raise exceptions.UnAggregableTimeseries(
references[key],
'Less than %f%% of datapoints overlap in this '
'timespan (%.2f%%)' % (needed_percent_of_overlap,
percent_of_overlap))

granularity, times, values, is_aggregated = (
agg_operations.evaluate(operations, key, times, values,
Expand Down
7 changes: 7 additions & 0 deletions gnocchi/tests/test_aggregates.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,13 @@ def test_get_measures_empty_metrics_no_overlap(self):
"metric", ["whatever", "mean"], ["everwhat", "mean"],
]])

def test_get_measures_empty_metric_needed_overlap_zero(self):
m_id = str(self.metric.id)
result = processor.get_measures(
self.storage, [(self.metric, "mean")],
operations=["metric", m_id, "mean"], needed_overlap=0)
self.assertEqual({'%s_mean' % m_id: []}, result)

def test_get_measures_unknown_aggregation(self):
metric2 = indexer.Metric(uuid.uuid4(),
self.archive_policies['low'])
Expand Down

0 comments on commit 1cefef0

Please sign in to comment.