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: avoid division by zero #458

Merged
merged 1 commit into from
Feb 13, 2020
Merged

fix: avoid division by zero #458

merged 1 commit into from
Feb 13, 2020

Conversation

deimosfr
Copy link
Contributor

@deimosfr deimosfr commented Feb 8, 2020

Summary

There is a bug with division by zero:

awslimitchecker 8.0.1 is AGPL-licensed free software; all users have a right to the full source code of this version. See <https://github.com/jantman/awslimitchecker>
Traceback (most recent call last):
...
  File "/awslimitchecker/limit.py", line 434, in check_thresholds
    pct = (usage / (limit * 1.0)) * 100
ZeroDivisionError: float division by zero

Contributor License Agreement

By submitting this work for inclusion in awslimitchecker, I agree to the following terms:

  • The contribution included in this request (and any subsequent revisions or versions of it)
    is being made under the same license as the awslimitchecker project (the Affero GPL v3,
    or any subsequent version of that license if adopted by awslimitchecker).
  • My contribution may perpetually be included in and distributed with awslimitchecker; submitting
    this pull request grants a perpetual, global, unlimited license for it to be used and distributed
    under the terms of awslimitchecker's license.
  • I have the legal power and rights to agree to these terms.

@codecov-io
Copy link

codecov-io commented Feb 8, 2020

Codecov Report

Merging #458 into develop will decrease coverage by 0.07%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #458      +/-   ##
===========================================
- Coverage      100%   99.92%   -0.08%     
===========================================
  Files           37       37              
  Lines         2823     2823              
  Branches       435      435              
===========================================
- Hits          2823     2821       -2     
- Misses           0        1       +1     
- Partials         0        1       +1
Impacted Files Coverage Δ
awslimitchecker/limit.py 98.8% <0%> (-1.2%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 37e843b...7aca720. Read the comment docs.

@jantman
Copy link
Owner

jantman commented Feb 12, 2020

@deimosfr Apologies for letting this sit so long, and thank you so much for the contribution! I'll do my best to get this released today or tomorrow.

@jantman jantman merged commit 5a6ffe5 into jantman:develop Feb 13, 2020
@jantman
Copy link
Owner

jantman commented Feb 13, 2020

@deimosfr I merged this and was doing some work on it locally adding test coverage, but I've run into a bit of an issue... I'm not entirely sure what a zero quota value means.

Would it be possible for you to please re-run awslimitchecker with debug-level output (-vv) to see exactly what service this is happening on, and then see which quota has a zero value? Before releasing this, I want to make sure that zero really means "you can't run any of this resource" and not that the default quota is in effect.

@deimosfr
Copy link
Contributor Author

Here is the output:

2020-02-24 00:05:00,459 [DEBUG connectionpool.py:428 - urllib3.connectionpool._make_request() ] https://ec2.eu-west-3.amazonaws.com:443 "POST / HTTP/1.1" 200 228
2020-02-24 00:05:00,466 [DEBUG ec2.py:696 - awslimitchecker.services.ec2._find_usage_networking_eni_sg() ] Getting usage for EC2 Network Interfaces
2020-02-24 00:05:00,817 [DEBUG connectionpool.py:428 - urllib3.connectionpool._make_request() ] https://ec2.eu-west-3.amazonaws.com:443 "POST / HTTP/1.1" 200 None
2020-02-24 00:05:02,514 [DEBUG ec2.py:204 - awslimitchecker.services.ec2._find_usage_spot_instances() ] Getting spot instance request usage
2020-02-24 00:05:02,571 [DEBUG connectionpool.py:428 - urllib3.connectionpool._make_request() ] https://ec2.eu-west-3.amazonaws.com:443 "POST / HTTP/1.1" 200 261
2020-02-24 00:05:02,574 [DEBUG ec2.py:227 - awslimitchecker.services.ec2._find_usage_spot_fleets() ] Getting spot fleet request usage
2020-02-24 00:05:02,636 [DEBUG connectionpool.py:428 - urllib3.connectionpool._make_request() ] https://ec2.eu-west-3.amazonaws.com:443 "POST / HTTP/1.1" 200 None
2020-02-24 00:05:02,637 [DEBUG ec2.py:128 - awslimitchecker.services.ec2.find_usage() ] Done checking usage.
Traceback (most recent call last):
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/bin/awslimitchecker", line 8, in <module>
    sys.exit(console_entry_point())
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/runner.py", line 548, in console_entry_point
    r.console_entry_point()
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/runner.py", line 520, in console_entry_point
    res, problems, problem_str = self.check_thresholds(metrics)
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/runner.py", line 332, in check_thresholds
    problems = self.checker.check_thresholds(
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/checker.py", line 633, in check_thresholds
    tmp = cls.check_thresholds()
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/services/base.py", line 260, in check_thresholds
    if limit.check_thresholds() is False:
  File "/home/pmavro/workspace/qovery/awslimitchecker/limitchecker/lib/python3.8/site-packages/awslimitchecker/limit.py", line 434, in check_thresholds
    pct = (usage / (limit * 1.0)) * 100
ZeroDivisionError: float division by zero

@jantman
Copy link
Owner

jantman commented Feb 26, 2020

@deimosfr Apologies, it looks like that didn't give me the level of information that I was looking for. Do you think that you could please also include the output of awslimitchecker -vv --list-limits (also specifying any other parameters that you did previously, such as service or region names)? I think that should let us see exactly which limit is being detected as zero, and confirm which source it's getting that value from.

@jantman
Copy link
Owner

jantman commented Mar 3, 2020

I believe that #460 is for this same issue. I'll try to get a release cut today.

@jantman
Copy link
Owner

jantman commented Mar 3, 2020

This has been released as 8.0.2 and is now live on PyPI.

Thank you so much!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants