Skip to content

Commit

Permalink
Fixed #678
Browse files Browse the repository at this point in the history
Signed-off-by: Chun Lin Yang <[email protected]>
  • Loading branch information
clyang82 committed Oct 25, 2018
1 parent 864fcdd commit fc9d180
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"log"
"net/http"
"sync"
"time"

"github.com/pkg/errors"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"
elastic "gopkg.in/olivere/elastic.v5"
"gopkg.in/olivere/elastic.v5"

"github.com/jaegertracing/jaeger/pkg/es"
storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics"
Expand Down Expand Up @@ -205,9 +203,9 @@ func (c *Configuration) GetTagDotReplacement() string {

// GetConfigs wraps the configs to feed to the ElasticSearch client init
func (c *Configuration) GetConfigs(logger *zap.Logger) []elastic.ClientOptionFunc {

options := make([]elastic.ClientOptionFunc, 3)
if c.TLS.Enabled {
tlsConfig, err := c.CreateTLSConfig()
tlsConfig, err := c.CreateTLSConfig(logger)
if err != nil {
return nil
}
Expand All @@ -217,45 +215,27 @@ func (c *Configuration) GetConfigs(logger *zap.Logger) []elastic.ClientOptionFun
TLSClientConfig: tlsConfig,
},
}

resp, err := httpClient.Get("https://elasticsearch:9200")
if err != nil {
fmt.Println(err)
}

htmlData, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
fmt.Printf("%v\n", resp.Status)
fmt.Printf(string(htmlData))

options := make([]elastic.ClientOptionFunc, 4)
options[0] = elastic.SetHttpClient(httpClient)
options[1] = elastic.SetURL(c.Servers...)
options[2] = elastic.SetSniff(c.Sniffer)
options[3] = elastic.SetScheme("https")
logger.Info("tlsConfig", zap.Any("tlsConfig", tlsConfig))
return options
}
options := make([]elastic.ClientOptionFunc, 3)
options[0] = elastic.SetURL(c.Servers...)
options[1] = elastic.SetBasicAuth(c.Username, c.Password)
options[2] = elastic.SetSniff(c.Sniffer)
return options
}

// CreateTLSConfig creates TLS Configuration to connect with ES Cluster.
func (c *Configuration) CreateTLSConfig() (*tls.Config, error) {
func (c *Configuration) CreateTLSConfig(logger *zap.Logger) (*tls.Config, error) {
rootCerts, err := c.LoadCertificatesFrom()
if err != nil {
log.Fatalf("Couldn't load root certificate from %s. Got %s.", c.TLS.CaPath, err)
logger.Fatal("Couldn't load root certificate", zap.Error(err))
}
if len(c.TLS.CertPath) > 0 && len(c.TLS.KeyPath) > 0 {
clientPrivateKey, err := c.LoadPrivateKeyFrom()
if err != nil {
log.Fatalf("Couldn't setup client authentication. Got %s.", err)
logger.Fatal("Couldn't setup client authentication", zap.Error(err))
}
return &tls.Config{
RootCAs: rootCerts,
Expand Down

0 comments on commit fc9d180

Please sign in to comment.