Permalink
Browse files

Merge pull request #12 from slackhappy/new_hypertable_api

hypertable: fix new algo (partly)
  • Loading branch information...
2 parents fad3282 + aa37a19 commit 33d3d46bc93516cb1d6803e46902cbe7695c9939 @slackhappy slackhappy committed Jun 5, 2012
Showing with 11 additions and 11 deletions.
  1. +11 −11 webapp/graphite/render/datalib.py
@@ -221,7 +221,7 @@ def fetchDataFromHyperTable(requestContext, pathExpr):
#TODO: use django settings
MIN_INTERVAL_SECS = 10
COL_INTERVAL_SECS = 60 * 60
- POSSIBLE_INTERVALS = [ 1, 10, 15, 30, 60, 120 ]
+ POSSIBLE_INTERVALS = [ 1, 10, 15, 30, 60 ]
log.info('fetching %s' % pathExpr)
@@ -269,8 +269,6 @@ def processResult(key, family, column, val, ts):
HyperTablePool.doScan(scan_spec, "metrics", processResult)
elapsed = end - start
- lowestMetricStep = elapsed # was: elapsed but for small
- # intervals it isn't great
stepsSeen = {}
# post-fetch processing
@@ -283,26 +281,28 @@ def processResult(key, family, column, val, ts):
sortedVals[m] = sorted(valuesMap[m], key=lambda x: x[0])
for i in range(1, len(sortedVals[m])):
step = sortedVals[m][i][0] - sortedVals[m][i-1][0]
- closestDist = 2 * POSSIBLE_INTERVALS[-1]
- closestDistAt = POSSIBLE_INTERVALS[-1]
+ closestDist = 1.5 * POSSIBLE_INTERVALS[-1]
+ closestDistAt = -1
#TODO this is slow
for interval in POSSIBLE_INTERVALS:
dist = abs(step - interval)
if dist < closestDist:
closestDist = dist
closestDistAt = interval
- stepsSeen[closestDistAt] += 1
- if step and step < minStep and elapsed % step == 0:
- minStep = step
- if lowestMetricStep == None or lowestMetricStep > minStep:
- lowestMetricStep = minStep
+ # don't let gappy data vote
+ if closestDistAt != -1:
+ stepsSeen[closestDistAt] += 1
mostCommonStep = -1
mostCommonCount = 0
print stepsSeen
for k,v in stepsSeen.iteritems():
if v > mostCommonCount:
mostCommonCount = v
mostCommonStep = k
+ print mostCommonStep
+ # hack for no data
+ if mostCommonStep == 0:
+ mostCommonStep = 60
for m in valuesMap.keys():
# resample everything to finest granularity
@@ -319,7 +319,7 @@ def processResult(key, family, column, val, ts):
seriesList = []
for m in valuesMap.keys():
- series = TimeSeries(removePrefix(m), start, end, lowestMetricStep, valuesMap[m])
+ series = TimeSeries(removePrefix(m), start, end, mostCommonStep, valuesMap[m])
series.pathExpression = pathExpr # hack to pass expressions through to render functions
seriesList.append(series)

0 comments on commit 33d3d46

Please sign in to comment.