mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 22:28:25 +00:00
chore: improve /healthz endpoint performance (#2014)
* Add benchmark for /healthz endpoint This benchmark will measure not only speed but also how much memory each request to /healthz allocate. I'm adding the benchmark to have a baseline to compare. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Hardcode /healthz body into a variable We know it will always be this value, there's no need to import and call json.MarshalIndent. Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com> * Initialize /healthz body only once Signed-off-by: Leandro López (inkel) <inkel.ar@gmail.com>
This commit is contained in:
@@ -147,6 +147,25 @@ func TestHealthz(t *testing.T) {
|
||||
}`, string(body))
|
||||
}
|
||||
|
||||
type mockRW struct{}
|
||||
|
||||
var _ http.ResponseWriter = mockRW{}
|
||||
var mh = http.Header{}
|
||||
|
||||
func (w mockRW) WriteHeader(int) {}
|
||||
func (w mockRW) Write([]byte) (int, error) { return 0, nil }
|
||||
func (w mockRW) Header() http.Header { return mh }
|
||||
|
||||
var w = mockRW{}
|
||||
var s = &server.Server{}
|
||||
|
||||
func BenchmarkHealthz(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
s.Healthz(w, nil)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseAtlantisURL(t *testing.T) {
|
||||
cases := []struct {
|
||||
In string
|
||||
|
||||
Reference in New Issue
Block a user