Skip to content
This repository was archived by the owner on Dec 1, 2018. It is now read-only.

Commit 5ad5c2c

Browse files
committed
fixing elasticsearch and adding tests
1 parent 185b35c commit 5ad5c2c

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

common/elasticsearch/elasticsearch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func CreateElasticSearchService(uri *url.URL) (*ElasticSearchService, error) {
127127
var startupFns []elastic.ClientOptionFunc
128128
if len(opts["nodes"]) > 0 {
129129
startupFns = append(startupFns, elastic.SetURL(opts["nodes"]...))
130-
} else if uri.Opaque != "" {
131-
startupFns = append(startupFns, elastic.SetURL(uri.Opaque))
130+
} else if uri.Scheme != "" && uri.Host != "" {
131+
startupFns = append(startupFns, elastic.SetURL(uri.Scheme+"://"+uri.Host))
132132
} else {
133133
return nil, fmt.Errorf("There is no node assigned for connecting ES cluster")
134134
}

common/elasticsearch/elasticsearch_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,53 @@ func TestCreateElasticSearchServiceForDefaultClusterName(t *testing.T) {
9696
t.Fatalf("cluster name is not equal. Expected: %s, Got: %s", ESClusterName, esSvc.ClusterName)
9797
}
9898
}
99+
100+
func TestCreateElasticSearchServiceSingleDnsEntrypoint(t *testing.T) {
101+
clusterName := "sandbox"
102+
esURI := fmt.Sprintf("https://foo.com:9200?"+
103+
"esUserName=test&esUserSecret=password&maxRetries=10&startupHealthcheckTimeout=30&"+
104+
"sniff=false&healthCheck=false&cluster_name=%s", clusterName)
105+
106+
url, err := url.Parse(esURI)
107+
if err != nil {
108+
t.Fatalf("Error when parsing URL: %s", err.Error())
109+
}
110+
111+
esSvc, err := CreateElasticSearchService(url)
112+
if err != nil {
113+
t.Fatalf("Error when creating config: %s", err.Error())
114+
}
115+
116+
expectedClient, err := elastic.NewClient(
117+
elastic.SetURL("https://foo.com:9200"),
118+
elastic.SetBasicAuth("test", "password"),
119+
elastic.SetMaxRetries(10),
120+
elastic.SetHealthcheckTimeoutStartup(30*time.Second),
121+
elastic.SetSniff(false), elastic.SetHealthcheck(false))
122+
123+
if err != nil {
124+
t.Fatalf("Error when creating client: %s", err.Error())
125+
}
126+
127+
actualClientRefl := reflect.ValueOf(esSvc.EsClient).Elem()
128+
expectedClientRefl := reflect.ValueOf(expectedClient).Elem()
129+
130+
if actualClientRefl.FieldByName("basicAuthUsername").String() != expectedClientRefl.FieldByName("basicAuthUsername").String() {
131+
t.Fatal("basicAuthUsername is not equal")
132+
}
133+
if actualClientRefl.FieldByName("maxRetries").Int() != expectedClientRefl.FieldByName("maxRetries").Int() {
134+
t.Fatal("maxRetries is not equal")
135+
}
136+
if actualClientRefl.FieldByName("healthcheckTimeoutStartup").Int() != expectedClientRefl.FieldByName("healthcheckTimeoutStartup").Int() {
137+
t.Fatal("healthcheckTimeoutStartup is not equal")
138+
}
139+
if actualClientRefl.FieldByName("snifferEnabled").Bool() != expectedClientRefl.FieldByName("snifferEnabled").Bool() {
140+
t.Fatal("snifferEnabled is not equal")
141+
}
142+
if actualClientRefl.FieldByName("healthcheckEnabled").Bool() != expectedClientRefl.FieldByName("healthcheckEnabled").Bool() {
143+
t.Fatal("healthcheckEnabled is not equal")
144+
}
145+
if esSvc.ClusterName != clusterName {
146+
t.Fatal("cluster name is not equal")
147+
}
148+
}

docs/sink-configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ additional node in the cluster. For example:
166166
```
167167
(*) Notice that using the `?nodes` notation will override the `ES_SERVER_URL`
168168

169+
If you run your ElasticSearch cluster behind a loadbalancer (or otherwise do
170+
not want to specify multiple nodes) then you can do the following:
171+
```
172+
--sink=elasticsearch:http://elasticsearch.example.com:9200?sniff=false
173+
```
169174

170175
Besides this, the following options can be set in query string:
171176

0 commit comments

Comments
 (0)