Skip to content

Commit

Permalink
k6runner: send NotAfter hint
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe authored and Nadia Santalla committed Sep 30, 2024
1 parent c81834b commit f56de6b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/k6runner/k6runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ func (r requestError) Error() string {
return fmt.Sprintf("%s: %s", r.Err, r.Message)
}

// HTTPRunRequest
type HTTPRunRequest struct {
Script Script `json:",inline"`
NotAfter time.Time `json:"notAfter"`
}

type RunResponse struct {
Error string `json:"error,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
Expand Down Expand Up @@ -449,7 +455,17 @@ func (r HttpRunner) request(ctx context.Context, script Script) (*RunResponse, e
ctx, cancel := context.WithDeadline(ctx, notAfter)
defer cancel()

reqBody, err := json.Marshal(script)
// Decorate the script request with the NotAfter hint.
// NotAfter hints runners when we're about to drop this request. Runners will refuse to start to run a script if
// this time is in the past, as it is guaranteed that we, the client, have already given up on the request.
// This allows runners to not waste time running scripts which will not complete before the client gives up on the
// request.
runRequest := HTTPRunRequest{
Script: script,
NotAfter: notAfter,
}

reqBody, err := json.Marshal(runRequest)
if err != nil {
return nil, fmt.Errorf("encoding script: %w", err)
}
Expand Down

0 comments on commit f56de6b

Please sign in to comment.