Skip to content
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

feat: add include_source_on_error param to bulk index requests #229

Merged
merged 21 commits into from
Mar 12, 2025

Conversation

kruskall
Copy link
Member

❓ Why is this being changed

At the moment ES might return the source a request in the error response. Set the parameter to avoid the fragile parsing logic and make bulk request handling more robust.

🧑‍💻 What is being changed

Set IncludeSourceOnError to false

✅ How to validate the change

unfortunately this can only be validate manually since it relies on an ES feature

@elastic-observability-automation elastic-observability-automation bot added the safe-to-test Automated label for running bench-diff on forked PRs label Jan 30, 2025
@kruskall kruskall marked this pull request as ready for review February 27, 2025 17:35
@kruskall kruskall requested a review from a team as a code owner February 27, 2025 17:35
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: how does this interact with ES 8.x? Should we make this behavior in docappender either configurable, or maintain 2 docappender major versions for 8.x or 9.x ES separately?

@kruskall
Copy link
Member Author

kruskall commented Mar 3, 2025

Q: how does this interact with ES 8.x

The elastictransport doesn't include the ES api so it's not tied to an ES/api version.
The include_source_on_error was backported to 8.x so the lib should be updated in both versions.

@kruskall kruskall requested review from carsonip and a team March 4, 2025 12:59
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might present a problem with backward compatibility, as this code change introduces version dependency on ES, which may not be feasible for elasticsearchexporter.

A path forward may be to make this behavior configurable, to allow es exporter to opt out of this and use the manual sanaitization code path.

bulk_indexer.go Outdated
v := req.URL.Query()
if b.config.Pipeline != "" {
v.Set("pipeline", b.config.Pipeline)
}
if b.config.RequireDataStream {
v.Set("require_data_stream", strconv.FormatBool(b.config.RequireDataStream))
}
v.Set("filter_path", "items.*._index,items.*.status,items.*.failure_store,items.*.error.type,items.*.error.reason")
v.Set("filter_path", strings.Join([]string{"items.*._index", "items.*.status", "items.*.failure_store", "items.*.error.type", "items.*.error.reason"}, ","))
v.Set("include_source_on_error", "false")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: what happens when this is passed to a ES <8.18? If it will fail the request, doesn't it mean that elasticsearch exporter cannot bump docappender, as es exporter doesn't have strict dependency on ES version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it gives HTTP 400

POST /_bulk?include_source_on_error=true
{"create":{"_index":"logs-foo-bar"}}
{"@timestamp":"1", "foo":"bar"}
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "request [/_bulk] contains unrecognized parameter: [include_source_on_error]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "request [/_bulk] contains unrecognized parameter: [include_source_on_error]"
  },
  "status": 400
}

Copy link
Member

@1pkg 1pkg Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Carson on this, there is a wider question about backward compatibility guarantees that we provide in this library. Since we version it independently from the stack version, do we need to always preserve backward compatibility with ES? could we break it with a major version bump?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A path forward may be to make this behavior configurable, to allow es exporter to opt out of this and use the manual sanaitization code path.

You are raising an important point here @carsonip . While we could just bump to a major version after adding the change, it would make it much harder to use it and upgrade to the latest version downstream.
Making it configurable sounds like the right direction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kruskall has already agreed on making this configurable in another discussion. The remaining bit will be whether to

  1. keep the old sanitization logic in docappender; or
  2. remove that logic and offload that to users (e.g. es exporter) requiring extra ES compatibility

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enum sgtm. If we're exposing these under docappender package, users will be calling it docappender.True which is a bit strange. What about IncludeSourceTrue, IncludeSourceFalse, IncludeSourceTrueSanitize?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the introduction of include_source_on_error conflict with backward compatibility regardless? In #229 (comment) @carsonip confirmed that older ES version will reject a request with include_source_on_error option. So even if we go with 3 state configuration option for include_source_on_error either with *bool or enum, users will still have to know somehow to not use anything but the default value of this option when they target older ES.

Copy link
Member

@carsonip carsonip Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As stated in the config comment, both True and False requires 8.18+. It'll be fine in apm server, if apm server <8.18 doesn't bump docappender. In es exporter we'll stick with Unset for a while. What kind of backward compatibility are you referring to here?

https://github.com/elastic/go-docappender/pull/229/files#diff-c7cec697c2474f331487a79c052f6150eca5c9a2162a74094df972d831e8223aR98

// Requires Elasticsearch 8.18+ if value is True or False.

Copy link
Member

@1pkg 1pkg Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worry here is that for an external library user it might be hard to discover this note, so in a hypothetical situation when someone updates this library and sets the flag with a good intention they will end up with a broken client.

I understand that setting safe default make it safe from backward compatibility perspective, but it kind of makes it more easy to misuse and claim that the library is not backward compatibility.

But regardless it's a minor concern and more a hypothetical situation, so I don't have any strong objection against either of options that were discussed.

Copy link
Member Author

@kruskall kruskall Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for raising the concern!
The backward compatibility guarantee is only for default options. I see your point but IMO we found the right balance by adding an option that require a more recent version of ES (along with proper documentation). Happy to discuss this more if you want 🙂

@kruskall kruskall requested a review from carsonip March 6, 2025 18:20
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 pending question on strings.Join.

If we release this, imo we should bump the major version as we now require ES 8.18 by default.

@kruskall kruskall requested review from carsonip and simitt March 10, 2025 16:52
@kruskall kruskall requested a review from carsonip March 10, 2025 21:23
carsonip
carsonip previously approved these changes Mar 11, 2025
Copy link
Member

@carsonip carsonip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm, some nits

@@ -843,9 +846,9 @@ func TestAppenderIndexFailedLogging(t *testing.T) {
require.Len(t, entries, N/2)
assert.Equal(t, "failed to index documents in 'an_index' (document_parsing_exception): ", entries[0].Message)
assert.Equal(t, int64(2), entries[0].Context[0].Integer)
assert.Equal(t, "failed to index documents in 'an_index' (error_type): error_reason_even", entries[1].Message)
assert.Equal(t, "failed to index documents in 'an_index' (error_type): ", entries[1].Message)
Copy link
Member

@carsonip carsonip Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @simitt the fact that we now wipe the reason entirely means that when include_source_on_error is Unset, we'll have very little info to debug with. I'm fine with it but it will make #236 more important for Unset usages like es exporter

@kruskall kruskall requested a review from carsonip March 11, 2025 17:08
carsonip
carsonip previously approved these changes Mar 11, 2025
Co-authored-by: Carson Ip <[email protected]>
@kruskall kruskall merged commit 13e4776 into elastic:main Mar 12, 2025
5 checks passed
@kruskall kruskall deleted the feat/disable-include-source branch March 12, 2025 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe-to-test Automated label for running bench-diff on forked PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants