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

[Ingest Manager] When not port are specified and the https is used fallback to 443 #18844

Merged
merged 4 commits into from
May 29, 2020
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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@
- More clear output of inspect command {pull}18405[18405]
- Pick up version from libbeat {pull}18350[18350]
- Use shorter hash for application differentiator {pull}18770[18770]
- When not port are specified and the https is used fallback to 443 {pull}18844[18844]
12 changes: 10 additions & 2 deletions x-pack/elastic-agent/pkg/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
)

const kibanaPort = 5601
const (
kibanaPort = 5601
kibanaHTTPSPort = 443
)

type requestFunc func(string, string, url.Values, io.Reader) (*http.Request, error)
type wrapperFunc func(rt http.RoundTripper) (http.RoundTripper, error)
Expand Down Expand Up @@ -144,7 +147,12 @@ func NewWithConfig(log *logger.Logger, cfg *Config, wrapper wrapperFunc) (*Clien
p = p + "/"
}

kibanaURL, err := common.MakeURL(string(cfg.Protocol), p, cfg.Host, kibanaPort)
usedDefaultPort := kibanaPort
if cfg.Protocol == "https" {
usedDefaultPort = kibanaHTTPSPort
}

kibanaURL, err := common.MakeURL(string(cfg.Protocol), p, cfg.Host, usedDefaultPort)
if err != nil {
return nil, errors.Wrap(err, "invalid Kibana endpoint")
}
Expand Down
34 changes: 34 additions & 0 deletions x-pack/elastic-agent/pkg/kibana/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io/ioutil"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"

Expand All @@ -32,6 +33,39 @@ func addCatchAll(mux *http.ServeMux, t *testing.T) *http.ServeMux {
return mux
}

func TestPortDefaults(t *testing.T) {
l, err := logger.New()
require.NoError(t, err)

testCases := []struct {
Name string
URI string
ExpectedPort int
ExpectedScheme string
}{
{"no scheme uri", "test.url", kibanaPort, "http"},
{"default kibana port", "http://test.url", kibanaPort, "http"},
{"specified kibana port", "http://test.url:123", 123, "http"},
{"default kibana https port", "https://test.url", kibanaHTTPSPort, "https"},
{"specified kibana https port", "https://test.url:123", 123, "https"},
}
for _, tc := range testCases {
t.Run(tc.Name, func(t *testing.T) {
cfg, err := NewConfigFromURL(tc.URI)
require.NoError(t, err)

c, err := NewWithConfig(l, cfg, nil)
require.NoError(t, err)

r, err := c.request("GET", "/", nil, strings.NewReader(""))
require.NoError(t, err)

assert.True(t, strings.HasSuffix(r.Host, fmt.Sprintf(":%d", tc.ExpectedPort)))
assert.Equal(t, tc.ExpectedScheme, r.URL.Scheme)
})
}
}

// - Prefix.
func TestHTTPClient(t *testing.T) {
ctx := context.Background()
Expand Down