Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 524dbcc

Browse files
authored
kibana: fail on error and improve log messages (#3190)
1 parent c2bf88e commit 524dbcc

1 file changed

Lines changed: 31 additions & 26 deletions

File tree

internal/kibana/url_prefixes.go

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"net/url"
1111
"strconv"
1212

13+
log "github.com/sirupsen/logrus"
14+
1315
"github.com/elastic/e2e-testing/internal/shell"
1416
"github.com/elastic/e2e-testing/internal/utils"
15-
log "github.com/sirupsen/logrus"
1617
)
1718

1819
const (
@@ -36,38 +37,42 @@ type Endpoint struct {
3637
// GetKibanaEndpoint - capture kibana environment information for determining endpoint
3738
func GetKibanaEndpoint() *Endpoint {
3839
remoteKibanaHost := shell.GetEnv("KIBANA_URL", "")
39-
if remoteKibanaHost != "" {
40-
remoteKibanaHost = utils.RemoveQuotes(remoteKibanaHost)
41-
u, err := url.Parse(remoteKibanaHost)
42-
if err != nil {
43-
log.WithFields(log.Fields{
44-
"url": remoteKibanaHost,
45-
"error": err,
46-
}).Trace("Could not parse KIBANA_URL, will attempt with original.")
47-
return &Endpoint{
48-
Scheme: "http",
49-
Host: "localhost",
50-
Port: 5601,
51-
}
52-
}
53-
host, port, err := net.SplitHostPort(u.Host)
54-
if err != nil {
55-
log.Fatal("Could not determine host/port from KIBANA_URL")
40+
if remoteKibanaHost == "" {
41+
return &Endpoint{
42+
Scheme: "http",
43+
Host: "localhost",
44+
Port: 5601,
5645
}
57-
kibanaPort, _ := strconv.Atoi(port)
46+
}
47+
48+
remoteKibanaHost = utils.RemoveQuotes(remoteKibanaHost)
49+
u, err := url.Parse(remoteKibanaHost)
50+
if err != nil {
51+
log.WithFields(log.Fields{
52+
"url": remoteKibanaHost,
53+
"error": err,
54+
}).Warn("Could not parse KIBANA_URL, will attempt with original.")
5855
return &Endpoint{
59-
Scheme: u.Scheme,
60-
Host: host,
61-
Port: kibanaPort,
56+
Scheme: "http",
57+
Host: "localhost",
58+
Port: 5601,
6259
}
60+
}
6361

62+
host, port, err := net.SplitHostPort(u.Host)
63+
if err != nil {
64+
log.Fatalf("Could not determine host/port from KIBANA_URL=%s", remoteKibanaHost)
6465
}
65-
return &Endpoint{
66-
Scheme: "http",
67-
Host: "localhost",
68-
Port: 5601,
66+
kibanaPort, err := strconv.Atoi(port)
67+
if err != nil {
68+
log.Fatalf("Could not convert kibana port %q to int", port)
6969
}
7070

71+
return &Endpoint{
72+
Scheme: u.Scheme,
73+
Host: host,
74+
Port: kibanaPort,
75+
}
7176
}
7277

7378
// getBaseURL will pull in the baseurl or an alternative host based on settings

0 commit comments

Comments
 (0)