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: benchmark and propagate the status to not to swallow the failure #808

Merged
merged 12 commits into from
Jun 27, 2023

Conversation

jcchavezs
Copy link
Member

@jcchavezs jcchavezs commented Jun 8, 2023

At some point the benchmaks got broken (can't access action logs older than 3 months) but could have been broken for a while.

BenchmarkCSSDecode/test\a\b\f\n\r\t\v\?\'\"\\x00\12\123\1234\12345\123456\ff01\ff5e\_\\x00__string-2         	 5382614	       222.9 ns/op
BenchmarkEscapeSeqDecode/#00-2                                                                               	229572150	         5.227 ns/op
BenchmarkEscapeSeqDecode/hello_world-2                                                                       	217793412	         5.508 ns/op
panic: runtime error: index out of range [44] with length 43

goroutine 460 [running]:
github.com/corazawaf/coraza/v3/internal/transformations.doEscapeSeqDecode({0x5e2241, 0x2b}, 0x0)
	/home/runner/work/coraza/coraza/internal/transformations/escape_seq_decode.go:101 +0x3a7
github.com/corazawaf/coraza/v3/internal/transformations.escapeSeqDecode({0x5e2241, 0x2b})
	/home/runner/work/coraza/coraza/internal/transformations/escape_seq_decode.go:17 +0x58
github.com/corazawaf/coraza/v3/internal/transformations.BenchmarkEscapeSeqDecode.func1(0xc00007c780)
	/home/runner/work/coraza/coraza/internal/transformations/escape_seq_decode_test.go:59 +0x65
testing.(*B).runN(0xc00007c780, 0x1)
	/opt/hostedtoolcache/go/1.20.4/x64/src/testing/benchmark.go:193 +0x[102](https://github.com/corazawaf/coraza/actions/runs/5210566284/jobs/9401796344?pr=808#step:5:103)
testing.(*B).run1.func1()
	/opt/hostedtoolcache/go/1.20.4/x64/src/testing/benchmark.go:233 +0x59
created by testing.(*B).run1
	/opt/hostedtoolcache/go/1.20.4/x64/src/testing/benchmark.go:226 +0x9c
exit status 2
FAIL	github.com/corazawaf/coraza/v3/internal/transformations	24.522s

See https://github.com/corazawaf/coraza/actions/runs/5210566284/jobs/9401796344?pr=808#step:5:97

cc @anuraaga @jptosso as they worked on this mainly

@jcchavezs jcchavezs requested a review from a team as a code owner June 8, 2023 11:16
@codecov
Copy link

codecov bot commented Jun 8, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02 ⚠️

Comparison is base (e1b119b) 81.58% compared to head (0a52de3) 81.57%.

❗ Current head 0a52de3 differs from pull request most recent head 9e9ed45. Consider uploading reports for the commit 9e9ed45 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #808      +/-   ##
==========================================
- Coverage   81.58%   81.57%   -0.02%     
==========================================
  Files         158      158              
  Lines        8966     8959       -7     
==========================================
- Hits         7315     7308       -7     
  Misses       1406     1406              
  Partials      245      245              
Flag Coverage Δ
default 76.56% <100.00%> (+0.30%) ⬆️
examples 25.66% <0.00%> (+0.02%) ⬆️
ftw 47.11% <100.00%> (-0.05%) ⬇️
ftw-multiphase 49.25% <100.00%> (-0.05%) ⬇️
tinygo 72.64% <100.00%> (+0.32%) ⬆️

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

Impacted Files Coverage Δ
internal/transformations/escape_seq_decode.go 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@anuraaga
Copy link
Contributor

anuraaga commented Jun 9, 2023

Always had trouble understanding the escape_seq_decode logic so just refactored it completely, notably continue makes the logic flow easier to follow IMO. Not sure what part of it fixed the bug but looks like it did :P

@anuraaga
Copy link
Contributor

anuraaga commented Jun 9, 2023

@jcchavezs I think you can finish, we should remove the actual performance regression check. GitHub runners machine configuration / busyness varies wildly across runs, it is not possible to do a automated perf check on them without custom runners. So the best we can do is just compute the numbers somewhere as a reference point, that's what I've been doing in wasilibs

https://github.com/wasilibs/go-re2/blob/main/.github/workflows/bench.yaml

@jcchavezs
Copy link
Member Author

Shopuld this be a benchmark or a test?

@anuraaga
Copy link
Contributor

anuraaga commented Jun 9, 2023

Not sure the question, but there should be a benchmark. It may also need to be a normal unit test.

@jcchavezs jcchavezs enabled auto-merge (squash) June 14, 2023 13:44
@fzipi
Copy link
Member

fzipi commented Jun 14, 2023

From the title of this PR I didn't expect the internal/transformations/escape_seq_decode.go to change in this PR. Can we create a new one, just for that change, and write a test if that is a fix?

@jcchavezs jcchavezs changed the title chore: propagates the pipe status after tee. fix: benchmark and propagate the status to not to swallow the failure Jun 14, 2023
@jcchavezs
Copy link
Member Author

The change in the yaml file makes the Ci fail (see commit 95804f3) and then the fix in the code makes this green. I just changed the title, does that look better @fzipi ?

@fzipi
Copy link
Member

fzipi commented Jun 15, 2023

I understand the pipe propagation for fixing the benchmark.

I don't understand why escape_seq_decode needed to change for a benchmark. Was this a bug in the code?

@jcchavezs
Copy link
Member Author

jcchavezs commented Jun 15, 2023 via email

@fzipi
Copy link
Member

fzipi commented Jun 15, 2023

Looks like we are not in sync.

@fzipi
Copy link
Member

fzipi commented Jun 15, 2023

Do we need to add additional tests here

func TestEscapeSeqDecode(t *testing.T) {
?

Looks like we found a bug of some sort, and the failing benchmarks uncovered it. Do we need additional tests?

@jcchavezs jcchavezs disabled auto-merge June 26, 2023 21:46
@jcchavezs
Copy link
Member Author

@fzipi added the test.

@jcchavezs jcchavezs enabled auto-merge (squash) June 27, 2023 08:15
@jcchavezs jcchavezs merged commit 0700bb0 into main Jun 27, 2023
@jcchavezs jcchavezs deleted the makes_benchmarks_fail branch June 27, 2023 08:22
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.

5 participants