Skip to content

Use JSON serialization for DLQ error messages instead of Ruby object inspection#1251

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/sub-pr-1250
Draft

Use JSON serialization for DLQ error messages instead of Ruby object inspection#1251
Copilot wants to merge 5 commits intomainfrom
copilot/sub-pr-1250

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 20, 2026

The DLQ error message in handle_dlq_response used Ruby's to_s on hashes, which changed format between JRuby 9 ("key"=>"value") and JRuby 10 ("key": "value"), causing brittle regex-based test assertions.

Changes

  • lib/logstash/plugin_mixins/elasticsearch/common.rb: Replace string interpolation of action_params and response with LogStash::Json.dump(...), producing stable JSON output across JRuby versions:

    # Before
    detailed_message = "#{message} status: #{status}, action: #{action_params}, response: #{response}"
    # After
    detailed_message = "#{message} status: #{status}, action: #{LogStash::Json.dump(action_params)}, response: #{LogStash::Json.dump(response)}"
  • spec/unit/outputs/elasticsearch_spec.rb: Replace the version-sensitive regex with straightforward include assertions on JSON key-value pairs:

    # Before — fragile, handles JRuby 9/10 differences
    expect(reason).to match /_id(?::| ?=>) ?"bar".*"foo" ?=> ?"bar".*response:.*"reason" ?=> ?"TEST"/
    # After — simple, format-agnostic
    expect(reason).to include '"_id":"bar"'
    expect(reason).to include '"foo":"bar"'
    expect(reason).to include '"reason":"TEST"'

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Replace Ruby's to_s representation with LogStash::Json.dump for
action_params and response in handle_dlq_response, producing consistent
JSON output across JRuby 9 and 10. Update tests to use simple include
assertions on JSON key-value pairs instead of complex version-sensitive
regexes.

Co-authored-by: jsvd <31809+jsvd@users.noreply.github.com>
Copilot AI changed the title [WIP] Update regex for reason matching in Elasticsearch spec to support JRuby 10 Use JSON serialization for DLQ error messages instead of Ruby object inspection Mar 20, 2026
Copilot AI requested a review from jsvd March 20, 2026 16:21
Copilot finished work on behalf of jsvd March 20, 2026 16:21
@elasticmachine
Copy link
Copy Markdown

💚 Build Succeeded

History

cc @jsvd @Copilot

Base automatically changed from jsvd-patch-1 to main March 27, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants