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

feat: add support for scientific get_counters #3538

Conversation

auspham
Copy link

@auspham auspham commented Sep 10, 2024

What I did

Fix #19192 happens when the counters value gets too big and turns into scientific number

How I did it

Since value getting from counters_db will be serialise to string. The scientific number will be serialised to something like 1e+1.

As a result, doing int("1e+1") directly will throw an error. Since natural of scientific number is float. A fix is to convert "1e+1" to 10.0 first and then do int(10.0)

How to verify it

  1. Sending large volume of traffic using traffic generator.
  2. run "portstat" or "show interface count" or "sonic-clear counter" without seeing #19192

Previous command output (if the output of a command-line utility has changed)

$ sudo ip netns exec asic2 portstat | grep -E 'IFACE|Ethernet256|Ethernet264'

Traceback (most recent call last):
  File "/usr/local/bin/portstat", line 675, in <module>
    main()
  File "/usr/local/bin/portstat", line 635, in main
    cnstat_dict, ratestat_dict = portstat.get_cnstat_dict()
  File "/usr/local/bin/portstat", line 151, in get_cnstat_dict
    self.collect_stat()
  File "/usr/local/lib/python3.9/dist-packages/utilities_common/multi_asic.py", line 157, in wrapped_run_on_all_asics
    func(self,  *args, **kwargs)
  File "/usr/local/bin/portstat", line 161, in collect_stat
    cnstat_dict, ratestat_dict = self.get_cnstat()
  File "/usr/local/bin/portstat", line 215, in get_cnstat
    cnstat_dict[port] = get_counters(port)
  File "/usr/local/bin/portstat", line 182, in get_counters
    fields[pos] = str(int(fields[pos]) + int(fvs[counter_name]))
ValueError: invalid literal for int() with base 10: '1.8342735403386e+14'

New command output (if the output of a command-line utility has changed)

TBD

Signed-off-by: Austin Pham <austinpham@microsoft.com>
@auspham auspham force-pushed the austinpham/28301884-add-scientific-support-portstat branch from 5fac540 to cfcdd6a Compare September 10, 2024 22:57
@yejianquan
Copy link
Contributor

Hi @qiluo-msft , could you help to review this PR?

@auspham
Copy link
Author

auspham commented Sep 19, 2024

Hi @qiluo-msft could you please help reviewing?

# fvs[counter_name] will be a string. To support scientific number, we convert it to float
# first since scientific number internally is a float.
# https://stackoverflow.com/questions/32861429/converting-number-in-scientific-notation-to-int
counter_value = int(float(fvs[counter_name]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bug should be appear even earlier. fvs[counter_name] should not be assigned string of a float number like "1e+1".

@auspham
Copy link
Author

auspham commented Oct 2, 2024

Closes as already opened in #3420

@auspham auspham closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[chassis]ValueError exception in interface counter
3 participants