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

Add snapshots support #76

Merged
merged 20 commits into from
Nov 4, 2020
Merged

Add snapshots support #76

merged 20 commits into from
Nov 4, 2020

Conversation

rolljee
Copy link
Contributor

@rolljee rolljee commented Oct 30, 2020

What does this PR do?

This PR adds the snapshots module to kourou.

Close #70

How should this be manually tested?

  1. git clone
  2. npm install
  3. ./bin/run es:snapshots:<command> <args> --<flags>

network.host: 0.0.0.0

# You need to create this folder in order to run snapshots
path.repo: ["/tmp/snapshots"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we pass this variable to ES with the environment instead of having to build a whole new Docker image?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried, does not work

Copy link
Contributor

Choose a reason for hiding this comment

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

Why 🤔

Copy link
Member

@alexandrebouthinon alexandrebouthinon Nov 2, 2020

Choose a reason for hiding this comment

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

I think this is due to the fact that the value is an array. Could you try to use YAML objects for environment variables? Like this:

services:
  kuzzle:
  # ...
  elasticsearch:
    image: yourImage
    environments:
      path.repo:
        - /tmp/snapshots
    # ...

or using regular YAML array of string:

services:
  kuzzle:
  # ...
  elasticsearch:
    image: yourImage
    environments:
      - 'path.repo=["/tmp/snapshots"]'
    # ...

Copy link
Member

@alexandrebouthinon alexandrebouthinon Nov 2, 2020

Choose a reason for hiding this comment

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

Double quote in the second snippet are required for YAML parsing (#76 (comment))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try that, get back to you if it works or not 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexandrebouthinon both of the options you proposed weren't successful. Only option I see is to keep it that way :x

Copy link
Member

Choose a reason for hiding this comment

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

Ok I thought it was a parsing and type inference problem. That's good for me then 🙂

@rolljee rolljee marked this pull request as ready for review November 2, 2020 10:52
@rolljee rolljee linked an issue Nov 2, 2020 that may be closed by this pull request
9 tasks
@rolljee rolljee marked this pull request as draft November 2, 2020 10:55
@rolljee rolljee marked this pull request as ready for review November 2, 2020 13:28
@rolljee rolljee requested a review from Aschen November 2, 2020 13:28
async getIndices(esClient: Client) {
const beforeResponse = await esClient.cat.indices({ format: 'json' })

const indices: string[] = beforeResponse.body
Copy link
Contributor

Choose a reason for hiding this comment

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

Type is automatically inferred here

Suggested change
const indices: string[] = beforeResponse.body
const indices = beforeResponse.body


const response = await esClient.snapshot.restore(esRequest)

const indicesAfterRestore = await this.getIndices(esClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should call the method only one time and store the result

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, i did that because i wasn't sure indices where put in open state after a restore leading to closed indice. but I checked in the doc

The restore operation must be performed on a functioning cluster. However, an existing index can be only restored if it’s closed and has the same number of shards as the index in the snapshot. The restore operation automatically opens restored indices if they were closed and creates new indices if they didn’t exist in the cluster.

So we can safely remove this call indeed.

await esClient.indices.open({ index })
}

this.logOk(`Success ${JSON.stringify(response.body)}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about this. Can't we have a better message or at least an indented JSON?

tsconfig.json Outdated
"strict": true,
"target": "es2017",
"esModuleInterop": true
"esModuleInterop": true,
"resolveJsonModule": true
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need this line anymore


import { Kommand } from '../../../common'

export default class ESDump extends Kommand {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking

Suggested change
export default class ESDump extends Kommand {
export default class EsSnapshotsDump extends Kommand {


import { Kommand } from '../../../common'

export default class EsCreateSnapshot extends Kommand {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking

Suggested change
export default class EsCreateSnapshot extends Kommand {
export default class EsSnapshotsCreateRepository extends Kommand {


import { Kommand } from '../../../common'

export default class ESlistSnapshot extends Kommand {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicking

Suggested change
export default class ESlistSnapshot extends Kommand {
export default class EsSnapshotsList extends Kommand {

}

const response = await esClient.snapshot.restore(esRequest)

Copy link
Contributor

Choose a reason for hiding this comment

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

You need to open the indices again and you should do that in a finally block to ensure they don't stay closed

network.host: 0.0.0.0

# You need to create this folder in order to run snapshots
path.repo: ["/tmp/snapshots"]
Copy link
Member

@alexandrebouthinon alexandrebouthinon Nov 2, 2020

Choose a reason for hiding this comment

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

I think this is due to the fact that the value is an array. Could you try to use YAML objects for environment variables? Like this:

services:
  kuzzle:
  # ...
  elasticsearch:
    image: yourImage
    environments:
      path.repo:
        - /tmp/snapshots
    # ...

or using regular YAML array of string:

services:
  kuzzle:
  # ...
  elasticsearch:
    image: yourImage
    environments:
      - 'path.repo=["/tmp/snapshots"]'
    # ...

network.host: 0.0.0.0

# You need to create this folder in order to run snapshots
path.repo: ["/tmp/snapshots"]
Copy link
Member

@alexandrebouthinon alexandrebouthinon Nov 2, 2020

Choose a reason for hiding this comment

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

Double quote in the second snippet are required for YAML parsing (#76 (comment))


import { Kommand } from '../../../common'

export default class EsSnapshotsDump extends Kommand {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should use the term "dump" in this module since they are not dumps but snapshots which is quite different

Suggested change
export default class EsSnapshotsDump extends Kommand {
export default class EsSnapshots extends Kommand {

Copy link
Contributor

Choose a reason for hiding this comment

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

So the command should be called create to follow ES terminology: https://www.elastic.co/guide/en/elasticsearch/reference/current/snapshot-restore.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a little confusing to just call it EsSnapshots

Since in this "snapshots" module we can create 2 types of thing

  1. Repository (the holder of snapshots)
  2. Snapshot (data)

I prefer option EsSnapshotsCreate since we have an EsSnapshotsCreateRepository

@alexandrebouthinon wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And also, shall we rename the Kommand -> es:snapshots:create ?

ping @Aschen @alexandrebouthinon

Copy link
Member

Choose a reason for hiding this comment

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

Yes I agree with you for the naming, we might as well stick to the Elasticsearch documentation 👍

Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

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

Last nitpicking I'm sorry 😅
The commands should be under the name snapshot and not snapshots since that's the name of a "module"

@rolljee rolljee merged commit 1beed5c into develop Nov 4, 2020
@rolljee rolljee deleted the feat/es-snapshots branch November 4, 2020 10:11
@Aschen Aschen mentioned this pull request Nov 10, 2020
Aschen added a commit that referenced this pull request Nov 10, 2020
# [0.17.0](https://github.com/kuzzleio/kourou/releases/tag/0.17.0) (2020-11-10)


#### New features

- [ [#76](#76) ] Add snapshots support   ([rolljee](https://github.com/rolljee))

#### Enhancement

- [ [#78](#78) ] Fix app:scaffold and improve api action hook help   ([Aschen](https://github.com/Aschen))
---
Copy link

🎉 This PR is included in version 1.0.0-beta.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Copy link

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

Add es:snapshot module
3 participants