Rolling Standard Deviation for N samples triggers UnboundLocalError in specific cases
I've discovered that the `stdev` function in graphite.
Basically, it boils down to a local named sumOfSquares not being initialized on the first N items, because the average is None (the sum is None; there is no data in the first N samples). And later in the series, a non-None average appears, and uninitialized sumOfSquares is passed in doStdDev, causing the error.
How can this be triggered? Well, as a simple replication case, if on the Graphite Composer you want to plot the last 24 hours, and you take the standard deviation of some metric that only has data starting 3 hours ago (ie. the data for the first 21 hours is None), then it'll blow up.
-- Andrew Crowell
Also, for some more diagnostics, here is a real, more complicated example, and the traceback demonstrating the problem:
Environment:
Request Method: GET
Request URL: http://
Django Version: 1.1.1
Python Version: 2.6.5
Installed Applications:
['graphite.
'graphite.render',
'graphite.cli',
'graphite.
'graphite.
'graphite.
'graphite.
'graphite.
'graphite.events',
'django.
'django.
'django.
'django.
'tagging']
Installed Middleware:
('django.
'django.
'django.
'django.
Traceback:
File "/usr/lib/
92. response = callback(request, *callback_args, **callback_kwargs)
File "/opt/graphite/
105. seriesList = evaluateTarget(
File "/opt/graphite/
10. result = evaluateTokens(
File "/opt/graphite/
21. return evaluateTokens(
File "/opt/graphite/
28. args = [evaluateTokens
File "/opt/graphite/
21. return evaluateTokens(
File "/opt/graphite/
28. args = [evaluateTokens
File "/opt/graphite/
21. return evaluateTokens(
File "/opt/graphite/
28. args = [evaluateTokens
File "/opt/graphite/
21. return evaluateTokens(
File "/opt/graphite/
29. return func(requestCon
File "/opt/graphite/
1071. (sd, sumOfSquares) = doStdDev(
Exception Type: UnboundLocalError at /render/
Exception Value: local variable 'sumOfSquares' referenced before assignment
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Graphite Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Andrew Crowell for more information if necessary.