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 multi-asic behaviour for dropstat #3059

Merged
merged 9 commits into from
Jul 24, 2024

Conversation

bktsim-arista
Copy link
Contributor

What I did

Previously, dropstat was not behaving correctly on multi-asic devices as the correct namespaces were not being traversed and namespace option -n was not available. This change fixes the multi-asic behaviour of this command and adds the -n option, with relevant unit tests to ensure correct functionality.

This is a part of the set of changes being pushed for sonic-net/sonic-buildimage#15148

How I did it

Added -n argument for multi-asic devices and relevant unit tests.

How to verify it

Use dropstat -c show with -n.

scripts/dropstat Outdated
if namespace and namespace not in namespaces:
raise Exception("Input arguments error. Namespaces must be one of", *namespaces)

if multi_asic.is_multi_asic() and not namespace:
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be replaced with a more consistent way at line 411:
@click.option('-n', '--namespace', help='Namespace name',
required=True if multi_asic.is_multi_asic() else False, type=click.Choice(multi_asic.get_namespace_list()))

Choose a reason for hiding this comment

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

@wenyiz2021 are you sure we should be using the @click decorators within the scripts/ folder?
This dropstat file doesn't hold any CLI commands just the implementation code for querying the redis DBs

Copy link
Contributor

Choose a reason for hiding this comment

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

See latest change. I took your suggestion to use the click library. Thanks!

os.environ["UTILITIES_UNIT_TESTING"] = "1"
os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic"
print("SETUP")

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add edge cases like:

  1. when no namespace is given for multi-asic
  2. when namespace is given on single-asic

Copy link
Contributor

Choose a reason for hiding this comment

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

See latest change. Above two edges have been covered in new UTs.

@vmittal-msft
Copy link
Contributor

@bktsim-arista Few things -

  1. Can you please share how "Show dropcounter capabilites/configuration/counts" command is going to change ?
  2. please add test for all options under dropcounter.
  3. If no namespace specified, Will it show for all namespaces? if we specify, will it show for only that namespace ?
  4. Is this verified to be working fine on pizza box as well as chassis?

Copy link
Contributor

@vmittal-msft vmittal-msft left a comment

Choose a reason for hiding this comment

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

Please check comment

@arista-nwolfe
Copy link

@bktsim-arista Few things -

  1. Can you please share how "Show dropcounter capabilites/configuration/counts" command is going to change ?
  2. please add test for all options under dropcounter.
  3. If no namespace specified, Will it show for all namespaces? if we specify, will it show for only that namespace ?
  4. Is this verified to be working fine on pizza box as well as chassis?

For questions 1 & 2: This PR only adds multi-asic support to show dropcounter counts so we shouldn't include test coverage for capabilities/configuration as it's not supported yet on multi-asic.

bktsim-arista and others added 5 commits June 30, 2024 15:22
and ensuring that dropstat iterates through correct namespaces
when 'show' command is run.
- Use click library as suggested by Wenyi to simplify argument parsing
- Support --namespace argument conditionally. If not passed, the default
  behavior is to display all namespaces.
- Utilize `run_on_multi_asic` decorator to abstract iterating over
  namespaces
- Added and updating UTs
Multi-asic counter clear is supported by unconditionally caching
counters from all namespaces. Also add new UTs to cover changes.
@kenneth-arista
Copy link
Contributor

@arlakshm please review

counter_type = args.type

dcstat = DropStat()
@click.command(help='Display drop counters')
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to add this change here?
dropstat is standalone python script. the click options need to present in show/dropcounter.py

Copy link
Contributor

Choose a reason for hiding this comment

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

The original script also supported argument parsing. Using the click simplified that logic significantly. It was suggested earlier by Wenyi and I agree this is an improvement over what was originally implemented. Furthermore, the UTs directly call this script.

@@ -1,5 +1,6 @@
import click
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some test to cover the single asic as well?

Also fixed test_show_pg_drop_masic_invalid_ns
To avoid interference of cached counters between UTs.
@kenneth-arista
Copy link
Contributor

kenneth-arista commented Jul 1, 2024

  • If no namespace specified, Will it show for all namespaces? if we specify, will it show for only that namespace ?

The latest changes support this.

wenyiz2021
wenyiz2021 previously approved these changes Jul 2, 2024
Copy link
Contributor

@wenyiz2021 wenyiz2021 left a comment

Choose a reason for hiding this comment

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

LGTM

@wenyiz2021
Copy link
Contributor

@arlakshm @vmittal-msft please check if your review comments are resolved

@kenneth-arista
Copy link
Contributor

  1. Is this verified to be working fine on pizza box as well as chassis?
    Yes, I verified that the changes work on a pizza box with a single ASIC.

For example,

admin@pkz303:/$ show dropcounters counts  --help
Usage: show dropcounters counts [OPTIONS]

  Show drop counts

