Skip to content

Fix regex in benchmarks cpu/disk_on_idle (BugFix)#2487

Open
bladernr wants to merge 6 commits into
mainfrom
2477-invalid-escape-char-in-benchmarks_idle_tests
Open

Fix regex in benchmarks cpu/disk_on_idle (BugFix)#2487
bladernr wants to merge 6 commits into
mainfrom
2477-invalid-escape-char-in-benchmarks_idle_tests

Conversation

@bladernr
Copy link
Copy Markdown
Collaborator

@bladernr bladernr commented Apr 21, 2026

Description

Resolved issues

Resolves #2477
Resolves CHECKBOX-2238

Documentation

NA

Tests

Tested on a fresh Bionic install to verify rawstrings does work back that far:

u@bionic-tester:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04 LTS
Release:        18.04
Codename:       bionic
u@bionic-tester:~$ python3 --version
Python 3.6.5
u@bionic-tester:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall(r"idle\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
99.787 %
u@bionic-tester:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall(r"util\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
0.013000000000000001 %

For comparison, this is Resolute where the initial warnings appeared for me, showing before and after:

bladernr@resolute-test:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu Resolute Raccoon (development branch)
Release:        26.04
Codename:       resolute
bladernr@resolute-test:~$ python3 --version
Python 3.14.4
bladernr@resolute-test:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall("idle\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
<string>:1: SyntaxWarning: "\S" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\S"? A raw string is also an option.
98.978 %
bladernr@resolute-test:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall(r"idle\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
98.829 %
bladernr@resolute-test:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall("util\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
<string>:1: SyntaxWarning: "\S" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\S"? A raw string is also an option.
0.0 %
bladernr@resolute-test:~$ iostat -x -m 1 10 | python3 -c 'import sys, re; lines="".join(sys.stdin.readlines()); l=[float(n) for n in (re.findall(r"util\n.*?(\S+)\n", lines))]; print(sum(l)/len(l),"%")'
0.0 %

 * for disk_on_idle and cpu_on_idle, fix regex to resolve warning about invalid escape char in newer python3 versions.
   (older Python3 just silently passed it)
 * Also added CLAUDE.md to gitignore to avoid accidentally pulling in Claude instructions when making commits. Fixes #2477
@bladernr bladernr linked an issue Apr 21, 2026 that may be closed by this pull request
1 task
@bladernr bladernr requested review from Copilot and gntzio and removed request for Copilot April 21, 2026 13:53
@bladernr bladernr changed the title (BugFix) fix regex in benchmarks cpu/disk_on_idle Fix regex in benchmarks cpu/disk_on_idle (BugFix) Apr 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Python SyntaxWarning noise in benchmark jobs by making the regex patterns raw strings (so \S is treated as a regex escape rather than an invalid Python string escape), and prevents accidental commits of local Claude instruction files.

Changes:

  • Update benchmarks/system/cpu_on_idle and benchmarks/system/disk_on_idle commands to use raw-string regex patterns in re.findall(...).
  • Add CLAUDE.md to .gitignore.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated no comments.

File Description
providers/base/units/benchmarks/jobs.pxu Uses raw-string regex literals in two benchmark job commands to eliminate invalid-escape warnings on newer Python versions.
.gitignore Ignores CLAUDE.md to avoid committing local tooling instructions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.93%. Comparing base (12822cf) to head (766b01a).
⚠️ Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2487      +/-   ##
==========================================
+ Coverage   58.91%   58.93%   +0.01%     
==========================================
  Files         476      477       +1     
  Lines       48011    48034      +23     
  Branches     8569     8571       +2     
==========================================
+ Hits        28286    28309      +23     
+ Misses      18833    18830       -3     
- Partials      892      895       +3     
Flag Coverage Δ
provider-base 34.19% <100.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread providers/base/units/benchmarks/jobs.pxu Outdated
…pt, add unit tests, and update the job descriptions accordingly
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread providers/base/tests/test_iostat_benchmark.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fernando79513 fernando79513 self-assigned this Apr 27, 2026
@bladernr bladernr requested a review from fernando79513 April 27, 2026 19:03
Copy link
Copy Markdown
Collaborator

@fernando79513 fernando79513 left a comment

Choose a reason for hiding this comment

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

First of all, thanks a lot for taking the time to translate this test to Python. I think it is much clearer what the test is doing now.

I am still not sure what the purpose of running this test is. AFAIK, it's just informative.

I have a couple of concerns with the previous implementation:

  • The "parse_iostat_column" function only seems to work because we are choosing to parse the last value of the row. If we wanted a different column, we would have to rewrite the functionality. At this point is just a "get_idle_value" or "get_util_value"
  • What happens if there is more than one disk on the device? How do we know which disk to check? I tested it locally and I got something like this:
Device            r/s     rMB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wMB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dMB/s   drqm/s  %drqm d_await dareq-sz     f/s f_await  aqu-sz  %util
nvme0n1         42.76      2.47     4.08   8.71    0.12    59.09   19.88      1.41    23.14  53.79    3.09    72.61    0.00      0.00     0.00   0.00    0.00     0.00    0.72    0.35    0.07   0.79
sda              0.00      0.00     0.00   2.16    1.34    23.25    0.00      0.00     0.00  16.67    5.80     4.80    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00
sdb              0.00      0.00     0.00  51.93    2.70    11.19    0.00      0.00     0.00   0.00    0.00     0.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.00

Comment on lines +66 to +68
except subprocess.CalledProcessError as e:
print("ERROR: iostat failed: {}".format(e), file=sys.stderr)
return 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to try/except if you are going to raise the error anyway.

Comment thread .gitignore
Comment on lines +4 to +5

CLAUDE.md
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is already a CLAUDE.md file in checkbox

Suggested change
CLAUDE.md



def parse_iostat_column(output, column):
values = [float(n) for n in re.findall(column + r"\n.*?(\S+)\n", output)]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this regex was here before, but it's only working because the value you are checking is the last one of the table:

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           3.62    0.00    2.46    0.08    0.00   93.84

Also, what happens if there is more than one disk?
You are getting only the value of the first disk displayed on the list:

Device            r/s     rMB/s   rrqm/s  %rrqm r_await rareq-sz     w/s     wMB/s   wrqm/s  %wrqm w_await wareq-sz     d/s     dMB/s   drqm/s  %drqm d_await dareq-sz     f/s f_await  aqu-sz  %util
sda              0.00      0.00     0.00   0.00    0.00     0.00    0.50      0.00     0.25  33.33    4.00     8.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.20
sdb              0.00      0.00     0.00   0.00    0.00     0.00    0.50      0.00     0.25  33.33    4.00     8.00    0.00      0.00     0.00   0.00    0.00     0.00    0.00    0.00    0.00   0.21

Is that the intended behavior?

stderr=subprocess.PIPE,
universal_newlines=True,
check=True,
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you are analyzing the output, it's simpler to use subprocess.check_output

Suggested change
)
result = subprocess.check_output(
["iostat", "-x", "-m", "1", str(args.time)],
universal_newlines=True,
)

Comment on lines +29 to +33
print(
"ERROR: No '{}' values found in iostat output".format(column),
file=sys.stderr,
)
return 1
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just raise a system exit. Don't print and return 1.

)
return 1
print("{:.2f}%".format(sum(values) / len(values)))
return 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No need to return 0

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.

Invalid escape char in benchmarks/system/disk_on_idle and cpu_on_idle

3 participants