Fec counters clear function#4640
Open
nkanchi-nexthop wants to merge 6 commits into
Open
Conversation
Signed-off-by: nkanchi-nexthop <nkanchi@nexthop.ai>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
prgeor
reviewed
Jul 9, 2026
|
|
||
|
|
||
| ======= | ||
| >>>>>>> 6009f7ce (NOS-8001: Clear all FEC counters in SONiC properly including histogram (#591)) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes sonic-clear counters not resetting FEC histogram/sliding-window outputs by aligning show interfaces counters fec-histogram with the portstat -fh cached clear-counter flow and extending portstat -c to clear additional FEC aggregate fields in RATES:<oid>.
Changes:
- Add a single-interface “vertical” FEC histogram view in
utilities_common/portstat.py, including per-bin “Last Updated” timestamps and optional relative time. - Extend
scripts/portstat -cto clear FEC sliding-window aggregate fields fromRATES:<oid>. - Add/extend unit tests to validate the updated
fec-histogramcommand behavior, cache contents, and aggregate clearing behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| utilities_common/portstat.py | Adds vertical FEC histogram rendering and timestamp/relative-time support; updates cnstat printing flow. |
| scripts/portstat | Adds --relative-timestamp flag; clears FEC aggregate fields on -c; wires relative-timestamp through to portstat output. |
| show/interfaces/init.py | Updates show interfaces counters fec-histogram to delegate to portstat -fh (but currently contains merge-conflict artifacts). |
| tests/portstat_test.py | Adds tests for the new flow and clearing behavior (but currently contains merge-conflict artifacts). |
Comments suppressed due to low confidence (1)
tests/portstat_test.py:75
- Unresolved merge-conflict markers (<<<<<<< / ======= / >>>>>>>) are present in this expected-output string, which will break test collection. Remove the conflict markers and keep the intended baseline string definition.
<<<<<<< HEAD
intf_fec_counters_fec_hist = """\
Symbol Errors Per Codeword Codewords
---------------------------- -----------
BIN0 1000000
Comment on lines
+916
to
+920
| <<<<<<< HEAD | ||
| @clicommon.pass_db | ||
| def fec_histogram(db, interfacename, namespace, display): | ||
| ======= | ||
| @click.pass_context |
Comment on lines
519
to
+523
| def test_show_intf_counters_fec_histogram(self): | ||
| runner = CliRunner() | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["counters"].commands["fec-histogram"], ["Ethernet0"]) | ||
| with mock.patch('show.interfaces.clicommon.run_command') as mock_run: | ||
| result = runner.invoke( | ||
| show.cli.commands["interfaces"].commands["counters"].commands["fec-histogram"], ["Ethernet0"]) |
Comment on lines
11
to
13
| from utilities_common import constants | ||
| from utilities_common.general import format_relative_time | ||
| import utilities_common.multi_asic as multi_asic_util |
Comment on lines
+442
to
+451
| ts_ms = asic_kvp.get(SAI_FEC_BIN_TIMESTAMP_KEY.format(i)) if asic_kvp else None | ||
| if ts_ms: | ||
| ts_str = datetime.datetime.fromtimestamp(int(ts_ms) / 1000.0) \ | ||
| .strftime('%Y-%m-%d %H:%M:%S') | ||
| else: | ||
| ts_str = STATUS_NA | ||
| row = ['BIN{}'.format(i), codewords, ts_str] | ||
| if relative_timestamp: | ||
| row.append(format_relative_time(ts_ms) if ts_ms else STATUS_NA) | ||
| table.append(row) |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Nikhil Kanchi <nkanchi@nexthop.ai>
a99f80d to
d828ca9
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Nikhil Kanchi <nkanchi@nexthop.ai>
edc104e to
eefe794
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Nikhil Kanchi <nkanchi@nexthop.ai>
f1bb371 to
c7cbaf3
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did
The
sonic-clear counterscommand does not reset FEC histogram output, soshow interface counters fec-histogramcontinued to show lifetime bin values after a clear. This fixes the upstream issue sonic-net/sonic-utilities#3741.How I did it
show interface counters fec-histogramto useportstat -fh -i <iface>so it follows the cached clear-counter flow introduced upstream in sonic-net/sonic-utilities#4075.portstat -cto clear the FEC sliding-window aggregate fields stored inRATES:<oid>.How to verify it
show interface counters fec-histogram <iface>andshow interface counters fec-stats <iface>on a port with existing FEC data.sonic-clear countersthen re-run the previous commands to confirm the histogram output and FEC sliding-window aggregates are reset.tests/portstat_test.py.Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)