-
Notifications
You must be signed in to change notification settings - Fork 2
Conversation
@kvch Can you vendor libbeat and make a PR with just that? That will make this PR a lot smaller. |
952afc2
to
951ee23
Compare
migration.go
Outdated
_, _, err := client.Reindex(managementIndexName, backupManagementIndexName, nil) | ||
if err != nil { | ||
return fmt.Errorf("error while backup up old .management-beats index: %+v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reindexing we create a very new index. Are there any index settings to apply before/when we create the backup index? E.g. set number of shards to 1?
E.g.
- load index mapping from existing
.management-beats
index - create target backup index with index mapping (and other settings?)
- reindex into backup index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it is a temporary index, I found it unnecessary to setup such things. Why do you think it is necessary?
migration.go
Outdated
} | ||
log.Println("Alias .management-beats is removed") | ||
|
||
_, _, err = client.Reindex(newManagementIndexName, managementIndexName, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think managementIndexName
does not exist anymore when we are here. We should create the index and establish the mapping before reindexing into the index to be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I need to put the same mapping and settings as it is done for newManagmentIndexName
.
migration.go
Outdated
return nil | ||
} | ||
|
||
func rollback(client *elasticsearch.Client) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if rollback itself fails. Can we continue from the last ok step if the user runs the script again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my plan, but the rollback functionality is a bit fragile right now. But the architecture you've proposed above will be able to achieve this. I could add a flag to set where to start the migration when running the script.
15043ac
to
ca0495b
Compare
07a4df6
to
7560f2c
Compare
Functionally LGTM. Worth noting that when migrating a very large deployment it did hang for a while. But I doubt anyone will be doing that (10k beats, 6 tags per beat, 500 configs per tag) |
@mattapperson I have done some refactoring to use the Bulk API of Elasticsearch to index new documents. Do you mind running another stress test to see if the script still hangs? |
step.go
Outdated
|
||
func (s steps) Undo(client *elasticsearch.Client) error { | ||
i := len(s) | ||
for i <= 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i:=len(s)-1; i >= 0; i-- {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️
migration.go
Outdated
for i := step; i < uint(len(migrationSteps)); i++ { | ||
err = migrationSteps[i].Do(client) | ||
if err != nil { | ||
undoErr := stepsToUndo.Undo(client) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you add a step to the undo list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere, but fixed.
step.go
Outdated
if err != nil { | ||
return fmt.Errorf("error while backup up old .management-beats index: %+v", err) | ||
} | ||
log.Println("Old .management-beats index is reindexed into .management-beats-backup") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better use log.Printf
with predefine index name variables.
8a751d0
to
0911757
Compare
I still need to do a bit more testing so I can remove the ugly "WIP" "sign" from the PR. |
"log" | ||
"time" | ||
|
||
//"gopkg.in/yaml.v2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed?
@kvch code look good, have you tested it with CM 6.x to 6.7 with real data? |
Yes, before the refactoring. Now I have tested it again, and added a few fixes. But I am facing a weird bug now, so I need a bit more time to find the problem. |
8a90d95
to
92dd275
Compare
@ph @mattapperson I have found the issue in the code. Now it is ready to be tested. |
Merging to prepare first release. |
THIS IS WORK IN PROGRESS
This tool migrates
.management-beats
index the following way:.management-beats
index as.management-beats-backup
. The backup is then aliased as.management-beats
..management-beats-new
. The new index mapping of 6.7 is PUT to ES..management-beats-backup
which does not require any transformation:beat
,enrollment_token
.tags
from.management-beats-backup
. These are transformed into newtag
documents. Also,configuration_block
documents are created for each config element of atag
..management-beats
..management-beats-new
is reindexed, and the backup is deleted.If something goes wrong along the process, everything is rolled back.
TODO
Aliases
toelasticsearch.Client
Possible enhancements