Options:
  -g, --group TEXT
  -t, --counter_type TEXT
  --verbose                Enable verbose output
  -n, --namespace []       Namespace name or all
  -h, -?, --help           Show this message and exit.

admin@pkz303:/$ show dropcounters counts
     IFACE    STATE    RX_ERR    RX_DROPS    TX_ERR    TX_DROPS    DEBUG1    DEBUG2    DEBUG3
----------  -------  --------  ----------  --------  ----------  --------  --------  --------
 Ethernet0        U         0           0         0           0         0         0         0
 Ethernet1        X         0           0         0           0         0         0         0
 Ethernet2        U         0           0         0           0         0         0         0
 Ethernet3        U         0           0         0           0         0         0         0
 Ethernet4        X         0           0         0           0         0         0         0
 Ethernet5        X         0           0         0           0         0         0         0
 Ethernet6        X         0           0         0           0         0         0         0
 Ethernet7        U         0           0         0           0         0         0         0
 Ethernet8        U         0           0         0           0         0         0         0
 Ethernet9        U         0           0         0           0         0         0         0
Ethernet10        U         0           0         0           0         0         0         0
Ethernet11        X         0           0         0           0         0         0         0
Ethernet12        U         0           0         0           0         0         0         0
Ethernet13        U         0           0         0           0         0         0         0
Ethernet14        U         0           0         0           0         0         0         0
Ethernet15        U         0           0         0           0         0         0         0
Ethernet16        X         0           0         0           0         0         0         0
Ethernet17        X         0           0         0           0         0         0         0
Ethernet18        U         0           0         0           0         0         0         0
Ethernet19        X         0           0         0           0         0         0         0
Ethernet20        U         0           0         0           0         0         0         0
Ethernet21        X         0           0         0           0         0         0         0
Ethernet22        U         0           0         0           0         0         0         0
Ethernet23        U         0           0         0           0         0         0         0
Ethernet24        U         0           0         0           0         0         0         0
Ethernet25        U         0           0         0           0         0         0         0
Ethernet26        U         0           0         0           0         0         0         0
Ethernet27        U         0           0         0           0         0         0         0
Ethernet28        U         0           0         0           0         0         0         0
Ethernet29        X         0           0         0           0         0         0         0
Ethernet30        U         0           0         0           0         0         0         0
Ethernet31        X         0           0         0           0         0         0         0
Ethernet32        U         0           0         0           0         0         0         0
Ethernet33        U         0           0         0           0         0         0         0
Ethernet34        X         0           0         0           0         0         0         0
Ethernet35        U         0           0         0           0         0         0         0
Ethernet36        U         0           0         0           0         0         0         0
Ethernet37        X         0           0         0           0         0         0         0
Ethernet38        U         0           0         0           0         0         0         0
Ethernet39        X         0           0         0           0         0         0         0
Ethernet40        X         0           0         0           0         0         0         0
Ethernet41        U         0           0         0           0         0         0         0
Ethernet42        U         0           0         0           0         0         0         0
Ethernet43        X         0           0         0           0         0         0         0
Ethernet44        X         0           0         0           0         0         0         0
Ethernet45        U         0           0         0           0         0         0         0
Ethernet46        X         0           0         0           0         0         0         0
Ethernet47        U         0           0         0           0         0         0         0
Ethernet48        U         0           0         0           0         0         0         0
Ethernet49        U         0           0         0           0         0         0         0
Ethernet50        U         0           0         0           0         0         0         0
Ethernet51        U         0           0         0           0         0         0         0

admin@pkz303:/$ show dropcounters counts -g TEST

     IFACE    STATE    DEBUG3
----------  -------  --------
 Ethernet0        U         0
 Ethernet1        X         0
 Ethernet2        U         0
 Ethernet3        U         0
 Ethernet4        X         0
 Ethernet5        X         0
 Ethernet6        X         0
 Ethernet7        U         0
 Ethernet8        U         0
 Ethernet9        U         0
Ethernet10        U         0
Ethernet11        X         0
Ethernet12        U         0
Ethernet13        U         0
Ethernet14        U         0
Ethernet15        U         0
Ethernet16        X         0
Ethernet17        X         0
Ethernet18        U         0
Ethernet19        X         0
Ethernet20        U         0
Ethernet21        X         0
Ethernet22        U         0
Ethernet23        U         0
Ethernet24        U         0
Ethernet25        U         0
Ethernet26        U         0
Ethernet27        U         0
Ethernet28        U         0
Ethernet29        X         0
Ethernet30        U         0
Ethernet31        X         0
Ethernet32        U         0
Ethernet33        U         0
Ethernet34        X         0
Ethernet35        U         0
Ethernet36        U         0
Ethernet37        X         0
Ethernet38        U         0
Ethernet39        X         0
Ethernet40        X         0
Ethernet41        U         0
Ethernet42        U         0
Ethernet43        X         0
Ethernet44        X         0
Ethernet45        U         0
Ethernet46        X         0
Ethernet47        U         0
Ethernet48        U         0
Ethernet49        U         0
Ethernet50        U         0
Ethernet51        U         0

