-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test for timeout and 429 on startup
- Loading branch information
1 parent
fd05c91
commit 3201150
Showing
3 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"io" | ||
"net" | ||
"net/http" | ||
"sync/atomic" | ||
"testing" | ||
) | ||
|
||
type statusProxy struct { | ||
t testing.TB | ||
enabled *atomic.Bool | ||
status int | ||
} | ||
|
||
// Create a new Status Proxy | ||
// If the proxy is enabled, the passed status is returned for all requiests | ||
// If it's disabled requests are made to upstream instead. | ||
func NewStatusProxy(t testing.TB, status int) *statusProxy { | ||
t.Helper() | ||
s := &statusProxy{ | ||
t: t, | ||
enabled: new(atomic.Bool), | ||
status: status, | ||
} | ||
return s | ||
} | ||
|
||
func (s *statusProxy) Enable() { | ||
s.enabled.Store(true) | ||
} | ||
|
||
func (s *statusProxy) Disable() { | ||
s.enabled.Store(false) | ||
} | ||
|
||
func (s *statusProxy) ServeHTTP(wr http.ResponseWriter, req *http.Request) { | ||
if s.enabled.Load() { | ||
wr.WriteHeader(s.status) | ||
return | ||
} | ||
req.RequestURI = "" | ||
|
||
if cIP, _, err := net.SplitHostPort(req.RemoteAddr); err == nil { | ||
req.Header.Set("X-Forwarded-For", cIP) | ||
} | ||
|
||
resp, err := (&http.Client{}).Do(req) | ||
if err != nil { | ||
if errors.Is(err, context.Canceled) { | ||
return | ||
} | ||
s.t.Fatal(err) | ||
return | ||
} | ||
defer resp.Body.Close() | ||
for name, values := range resp.Header { | ||
for _, value := range values { | ||
wr.Header().Add(name, value) | ||
} | ||
} | ||
wr.WriteHeader(resp.StatusCode) | ||
io.Copy(wr, resp.Body) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
output: | ||
elasticsearch: | ||
hosts: {{ .Hosts }} | ||
service_token: {{ .ServiceToken }} | ||
proxy_url: {{ .Proxy }} | ||
|
||
fleet.agent.id: e2e-test-id | ||
|
||
inputs: | ||
- type: fleet-server | ||
|
||
logging: | ||
to_stderr: true |