Fix enroll request retry in osquery-perf (#18227)
This was discovered by @xpkoala while performing a load test for the calendar backoff feature. Some enroll requests were failing due to enrolling hosts too fast (`-var loadtest_containers` from `0` to `40` at once), and osquery-perf had a bug in the enroll request where the `bytes.Buffer` was being incorrectly reused thus sending an empty body on the enroll retries, getting 400s from Fleet due to `Expected JSON Body`: ``` 2024/04/11 18:57:49 request failed: 400 ```
This commit is contained in:
@@ -1275,13 +1275,11 @@ func (a *agent) enroll(i int, onlyAlreadyEnrolled bool) error {
|
||||
return errors.New("not enrolled")
|
||||
}
|
||||
|
||||
var body bytes.Buffer
|
||||
if err := a.templates.ExecuteTemplate(&body, "enroll", a); err != nil {
|
||||
log.Println("execute template:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
response := a.waitingDo(func() *http.Request {
|
||||
var body bytes.Buffer
|
||||
if err := a.templates.ExecuteTemplate(&body, "enroll", a); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
request, err := http.NewRequest("POST", a.serverAddress+"/api/osquery/enroll", &body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user