Use config string for elasticsearch client

This commit is contained in:
Mak Muftic 2021-09-16 12:15:42 +02:00
parent 5cbd2519da
commit c25a5e06cf
2 changed files with 18 additions and 3 deletions

View File

@ -376,7 +376,9 @@ func GossipSub(in GossipIn) (service *pubsub.PubSub, err error) {
transports = append(transports, jsonTransport)
}
if in.Cfg.ElasticSearchTracer != "" {
elasticSearchTransport, err := tracer.NewElasticSearchTransport()
elasticSearchTransport, err := tracer.NewElasticSearchTransport(
in.Cfg.ElasticSearchTracer,
)
if err != nil {
return nil, err
}

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/url"
"strings"
"github.com/elastic/go-elasticsearch/v7"
@ -17,8 +18,20 @@ const (
ElasticSearch_DOC_PUBSUB = "doc_pubsub"
)
func NewElasticSearchTransport() (TracerTransport, error) {
es, err := elasticsearch.NewDefaultClient()
func NewElasticSearchTransport(connectionString string) (TracerTransport, error) {
conUrl, err := url.Parse(connectionString)
username := conUrl.User.Username()
password, _ := conUrl.User.Password()
cfg := elasticsearch.Config{
Addresses: []string{
"https://" + conUrl.Host,
},
Username: username,
Password: password,
}
es, err := elasticsearch.NewClient(cfg)
if err != nil {
return nil, err