Skip to content

Commit b9617bb

Browse files
committed
fix bug
Signed-off-by: Achref Ben Saad <achref@accuknox.com>
1 parent 9a65100 commit b9617bb

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

relay-server/elasticsearch/adapter.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ type ElasticsearchClient struct {
4343
// It then creates a new NewBulkIndexer with the esClient
4444
func NewElasticsearchClient(esURL string, esUser string, esPassword string, esCaCertPath string, esAllowInsecureTLS bool) (*ElasticsearchClient, error) {
4545

46-
caCertBytes := []byte{}
47-
if esCaCertPath != "" {
48-
var err error
49-
caCertBytes, err = os.ReadFile(esCaCertPath)
50-
if err != nil {
51-
return nil, fmt.Errorf("failed to open Elasticsearch CA file: %v", err)
52-
}
53-
}
5446
retryBackoff := backoff.NewExponentialBackOff()
5547
cfg := elasticsearch.Config{
5648
Addresses: []string{esURL},
@@ -71,7 +63,14 @@ func NewElasticsearchClient(esURL string, esUser string, esPassword string, esCa
7163
InsecureSkipVerify: esAllowInsecureTLS,
7264
},
7365
},
74-
CACert: caCertBytes,
66+
}
67+
68+
if esCaCertPath != "" {
69+
caCertBytes, err := os.ReadFile(esCaCertPath)
70+
if err != nil {
71+
return nil, fmt.Errorf("failed to open Elasticsearch CA file: %v", err)
72+
}
73+
cfg.CACert = caCertBytes
7574
}
7675

7776
if len(esUser) != 0 && len(esPassword) != 0 {
@@ -86,10 +85,13 @@ func NewElasticsearchClient(esURL string, esUser string, esPassword string, esCa
8685
bi, err := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
8786
Client: esClient, // The Elasticsearch client
8887
FlushBytes: 1000000, // The flush threshold in bytes [1mb]
89-
FlushInterval: 30 * time.Second, // The periodic flush interval [30 secs]
88+
FlushInterval: 10 * time.Second, // The periodic flush interval [30 secs]
89+
OnError: func(ctx context.Context, err error) {
90+
log.Fatalf("Error creating the indexer: %v", err)
91+
},
9092
})
9193
if err != nil {
92-
log.Fatalf("Error creating the indexer: %s", err)
94+
log.Fatalf("Error creating the indexer: %v", err)
9395
}
9496
alertCh := make(chan interface{}, 10000)
9597
return &ElasticsearchClient{bulkIndexer: bi, esClient: esClient, alertCh: alertCh}, nil

relay-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func main() {
9797
if enableEsDashboards == "true" {
9898
esCl, err := elasticsearch.NewElasticsearchClient(esUrl, esUser, esPassword, esCaCertPath, esAllowInsecureTLS)
9999
if err != nil {
100-
kg.Warnf("Failed to start a Elasticsearch Client")
100+
kg.Warnf("Failed to start a Elasticsearch Client, %v", err)
101101
return
102102
}
103103
relayServer.ELKClient = esCl

0 commit comments

Comments
 (0)