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

Support v2 templates in ES indexing calls #17809

Closed
ycombinator opened this issue Apr 17, 2020 · 14 comments
Closed

Support v2 templates in ES indexing calls #17809

ycombinator opened this issue Apr 17, 2020 · 14 comments
Labels

Comments

@ycombinator
Copy link
Contributor

ycombinator commented Apr 17, 2020

Elasticsearch is introducing v2 of index templates. To understand the motivation for this change and it's details, see: elastic/elasticsearch#53101.

In 7.x (once elastic/elasticsearch#55411 is merged), Elasticsearch indexing APIs will accept an optional query string parameter: prefer_v2_templates. In 7.x, the default value for this parameter will be false, indicating that v1 templates should be used. In 8.0, the default value will change to true, indicating that v2 templates should be used.

This issue is to track changes needed in Beats to work with v2 templates. Concretely:

  • For 7.x Beats:

    • If the Beat is operating standalone (i.e. not managed via Fleet + Agent), it is responsible for creating the index template (v1) in Elasticsearch. As such, indexing calls from such Beats should pass prefer_v2_templates=false in indexing requests to Elasticsearch.
    • If the Beat is being managed by Fleet, then the Beat is not responsible for creating the index template in Elasticsearch. It assumes (maybe checks?) the index template has been created before indexing it's events. Further, Fleet will create v2 index templates. So such Beats should pass prefer_v2_templates=true in indexing requests to Elasticsearch.
  • Starting 8.0.0, Beats will use v2 index templates, either ones they create on their own (in standalone mode) or because Fleet created them beforehand. So such Beats should pass prefer_v2_templates=true in indexing requests to Elasticsearch.

Related: #17829

@ycombinator ycombinator changed the title Support v2 templates in ES client bulk API calls Support v2 templates in ES indexing calls Apr 17, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ingest-management (Team:Ingest Management)

@ycombinator ycombinator added Team:Integrations Label for the Integrations team and removed Team:Ingest Management labels Apr 17, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@urso
Copy link

urso commented Apr 20, 2020

If the Beat is operating standalone (i.e. not managed via Fleet + Agent), it is responsible for creating the index template (v1) in Elasticsearch. As such, indexing calls from such Beats should pass prefer_v2_templates=false in indexing requests to Elasticsearch.

In case the generated templates are the same from Beats POV, I would opt to not send a prefer_v2_templates flag at all, no matter which ES version is used. Instead we should only use prefer_v2_templates=true, iff the Beat is managed by Fleet + Elasticsearch is < 8.0. WDYT?

@ycombinator
Copy link
Contributor Author

Agreed on both points, assuming Beats does not need to do any v1->v2 migration work (which seems quite likely to be the case, but will know for sure after #17829) .

@ph
Copy link
Contributor

ph commented Apr 20, 2020

@urso @ycombinator what would be the best way to enable that? Are you planning to have an option in the output that we can just set?

@ycombinator
Copy link
Contributor Author

@ph Yes, that could be one way: an option in the elasticsearch output that Agent can set. We can leave this option undocumented if we don't want end-users to use it. Alternatively, we could add a new class of settings to Beats under a fleet.* namespace if we expect there to be more "internal API" settings that only make sense between Fleet and Beats.

@ph
Copy link
Contributor

ph commented Apr 20, 2020

Good point, I think it depends at how we want to expose this to other use case. If we do not, we could add a new option under management.v2_templates: true or management.fleet.v2_template: true

This seem to be a temporary usage so I would go on the easiest way to implement it.

@ycombinator
Copy link
Contributor Author

This seem to be a temporary usage so I would go on the easiest way to implement it.

Good point — this option will go away at some point, probably 9.0. Easiest would be to make it an option on the ES output (potentially undocumented). So I'm +1 for this unless @urso has a different preference.

@urso
Copy link

urso commented Apr 20, 2020

No real preference :)

We also have a 'private' CLI flag named -environment. We currently use it to decide on defaults in the log output.

In case we really introduce a management or fleet namespace for other things as well, then it might be as simple as enable template v2 support once the namespace is available.

@urso
Copy link

urso commented Apr 24, 2020

Looks like the 'API' to install templates is changing as well:

V1 and V2 have separate APIs:

V1:
GET/PUT/DELETE /_template/<name>

V2:
GET/PUT/DELETE /_component_template/<name>
GET/PUT/DELETE /_index_template/<name>

@ycombinator
Copy link
Contributor Author

@urso Yes, I made the same comment on the related issue: #17829. This issue here is meant just for the indexing part.

@ph
Copy link
Contributor

ph commented May 6, 2020

We have added a workaround in the 7.8/7.x released of the agent.
We uses the params option to the elasticsearch output for that.

ph added a commit to ph/beats that referenced this issue May 6, 2020
To make sure we use the v2 templates we must send on bulk request the
params `prefer_v2_templates=true` if not it will default to v1 and will
not try to use the v2 template at all.

Reference: elastic#17809
ph added a commit that referenced this issue May 7, 2020
#18318)

* [Elastic Agent] Add params `prefer_v2_templates=true` on the ES output

To make sure we use the v2 templates we must send on bulk request the
params `prefer_v2_templates=true` if not it will default to v1 and will
not try to use the v2 template at all.

Reference: #17809

* [Libbeat] Respect the `parameters` option defined in the ES output.

This make sure that any values defined in the `parameters` option of the
ES output is correctly added to every bulk request query string.

Fixes: #18325


* Adding tests

Co-authored-by: Nicolas Ruflin <[email protected]>
@urso
Copy link

urso commented May 12, 2020

The indexing part did become much easier for us (prefer_v2_template parameter has been removed): elastic/elasticsearch#56528

@urso urso closed this as completed May 12, 2020
@zube zube bot added the [zube]: Done label May 12, 2020
@ph
Copy link
Contributor

ph commented May 12, 2020

@urso indeed its much simplier now. thanks for closing this.

blakerouse pushed a commit to blakerouse/beats that referenced this issue May 12, 2020
elastic#18318)

* [Elastic Agent] Add params `prefer_v2_templates=true` on the ES output

To make sure we use the v2 templates we must send on bulk request the
params `prefer_v2_templates=true` if not it will default to v1 and will
not try to use the v2 template at all.

Reference: elastic#17809

* [Libbeat] Respect the `parameters` option defined in the ES output.

This make sure that any values defined in the `parameters` option of the
ES output is correctly added to every bulk request query string.

Fixes: elastic#18325


* Adding tests

Co-authored-by: Nicolas Ruflin <[email protected]>
(cherry picked from commit d152d08)
blakerouse added a commit that referenced this issue May 13, 2020
#18318) (#18464)

* [Elastic Agent] Add params `prefer_v2_templates=true` on the ES output

To make sure we use the v2 templates we must send on bulk request the
params `prefer_v2_templates=true` if not it will default to v1 and will
not try to use the v2 template at all.

Reference: #17809

* [Libbeat] Respect the `parameters` option defined in the ES output.

This make sure that any values defined in the `parameters` option of the
ES output is correctly added to every bulk request query string.

Fixes: #18325


* Adding tests

Co-authored-by: Nicolas Ruflin <[email protected]>
(cherry picked from commit d152d08)

Co-authored-by: Pier-Hugues Pellerin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants