-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix Elasticsearch version in ES OTEL writer #2409
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,9 @@ type ElasticsearchClient interface { | |
Search(ctx context.Context, query SearchBody, size int, indices ...string) (*SearchResponse, error) | ||
// MultiSearch searches data via /_msearch | ||
MultiSearch(ctx context.Context, queries []SearchBody) (*MultiSearchResponse, error) | ||
|
||
// Major version returns major ES version | ||
MajorVersion() int | ||
} | ||
|
||
// BulkResponse is a response returned by Elasticsearch Bulk API | ||
|
@@ -172,20 +175,20 @@ func NewElasticsearchClient(params config.Configuration, logger *zap.Logger) (El | |
if err != nil { | ||
return nil, err | ||
} | ||
if params.GetVersion() == 0 { | ||
esVersion := int(params.GetVersion()) | ||
if esVersion == 0 { | ||
esPing := elasticsearchPing{ | ||
username: params.Username, | ||
password: params.Password, | ||
roundTripper: roundTripper, | ||
} | ||
esVersion, err := esPing.getVersion(params.Servers[0]) | ||
esVersion, err = esPing.getVersion(params.Servers[0]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
logger.Info("Elasticsearch detected", zap.Int("version", esVersion)) | ||
params.Version = uint(esVersion) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ES version is derived here in the client factory method and assigned to the config. However the config is passed by value, hence the changes are not reflected after this function. Then the wrong value of the version was used by the called to create index template. Instead of overriding the config it is cleaner to expose the version on the client. |
||
} | ||
return newElasticsearchClient(int(params.Version), clientConfig{ | ||
return newElasticsearchClient(esVersion, clientConfig{ | ||
DiscoverNotesOnStartup: params.Sniffer, | ||
Addresses: params.Servers, | ||
Username: params.Username, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to check length of
.Servers
before dereferencing? It does appear that right now it's impossible to pass Servers with length 0 into this method, but the code that prevents that is fairly distant from this.Might be better if this method protects itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 I am will submit a follow-up PR to fix that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2411