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

Fix asPercent so that panic does not occur if seriesList and total values are not the same length #86

Closed
carrieedwards opened this issue Aug 29, 2022 · 0 comments · Fixed by #87
Labels
bug Something isn't working

Comments

@carrieedwards
Copy link
Collaborator

carrieedwards commented Aug 29, 2022

For asPercent, if total is specified and it is a list of the same length as seriesList, but the length of each series' values is longer than the length of each totalSeries values, the following panic is occurring:

recovered from panic: \"runtime error: index out of range [5] with length 5

This is occurring when total[n].Values[i] is accessed, when i is an index greater than the length of total[n].Values.

In Graphite web, this situation is prevented by the following:

https://github.com/graphite-project/graphite-web/blob/b52987ac97f49dcfb401a21d4b92860cfcbcf074/webapp/graphite/render/functions.py#L1041

When izip_longest() is called in Python, if the series are different lengths, then None will be used for the value for that series' item in the tuple. Then safeDiv will return None for the value if one of the series has a value of None.

To fix this issue in CarbonAPI, the percentage calculates for seriesList should stop at the point where it exceeds the length of totalSeries values and then math.NaN() should be assigned to the remaining values.

@carrieedwards carrieedwards added the bug Something isn't working label Aug 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant