Skip to content

Commit

Permalink
"backporting" graphite-project#170 into 0.9.x
Browse files Browse the repository at this point in the history
(cherry picked from commit 5b1015d)
  • Loading branch information
Yoav authored and fessyfoo committed Nov 26, 2014
1 parent b787e05 commit 141b97e
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions webapp/graphite/render/views.py
Expand Up @@ -12,6 +12,7 @@
See the License for the specific language governing permissions and
limitations under the License."""
import csv
import math
from datetime import datetime
from time import time
from random import shuffle
Expand Down Expand Up @@ -128,10 +129,34 @@ def renderView(request):

if format == 'json':
series_data = []
for series in data:
timestamps = range(series.start, series.end, series.step)
datapoints = zip(series, timestamps)
series_data.append( dict(target=series.name, datapoints=datapoints) )
if 'maxDataPoints' in requestOptions and any(data):
startTime = min([series.start for series in data])
endTime = max([series.end for series in data])
timeRange = endTime - startTime
maxDataPoints = requestOptions['maxDataPoints']
for series in data:
numberOfDataPoints = timeRange/series.step
if maxDataPoints < numberOfDataPoints:
valuesPerPoint = math.ceil(float(numberOfDataPoints) / float(maxDataPoints))
secondsPerPoint = int(valuesPerPoint * series.step)
# Nudge start over a little bit so that the consolidation bands align with each call
# removing 'jitter' seen when refreshing.
nudge = secondsPerPoint + (series.start % series.step) - (series.start % secondsPerPoint)
series.start = series.start + nudge
valuesToLose = int(nudge/series.step)
for r in range(1, valuesToLose):
del series[0]
series.consolidate(valuesPerPoint)
timestamps = range(series.start, series.end, secondsPerPoint)
else:
timestamps = range(series.start, series.end, series.step)
datapoints = zip(series, timestamps)
series_data.append(dict(target=series.name, datapoints=datapoints))
else:
for series in data:
timestamps = range(series.start, series.end, series.step)
datapoints = zip(series, timestamps)
series_data.append( dict(target=series.name, datapoints=datapoints) )

if 'jsonp' in requestOptions:
response = HttpResponse(
Expand Down Expand Up @@ -230,6 +255,8 @@ def parseOptions(request):
requestOptions['jsonp'] = queryParams['jsonp']
if 'noCache' in queryParams:
requestOptions['noCache'] = True
if 'maxDataPoints' in queryParams and queryParams['maxDataPoints'].isdigit():
requestOptions['maxDataPoints'] = int(queryParams['maxDataPoints'])

requestOptions['localOnly'] = queryParams.get('local') == '1'

Expand Down

0 comments on commit 141b97e

Please sign in to comment.