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

Refactor index management #10347

Merged
merged 57 commits into from
Jan 31, 2019
Merged

Refactor index management #10347

merged 57 commits into from
Jan 31, 2019

Conversation

urso
Copy link

@urso urso commented Jan 26, 2019

Changes:

  • introduce Index + ILM manager interfaces responsible for:
    • create ILM policy
    • create write alias
    • create and load template
    • separate interfaces for re-use: manager, apihandler
    • provide default API handler for elasticsearch.Client
  • Index + ILM support interfaces, that can be swapped out with custom implementation (still WIP)
    • Beat implementing custom managers have to decide on config file format
  • ILM settings have been moved to ilm.setup
  • Introduce setup.ilm.enabled: auto (new default)
    • Index manager will detect on connect to Elasticsearch if ILM can be enabled or not
    • Lazily chooses write alias or old-style index for publishing
    • Index Manager does not check ILM availabilty on startup, but on first connect (so to not block beats startup)
    • If Elasticsearch < 7.0, then auto defaults to false
    • If Elasticsearch > 7.0, then auto checks if ILM is available and enbaled
    • If setup.ilm.enabled: true, then fail check if version does not support ILM or ILM is disabled
  • Publisher pipeline does not use output package anymore to create an output, but a callback -> Beat instance itself creates output instances, passing IndexManager and other info to the output loader.
  • Outputs can use IndexManager in order to create the per event index selector
  • remove fragile manipulation of common.Config objects, that have been already partially parsed.
  • Ensure ILM can be setup if setup.ilm.enabled: true, but elasticsearch output is configured via Central Management

Followup: update docs

@urso urso requested a review from a team as a code owner January 26, 2019 01:33
libbeat/publisher/pipeline/pipeline.go Show resolved Hide resolved
libbeat/publisher/pipeline/module.go Show resolved Hide resolved
libbeat/outputs/output_reg.go Show resolved Hide resolved
libbeat/outputs/output_reg.go Show resolved Hide resolved
libbeat/ilm/single.go Outdated Show resolved Hide resolved
libbeat/ilm/eshandler.go Outdated Show resolved Hide resolved
libbeat/ilm/error.go Outdated Show resolved Hide resolved
libbeat/ilm/error.go Outdated Show resolved Hide resolved
libbeat/ilm/error.go Outdated Show resolved Hide resolved
libbeat/ilm/error.go Outdated Show resolved Hide resolved
@urso urso requested a review from ph January 26, 2019 01:33
@urso urso added the in progress Pull request is currently in progress. label Jan 26, 2019
libbeat/idxmgmt/ilm/single.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/noop.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/error.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/config.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/config.go Show resolved Hide resolved
libbeat/common/reload/reload.go Show resolved Hide resolved
libbeat/common/reload/reload.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/single.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/ilm.go Show resolved Hide resolved
libbeat/idxmgmt/idxmgmt.go Show resolved Hide resolved
@urso urso force-pushed the refactor-index-management branch from a95cabd to 508e80a Compare January 27, 2019 16:13
@urso urso requested review from a team as code owners January 28, 2019 06:59
@urso urso removed request for a team January 28, 2019 07:17
@urso urso added review libbeat and removed in progress Pull request is currently in progress. labels Jan 28, 2019
@urso urso changed the title [WIP] Refactor index management Refactor index management Jan 28, 2019
Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

@urso really good PR, I really like how you actually encapsulated all the logic inside the idxmgmt package, I found two things.

  1. There was a problem with the integration suite with your code in the libbeat
command [go test -tags integration -cover -coverprofile /tmp/gotestcover-226034385 github.com/elastic/beats/libbeat/idxmgmt/ilm]: exit status 1
# github.com/elastic/beats/libbeat/idxmgmt/ilm
idxmgmt/ilm/eshandler_integration_test.go:28:2: cannot find package "github.com/satori/go.uuid" in any of:
	/go/src/github.com/elastic/beats/vendor/github.com/satori/go.uuid (vendor tree)
	/usr/local/go/src/github.com/satori/go.uuid (from $GOROOT)
	/go/src/github.com/satori/go.uuid (from $GOPATH)
FAIL	github.com/elastic/beats/libbeat/idxmgmt/ilm [setup failed]
  1. I will fix the issue when the docker-compose logs is shallowing the previous error.

CHANGELOG-developer.next.asciidoc Show resolved Hide resolved
auditbeat/auditbeat.reference.yml Outdated Show resolved Hide resolved
auditbeat/auditbeat.reference.yml Outdated Show resolved Hide resolved
libbeat/cmd/export/ilm_policy.go Outdated Show resolved Hide resolved
libbeat/cmd/export/ilm_policy.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Outdated Show resolved Hide resolved
libbeat/idxmgmt/ilm/eshandler.go Show resolved Hide resolved
@urso
Copy link
Author

