Skip to content
Open
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
15 changes: 14 additions & 1 deletion internal/storage/elasticsearch/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,23 @@ func NewClient(ctx context.Context, c *Configuration, logger *zap.Logger, metric

if c.Version == 0 {
// Determine ElasticSearch Version
pingResult, _, err := rawClient.Ping(c.Servers[0]).Do(ctx)
pingResult, pingStatus, err := rawClient.Ping(c.Servers[0]).Do(ctx)
if err != nil {
return nil, err
}

// Non-2xx responses aren't reported as errors by the ping code (7.0.32 version of
// the elastic client).
if pingStatus < 200 || pingStatus >= 300 {
return nil, fmt.Errorf("ElasticSearch server %s returned HTTP %d, expected 2xx", c.Servers[0], pingStatus)
}

// The deserialization in the ping implementation may succeed even if the response
// contains no relevant properties and we may get empty values in that case.
if len(pingResult.Version.Number) == 0 {
return nil, fmt.Errorf("ElasticSearch server %s returned invalid ping response", c.Servers[0])
}

esVersion, err := strconv.Atoi(string(pingResult.Version.Number[0]))
if err != nil {
return nil, err
Expand Down
Loading