Skip to content

Commit

Permalink
x-pack/filebeat/input/{cel,httpjson}: fix flaky test
Browse files Browse the repository at this point in the history
Do not use uncontrolled randomisation in tests where it is not necessary. The
retry tests in the httpjson and cel packages were using a randomised 5xx HTTP
status code to trigger the retry behaviour of the the go-retryablehttp
package. This had the unfortunate consequence of causing 1% of test runs to
fail.

The reason for this is given in the go-retryablehttp documentation[1]:

	Mainly, if an error is returned by the client (connection errors,
	etc.), or if a 500-range response code is received (except 501),
	then a retry is invoked after a wait period.

Since the package is already tested, and is documented to accept all 5xx
status codes except 501 to cause a retry, just use 500.

[1]https://pkg.go.dev/github.com/hashicorp/[email protected]#section-readme
  • Loading branch information
efd6 committed Oct 22, 2024
1 parent 7ca9893 commit c46b21d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Close connections properly in Filbeat's HTTPJSON input. {pull}39790[39790]
- Add the Offset property to libbeat/reader.Message to store the total number of bytes read and discarded before generating the message. This enables inputs to accurately determine how much data has been read up to the message, using Message.Bytes + Message.Offset. {pull}39873[39873] {issue}39653[39653]
- AWS CloudWatch Metrics record previous endTime to use for next collection period and change log.logger from cloudwatch to aws.cloudwatch. {pull}40870[40870]
- Fix flaky test in cel and httpjson inputs of filebeat. {issue}40503[40503] {pull}41358[41358]

==== Added

Expand Down
4 changes: 2 additions & 2 deletions x-pack/filebeat/input/cel/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"flag"
"fmt"
"io"
"math/rand"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -1947,7 +1946,8 @@ func retryHandler() http.HandlerFunc {
w.Write([]byte(`{"hello":"world"}`))
return
}
w.WriteHeader(rand.Intn(100) + 500)
// Any 5xx except 501 will result in a retry.
w.WriteHeader(500)
count++
}
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/filebeat/input/httpjson/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -1724,7 +1723,8 @@ func retryHandler() http.HandlerFunc {
_, _ = w.Write([]byte(`{"hello":"world"}`))
return
}
w.WriteHeader(rand.Intn(100) + 500)
// Any 5xx except 501 will result in a retry.
w.WriteHeader(500)
count += 1
}
}
Expand Down

0 comments on commit c46b21d

Please sign in to comment.