Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Kibana Client's Transport and Version #12422

Merged
merged 2 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions libbeat/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type Connection struct {
Username string
Password string

http *http.Client
version common.Version
HTTP *http.Client
Version common.Version
}

type Client struct {
Expand Down Expand Up @@ -134,7 +134,7 @@ func NewClientWithConfig(config *ClientConfig) (*Client, error) {
URL: kibanaURL,
Username: username,
Password: password,
http: &http.Client{
HTTP: &http.Client{
Transport: &http.Transport{
Dial: dialer.Dial,
DialTLS: tlsDialer.Dial,
Expand Down Expand Up @@ -195,7 +195,7 @@ func (conn *Connection) Send(method, extraPath string,
req.Header.Add("Accept", "application/json")
req.Header.Set("kbn-xsrf", "1")
if method != "GET" {
req.Header.Set("kbn-version", conn.version.String())
req.Header.Set("kbn-version", conn.Version.String())
}

for header, values := range headers {
Expand All @@ -209,7 +209,7 @@ func (conn *Connection) Send(method, extraPath string,

// Implements RoundTrip interface
func (conn *Connection) RoundTrip(r *http.Request) (*http.Response, error) {
return conn.http.Do(r)
return conn.HTTP.Do(r)
}

func (client *Client) readVersion() error {
Expand Down Expand Up @@ -253,13 +253,13 @@ func (client *Client) readVersion() error {
return fmt.Errorf("fail to parse kibana version (%v): %+v", versionString, err)
}

client.version = *version
client.Version = *version
return nil
}

// GetVersion returns the version read from kibana. The version is not set if
// IgnoreVersion was set when creating the client.
func (client *Client) GetVersion() common.Version { return client.version }
func (client *Client) GetVersion() common.Version { return client.Version }

func (client *Client) ImportJSON(url string, params url.Values, jsonBody map[string]interface{}) error {

Expand Down
6 changes: 3 additions & 3 deletions libbeat/kibana/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestErrorJson(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil, nil)
assert.Equal(t, http.StatusOK, code)
Expand All @@ -50,7 +50,7 @@ func TestErrorBadJson(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, nil, nil)
assert.Equal(t, http.StatusOK, code)
Expand All @@ -68,7 +68,7 @@ func TestSuccess(t *testing.T) {

conn := Connection{
URL: kibanaTs.URL,
http: http.DefaultClient,
HTTP: http.DefaultClient,
}
code, _, err := conn.Request(http.MethodPost, "", url.Values{}, http.Header{"foo": []string{"bar"}}, nil)
assert.Equal(t, http.StatusOK, code)
Expand Down