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

update elastic client in index server #349

Closed
wants to merge 1 commit into from
Closed
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
46 changes: 9 additions & 37 deletions src/cloud/indexer/indexer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
package main

import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net/http"
_ "net/http/pprof"

Expand All @@ -36,6 +32,7 @@ import (

"px.dev/pixie/src/cloud/indexer/controllers"
"px.dev/pixie/src/cloud/indexer/md"
"px.dev/pixie/src/cloud/shared/esutils"
"px.dev/pixie/src/cloud/vzmgr/vzmgrpb"
"px.dev/pixie/src/shared/services"
"px.dev/pixie/src/shared/services/env"
Expand Down Expand Up @@ -67,41 +64,16 @@ func newVZMgrClient() (vzmgrpb.VZMgrServiceClient, error) {
return vzmgrpb.NewVZMgrServiceClient(vzmgrChannel), nil
}

func getESHTTPSClient() (*http.Client, error) {
caFile := viper.GetString("es_ca_cert")
caCert, err := ioutil.ReadFile(caFile)
if err != nil {
return nil, err
}
caCertPool := x509.NewCertPool()
ok := caCertPool.AppendCertsFromPEM(caCert)
if !ok {
return nil, fmt.Errorf("failed to append caCert to pool")
}
tlsConfig := &tls.Config{
RootCAs: caCertPool,
}
tlsConfig.BuildNameToCertificate()
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
httpClient := &http.Client{
Transport: transport,
}
return httpClient, nil
}

func mustConnectElastic() *elastic.Client {
esURL := viper.GetString("es_url")
httpClient, err := getESHTTPSClient()
if err != nil {
log.WithError(err).Fatal("Failed to create HTTPS client")
}
es, err := elastic.NewClient(elastic.SetURL(esURL),
elastic.SetHttpClient(httpClient),
elastic.SetBasicAuth(viper.GetString("es_user"), viper.GetString("es_passwd")),
// Sniffing seems to be broken with TLS, don't turn this on unless you want pain.
elastic.SetSniff(false))

es, err := esutils.NewEsClient(&esutils.Config{
URL: []string{esURL},
User: viper.GetString("es_user"),
Passwd: viper.GetString("es_passwd"),
CaCertFile: viper.GetString("es_ca_cert"),
})

if err != nil {
log.WithError(err).Fatalf("Failed to connect to elastic at url: %s", esURL)
}
Expand Down