admin@pkz303:/$ show dropcounters counts -t PORT_INGRESS_DROPS
     IFACE    STATE    RX_ERR    RX_DROPS    DEBUG1    DEBUG2    DEBUG3
----------  -------  --------  ----------  --------  --------  --------
 Ethernet0        U         0           0         0         0         0
 Ethernet1        X         0           0         0         0         0
 Ethernet2        U         0           0         0         0         0
 Ethernet3        U         0           0         0         0         0
 Ethernet4        X         0           0         0         0         0
 Ethernet5        X         0           0         0         0         0
 Ethernet6        X         0           0         0         0         0
 Ethernet7        U         0           0         0         0         0
 Ethernet8        U         0           0         0         0         0
 Ethernet9        U         0           0         0         0         0
Ethernet10        U         0           0         0         0         0
Ethernet11        X         0           0         0         0         0
Ethernet12        U         0           0         0         0         0
Ethernet13        U         0           0         0         0         0
Ethernet14        U         0           0         0         0         0
Ethernet15        U         0           0         0         0         0
Ethernet16        X         0           0         0         0         0
Ethernet17        X         0           0         0         0         0
Ethernet18        U         0           0         0         0         0
Ethernet19        X         0           0         0         0         0
Ethernet20        U         0           0         0         0         0
Ethernet21        X         0           0         0         0         0
Ethernet22        U         0           0         0         0         0
Ethernet23        U         0           0         0         0         0
Ethernet24        U         0           0         0         0         0
Ethernet25        U         0           0         0         0         0
Ethernet26        U         0           0         0         0         0
Ethernet27        U         0           0         0         0         0
Ethernet28        U         0           0         0         0         0
Ethernet29        X         0           0         0         0         0
Ethernet30        U         0           0         0         0         0
Ethernet31        X         0           0         0         0         0
Ethernet32        U         0           0         0         0         0
Ethernet33        U         0           0         0         0         0
Ethernet34        X         0           0         0         0         0
Ethernet35        U         0           0         0         0         0
Ethernet36        U         0           0         0         0         0
Ethernet37        X         0           0         0         0         0
Ethernet38        U         0           0         0         0         0
Ethernet39        X         0           0         0         0         0
Ethernet40        X         0           0         0         0         0
Ethernet41        U         0           0         0         0         0
Ethernet42        U         0           0         0         0         0
Ethernet43        X         0           0         0         0         0
Ethernet44        X         0           0         0         0         0
Ethernet45        U         0           0         0         0         0
Ethernet46        X         0           0         0         0         0
Ethernet47        U         0           0         0         0         0
Ethernet48        U         0           0         0         0         0
Ethernet49        U         0           0         0         0         0
Ethernet50        U         0           0         0         0         0
Ethernet51        U         0           0         0         0         0

admin@pkz303:/$ dropstat --version
dropstat, version 1.0

Also some minor test renaming and cleanup for clarity
@wenyiz2021
Copy link
Contributor

@arlakshm has a concern on using click option in scripts directory which is outside of show directory.
otherwise LGTM.
thanks @kenneth-arista for adding test as well

@kenneth-arista
Copy link
Contributor

@arlakshm has a concern on using click option in scripts directory which is outside of show directory. otherwise LGTM. thanks @kenneth-arista for adding test as well

Thanks @wenyiz2021 . The @click library usage in the script significantly improves the readability and maintainability of the standalone script. Thanks Wenyi for suggesting it. I think this is a good change. @arlakshm please let me know how you would like to proceed. I recommend keeping the change 😄

@kenneth-arista
Copy link
Contributor

@wenyiz2021 can you help merge this change?

@wenyiz2021 wenyiz2021 merged commit a813215 into sonic-net:master Jul 24, 2024
7 checks passed
mssonicbld pushed a commit to mssonicbld/sonic-utilities that referenced this pull request Nov 30, 2024
* Fixes dropstat multi-asic behaviour by using multi-asic helpers
and ensuring that dropstat iterates through correct namespaces
when 'show' command is run.


Co-authored-by: rdjeric <rdjeric@arista.com>
Co-authored-by: Kenneth Cheung <kennethcheung@arista.com>
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202405: #3637

mssonicbld pushed a commit that referenced this pull request Nov 30, 2024
* Fixes dropstat multi-asic behaviour by using multi-asic helpers
and ensuring that dropstat iterates through correct namespaces
when 'show' command is run.


Co-authored-by: rdjeric <rdjeric@arista.com>
Co-authored-by: Kenneth Cheung <kennethcheung@arista.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants