Repository navigation
out_opensearch,in_opensearch: rebuild the client when only the port, scheme or path of a host changes - #202
Merged
Conversation
is_existing_connection compared the port inside the argument of eql? (`a.eql? b || c` parses as `a.eql?(b || c)`), so a host that only changed its port kept the client of the previous one. A host placeholder that expands to the same name on another port sent the chunk to the old port. Compare the whole host hash instead, and keep copies of the hashes because the client normalizes the ones it gets. Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
Watson1978
approved these changes
Nov 10, 2026
Watson1978
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the fix. I checked it locally.
- The four new tests fail on main and pass on this PR. The full test suite passes.
- When a host placeholder expands to the same name on another port, chunks now go to the right port. On main, they all go to the first one.
- When the host settings do not change, the same client is still reused. I tried many setups, including
hostsURLs with a trailing slash,path, credentials, IPv6 and an AWS endpoint.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
is_existing_connection(in bothout_opensearchandin_opensearch) is meant to drop the cached client when the hosts change, but the port check never runs:Without parentheses this parses as
host.eql?(current_host || port_changed), so only the host name is compared. When a host placeholder expands to the same name on another port (for examplehosts ${tag}with tagsos.internal:9200andos.internal:9201), the chunk is sent through the client built for the first port. A change of scheme or path is not detected either.This change compares the whole host hash instead. The client from opensearch-ruby normalizes the hashes it receives (
port.to_i,path.chomp('/')), and@current_configused to share them through a shallowclone, so it now keeps copies to compare against whatget_connection_optionsreturns next time.Tests added:
test_out_opensearch.rb:test_client_is_rebuilt_when_only_a_part_other_than_the_host_name_changes, with port, scheme and path cases. The same host returns the same client, and the changed one returns a new client that points to the new port, scheme or path.test_in_opensearch.rb:test_client_is_rebuilt_when_only_the_port_changes.All four fail on
mainand pass with the change.bundle exec rake test: 464 tests, 0 failures, 1 error. The error istest_out_opensearch_data_stream.rbtest_time_placeholder, which also fails onmainhere: it stubsfoo_<local date>while the plugin asks forfoo_<UTC date>, and they differ near midnight in my time zone.(check all that apply)
versionin gemspec are untouched