Skip to content

Commit

Permalink
Add SendWithContext method to Kibana client. (elastic#16515) (elastic…
Browse files Browse the repository at this point in the history
…#16542)

This allows passing in context for http requests made to Kibana.
Requirement for elastic/apm-server#3185
  • Loading branch information
simitt authored Feb 25, 2020
1 parent 29f87aa commit 7ab6d23
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion libbeat/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package kibana

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand Down Expand Up @@ -181,9 +182,16 @@ func (conn *Connection) Request(method, extraPath string,
func (conn *Connection) Send(method, extraPath string,
params url.Values, headers http.Header, body io.Reader) (*http.Response, error) {

return conn.SendWithContext(context.Background(), method, extraPath, params, headers, body)
}

// SendWithContext sends an application/json request to Kibana with appropriate kbn headers and the given context.
func (conn *Connection) SendWithContext(ctx context.Context, method, extraPath string,
params url.Values, headers http.Header, body io.Reader) (*http.Response, error) {

reqURL := addToURL(conn.URL, extraPath, params)

req, err := http.NewRequest(method, reqURL, body)
req, err := http.NewRequestWithContext(ctx, method, reqURL, body)
if err != nil {
return nil, fmt.Errorf("fail to create the HTTP %s request: %+v", method, err)
}
Expand Down

0 comments on commit 7ab6d23

Please sign in to comment.