urso commented Jan 29, 2019

There was a problem with the integration suite with your code in the libbeat

goimports did select the wrong package :(. I fixed the import (and removed old dependency from my machine). Beats-CI and travis being green is somewhat worrysome.

@urso urso force-pushed the refactor-index-management branch from 1862a0f to 92a138b Compare January 29, 2019 09:52
@@ -0,0 +1,94 @@
// Licensed to Elasticsearch B.V. under one or more contributor
Copy link
Contributor

Choose a reason for hiding this comment

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

I have seen similar functionality in go-txfile. It is definitely a better approach for error handling compared to what Golang provides by default. Do you have any plans to consolidate error handling? E.g moving the functions to libbeat and leaving the error variables here.

Copy link
Author

Choose a reason for hiding this comment

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

We also have some similar functionality in go-ucfg.

Do you have any plans to consolidate error handling?

Yes. See: https://github.com/urso/ecslog/tree/master/errx

@urso urso force-pushed the refactor-index-management branch from 92a138b to 004832d Compare January 29, 2019 09:57
return status == 200, nil
}

func (h *esClientHandler) HasAlias(name string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am looking forward to having an Elasticseach Golang client. I had to implement the same functions in the migration tool.

@@ -21,6 +21,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Rename `process.exe` to `process.executable` in add_process_metadata to align with ECS. {pull}9949[9949]
- Import ECS change https://github.com/elastic/ecs/pull/308[ecs#308]:
leaf field `user.group` is now the `group` field set. {pull}10275[10275]
- Move output.elasticsearch.ilm settings to setup.ilm. {pull}10347[10347]
- ILM will be available by default if Elasticsearch > 7.0 is used. {pull}10347[10347]
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens for the OSS users? Should this be >= 7?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, auto is default and not true ... I assume this does the trick.

Copy link
Author

Choose a reason for hiding this comment

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

yep, auto does the trick.

@ph
Copy link
Contributor

ph commented Jan 29, 2019

goimports did select the wrong package :(. I fixed the import (and removed old dependency from my machine). Beats-CI and travis being green is somewhat worrysome.

I have fixed that in #10380

type Alias struct {
Name string
Pattern string
}
Copy link
Contributor

Choose a reason for hiding this comment

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

<3 ^

@urso urso force-pushed the refactor-index-management branch from 7e51210 to 8c29608 Compare January 31, 2019 00:12
@urso
Copy link
Author

urso commented Jan 31, 2019

Jenkins, please test this.

@urso
Copy link
Author

urso commented Jan 31, 2019

Jenkins, test this.

@ph
Copy link
Contributor

ph commented Jan 31, 2019

The failures are not related to this change.

@urso urso merged commit 2bbf828 into elastic:master Jan 31, 2019
@simitt
Copy link
Contributor

simitt commented Jan 31, 2019

Thanks for putting this PR up @urso! First experiences trying this out showed that the integration with the new supporters is pretty smooth!

@urso urso deleted the refactor-index-management branch January 31, 2019 14:49
DStape pushed a commit to DStape/beats that referenced this pull request Aug 20, 2019
Changes:
- introduce Index + ILM manager interfaces responsible for:
  - create ILM policy
  - create write alias
  - create and load template
  - separate interfaces for re-use: manager, apihandler
  - provide default API handler for elasticsearch.Client
- Index + ILM support interfaces, that can be swapped out with custom implementation (still WIP)
  - Beat implementing custom managers have to decide on config file format
- ILM settings have been moved to `ilm.setup`
- Introduce `setup.ilm.enabled: auto` (new default)
  - Index manager will detect on connect to Elasticsearch if ILM can be enabled or not
  - Lazily chooses write alias or old-style index for publishing
  - Index Manager does not check ILM availabilty on startup, but on first connect (so to not block beats startup)
  - If Elasticsearch < 7.0, then `auto` defaults to false
  - If Elasticsearch > 7.0, then `auto` checks if ILM is available and enbaled
  - If `setup.ilm.enabled: true`, then fail check if version does not support ILM or ILM is disabled
- Publisher pipeline does not use output package anymore to create an output, but a callback -> Beat instance itself creates output instances, passing IndexManager and other info to the output loader.
- Outputs can use IndexManager in order to create the per event index selector
- remove fragile manipulation of `common.Config` objects, that have been already partially parsed.
- Ensure ILM can be setup if `setup.ilm.enabled: true`, but elasticsearch output is configured via Central Management


Followup: update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants