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

[portstat, intfstat] update rates and utilization #817

Closed
wants to merge 9 commits into from

Conversation

mykolaf
Copy link
Collaborator

@mykolaf mykolaf commented Feb 21, 2020

According to HLD

Depends on sonic-swws-common #330

- What I did
Update the logic for port rates and utilization
- How I did it

- How to verify it

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

admin@sonic:~$ show int count
      IFACE    STATE    RX_OK    RX_BPS    RX_UTIL    RX_ERR    RX_DRP    RX_OVR    TX_OK    TX_BPS    TX_UTIL    TX_ERR    TX_DRP    TX_OVR
-----------  -------  -------  --------  ---------  --------  --------  --------  -------  --------  ---------  --------  --------  --------
  Ethernet0        X        0       N/A        N/A         0         0       N/A        0       N/A        N/A         0         0       N/A
  Ethernet2        U      287       N/A        N/A         0         0       N/A      818       N/A        N/A         0         0       N/A
  Ethernet4        U      380       N/A        N/A         0         0       N/A      858       N/A        N/A         0         0       N/A
  Ethernet6        U      286       N/A        N/A         0         0       N/A      850       N/A        N/A         0         0       N/A

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

admin@sonic:~$ show int count
      IFACE    STATE    RX_OK      RX_BPS    RX_UTIL    RX_ERR    RX_DRP    RX_OVR    TX_OK      TX_BPS    TX_UTIL    TX_ERR    TX_DRP    TX_OVR
-----------  -------  -------  ----------  ---------  --------  --------  --------  -------  ----------  ---------  --------  --------  --------
  Ethernet0        X        0    0.00 B/s      0.00%         0         0       N/A        0    0.00 B/s      0.00%         0         0       N/A
  Ethernet2        U        0    0.00 B/s      0.00%         0         0       N/A        0    0.00 B/s      0.00%         0         0       N/A
  Ethernet4        U        0    0.00 B/s      0.00%         0         0       N/A        0    0.00 B/s      0.00%         0         0       N/A
  Ethernet6        U        0    0.00 B/s      0.00%         0         0       N/A        0    0.00 B/s      0.00%         0         0       N/A

"PortChannel0003 0 0.00 B/s 0.00/s 0 0 0.00 B/s 0.00/s 0",
"PortChannel0004 0 0.00 B/s 0.00/s 0 0 0.00 B/s 0.00/s 0",
"Vlan1000 0 0.00 B/s 0.00/s 0 0 0.00 B/s 0.00/s 0"]
expected = ["Ethernet20 0 0.00 B/s 0.00/s 0.00% 0 0 0.00 B/s 0.00/s 0.00% 0",
Copy link
Contributor

Choose a reason for hiding this comment

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

what will be command to check RIF Counters ?
Has this been verified if RIF is both Over Port-Channel and VLAN ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The command to check RIF counters is show interface counters rif .

scripts/portstat Outdated
format_prate(rates.rx_pps),
format_util(rates.rx_util),
ns_diff(cntr.rx_err, old_cntr.rx_err),
ns_diff(cntr.rx_drop, old_cntr.rx_drop),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the O/P of show interface counters remains same (backward compatible ) after these changes ? Is there any difference ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is no difference in how the output looks,
one difference in behavior is that clear command will not affect the rates&utilization. Still clears the counters.

@lgtm-com
Copy link

lgtm-com bot commented Apr 21, 2020

This pull request introduces 2 alerts when merging de7c8588372de20b3f1d042b979fc513ac840b44 into a87173b - view on LGTM.com

new alerts:

  • 1 for Unused local variable
  • 1 for Result of integer division may be truncated

abdosi
abdosi previously approved these changes May 18, 2020
@qiluo-msft
Copy link
Contributor

qiluo-msft commented Jun 8, 2020

Please fix LGTM new alerts.


In reply to: 640825246

@lgtm-com
Copy link

lgtm-com bot commented Jun 9, 2020

This pull request introduces 10 alerts when merging a1806b533ea2c14459e19dcf630faa1c0033a96d into d2c997c - view on LGTM.com

new alerts:

  • 6 for Wrong number of arguments in a call
  • 2 for Result of integer division may be truncated
  • 1 for Unused import
  • 1 for Variable defined multiple times

@lgtm-com
Copy link

lgtm-com bot commented Jun 9, 2020

This pull request introduces 3 alerts when merging 45ea09182dc6b310350db47f7c4cf733bd4646c3 into 1ddd3f2 - view on LGTM.com

new alerts:

  • 2 for Result of integer division may be truncated
  • 1 for Unused local variable

@lgtm-com
Copy link

lgtm-com bot commented Jun 10, 2020

This pull request introduces 1 alert when merging 42a3a941050c2e99946f9dece87aa78e5cb7e44f into 1ddd3f2 - view on LGTM.com

new alerts:

  • 1 for Result of integer division may be truncated

@mykolaf
Copy link
Collaborator Author

mykolaf commented Jun 10, 2020

retest this please

@liat-grozovik
Copy link
Collaborator

@abdosi anything else needed to approve this PR?

abdosi
abdosi previously approved these changes Jul 7, 2020
Copy link
Contributor

@abdosi abdosi left a comment

Choose a reason for hiding this comment

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

LGTM

@mykolaf
Copy link
Collaborator Author

mykolaf commented Jul 20, 2020

@abdosi can we merge this?

@liat-grozovik
Copy link
Collaborator

@mykolaf can this be merged or this is pending on another PR?

@volodymyrsamotiy
Copy link
Collaborator

@abdosi, could you please help to have this PR merged?
It is approved, all checks passed and all other related PRs are already merged, without it we have incomplete functionality in master.
Thanks.

liat-grozovik
liat-grozovik previously approved these changes Aug 3, 2020
@mykolaf

This comment has been minimized.

2 similar comments
@liat-grozovik
Copy link
Collaborator

retest this please

@liat-grozovik
Copy link
Collaborator

retest this please

Copy link
Contributor

@lguohan lguohan left a comment

Choose a reason for hiding this comment

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

since there is new feature is added, need unit test to cover the new feature.

Mykola Faryma added 3 commits August 18, 2020 19:02
Signed-off-by: Mykola Faryma <[email protected]>
Signed-off-by: Mykola Faryma <[email protected]>
@lgtm-com
Copy link

lgtm-com bot commented Oct 20, 2020

This pull request introduces 2 alerts when merging 3b46b03 into 13bd06b - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Wrong number of arguments in a call

* Fix review comments

Signed-off-by: Volodymyr Samotiy <[email protected]>
liat-grozovik
liat-grozovik previously approved these changes Oct 20, 2020
lguohan
lguohan previously approved these changes Oct 22, 2020
@lguohan
Copy link
Contributor

lguohan commented Oct 22, 2020

retest this please

@lguohan
Copy link
Contributor

lguohan commented Oct 22, 2020

looks like the unit test are failing, can you folks check?

@keboliu
Copy link
Collaborator

keboliu commented Nov 4, 2020

retest this please

2 similar comments
@liat-grozovik
Copy link
Collaborator

retest this please

@liat-grozovik
Copy link
Collaborator

retest this please

…o rates

Conflicts:
	scripts/intfstat
	scripts/portstat
	utilities_common/netstat.py
@volodymyrsamotiy volodymyrsamotiy dismissed stale reviews from lguohan and liat-grozovik via 66cf477 June 10, 2021 15:37
@lgtm-com
Copy link

lgtm-com bot commented Jun 10, 2021

This pull request introduces 1 alert when merging 66cf477 into 25e17de - view on LGTM.com

new alerts:

  • 1 for Wrong number of arguments in a call

* Fix "wrong number of args" issue after merge from upstream

Signed-off-by: Volodymyr Samotiy <[email protected]>
@liat-grozovik
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liat-grozovik
Copy link
Collaborator

@lguohan can you please review and approve? we currently have a mismatch between the CLI and the way the rates are calculated by the lua script.

@lguohan
Copy link
Contributor

lguohan commented Jul 15, 2021

can you check the pr check failure?

@liat-grozovik
Copy link
Collaborator

@dgsudharsan can you please also review?

@liat-grozovik
Copy link
Collaborator

@lguohan can you please review following the fixes provided?

cntr.tx_p_err))
old_cntr = NStats._make([0] * len(nstat_fields))

rates = ratestat_dict.get(key, RateStats._make([STATUS_NA]*len(ratestat_fields)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think ratestat_dict is defined anywhere else in the file. Is there a missing piece of code?


STATUS_NA = 'N/A'
PORT_RATE = 40

rates_key_list = [ 'RX_BPS', 'RX_PPS', 'RX_UTIL', 'TX_BPS', 'TX_PPS', 'TX_UTIL' ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think these should be declared in this file. This needs to go inside portstat and rifstat respectively. This file is meant to be like a library for various formatting APIs

"""
Get the Intf speed
"""
full_table_id = PORT_STATUS_TABLE_PREFIX + port_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

PORT_STATUS_TABLE_PREFIX doesn't seem to be defined anywhere. Missing code?

"""
full_table_id = PORT_STATUS_TABLE_PREFIX + port_name
admin_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_ADMIN_STATUS_FIELD)
oper_state = self.db.get(self.db.APPL_DB, full_table_id, PORT_OPER_STATUS_FIELD)
Copy link
Collaborator

Choose a reason for hiding this comment

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

PORT_OPER_STATUS_FIELD doesn't seem to be defined anywhere. Missing code?

Comment on lines +137 to +145
if admin_state is None or oper_state is None:
return STATUS_NA
elif admin_state.upper() == PORT_STATUS_VALUE_DOWN:
return PORT_STATE_DISABLED
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_UP:
return PORT_STATE_UP
elif admin_state.upper() == PORT_STATUS_VALUE_UP and oper_state.upper() == PORT_STATUS_VALUE_DOWN:
return PORT_STATE_DOWN
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please check all the variables used there. They don't seem to be defined.

@@ -127,6 +127,24 @@ class Intfstat(object):
else:
return STATUS_NA

def get_intf_speed(self, port_name):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This API is not called anywhere. Why is this API needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also check why get_intf_state is needed. I don't see it called anywhere

@@ -110,17 +110,9 @@ def test_clear(self):
assert result.exit_code == 0
result = runner.invoke(show.cli.commands["interfaces"].commands["counters"].commands["rif"], [])
print(result.stdout)
expected = ["Ethernet20 0 0.00 B/s 0.00/s 0 0 0.00 B/s 0.00/s 0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please include the new output in the test rather than just removing the expected here? I believe it's required to validate the output format

if brate == STATUS_NA:
return STATUS_NA
else:
util = brate/(float(port_rate)*1024*1024*1024/8.0)*100
Copy link
Collaborator

Choose a reason for hiding this comment

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

This assumes the port speed to be Gbps. Though most of the devices have lowest speed as 1 Gbps. I don't think it's a good design here. If SONiC is planned to be used for management and other low capacity devices in the future this will become a bug for ports less than 1Gbps. I would rather prefer logic using the port speed to determine the factor to divide rather than blindly assuming Gbps

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please describe the suggested approach in more detail?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe port speed can be used to figure out if it is in Gbps or Mbps. By default I believe speed is in Mbps (eg 40G is 40000)

@volodymyrsamotiy
Copy link
Collaborator

Closing since there is new PR #1750 with the same changes + some fixes and rebased code.

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.

9 participants