kibana/packages/kbn-es
Kibana Machine 71227e03a7
[8.9] Fix yarn es snapshot cache hit (#161183) (#161390)
# Backport

This will backport the following commits from `main` to `8.9`:
- [Fix yarn es snapshot cache hit
(#161183)](https://github.com/elastic/kibana/pull/161183)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Vettorello","email":"marco.vettorello@elastic.co"},"sourceCommit":{"committedDate":"2023-07-06T19:00:29Z","message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760","branchLabelMapping":{"^v8.10.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["build","release_note:skip","backport:all-open","v8.10.0"],"number":161183,"url":"https://github.com/elastic/kibana/pull/161183","mergeCommit":{"message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.10.0","labelRegex":"^v8.10.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/161183","number":161183,"mergeCommit":{"message":"Fix
yarn es snapshot cache hit (#161183)\n\nThe `yarn es` command provides a
useful `--use-cached` to avoid\r\nredownloading the cache, but this is
always skipped because no one set\r\nthe `exists` field is required by
the command to check if the cache is\r\navailable.\r\n\r\nThis commit
just adds that `exists` property where is needed (when reading\r\nthe
`.meta` file) and leaves the rest of the code unaltered.\r\nI could have
implemented the same behavior by returning `null` from the\r\n`readMeta`
and doing a null check where we checked for the `exists`\r\nproperty.
Please feel free which approach you feel
better.","sha":"acba5fb088407c205355d73d65c198d1fe977760"}}]}]
BACKPORT-->

Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
2023-07-06 13:06:09 -07:00
..
src [8.9] Fix yarn es snapshot cache hit (#161183) (#161390) 2023-07-06 13:06:09 -07:00
index.ts Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
jest.config.js [jest] add *_node presets (#126192) 2022-02-23 09:36:30 -06:00
jest.integration.config.js [jest] add *_node presets (#126192) 2022-02-23 09:36:30 -06:00
kibana.jsonc Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
package.json Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
README.mdx [kbn/es] Add dev docs for snapshot promotion pipeline (#148350) 2023-01-05 12:45:34 -06:00
tsconfig.json Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00

---
id: kibDevDocsOpsEs
slug: /kibana-dev-docs/ops/es
title: "@kbn/es"
description: A cli package for running elasticsearch or building snapshot artifacts
date: 2022-05-24
tags: ['kibana', 'dev', 'contributor', 'operations', 'es']
---

> A command line utility for running elasticsearch from snapshot, source, archive or even building snapshot artifacts. 

## Getting started
If running elasticsearch from source, elasticsearch needs to be cloned to a sibling directory of Kibana.

To run, go to the Kibana root and run `node scripts/es --help` to get the latest command line options.

The script attempts to preserve the existing interfaces used by Elasticsearch CLI. This includes passing through options with the `-E` argument and the `ES_JAVA_OPTS` environment variable for Java options.

### Examples

Run a snapshot install with a trial license
```
node scripts/es snapshot --license=trial
```

Run from source with a configured data directory
```
node scripts/es source --Epath.data=/home/me/es_data
```

## API

### run
Start a cluster
```
var es = require('@kbn/es');
es.run({
  license: 'basic',
  version: 7.0,
})
.catch(function (e) {
  console.error(e);
  process.exitCode = 1;
});
```

#### Options

##### options.license

Type: `String`

License type, one of: trial, basic, gold, platinum

##### options.version

Type: `String`

Desired elasticsearch version

##### options['source-path']

Type: `String`

Cloned location of elasticsearch repository, used when running from source

##### options['base-path']

Type: `String`

Location where snapshots are cached

## Snapshot Updates

Snapshots are built and tested daily.  If tests pass, the snapshot is promoted and will automatically be used when started from the CLI.

CI pipelines supporting this can be found at:

- https://buildkite.com/elastic/kibana-elasticsearch-snapshot-build
- https://buildkite.com/elastic/kibana-elasticsearch-snapshot-verify
- https://buildkite.com/elastic/kibana-elasticsearch-snapshot-promote

## Snapshot Pinning

Sometimes we need to pin snapshots for a specific version. We'd really like to get this automated, but until that is completed here are the steps to take to build, upload, and switch to pinned snapshots for a branch.

To use these steps you'll need to setup the google-cloud-sdk, which can be installed on macOS with `brew cask install google-cloud-sdk`. Login with the CLI and you'll have access to the `gsutil` to do efficient/parallel uploads to GCS from the command line.

 1. Clone the elasticsearch repo somewhere
 2. Checkout the branch you want to build
 3. Build the new artifacts

    ```
    node scripts/es build_snapshots --output=~/Downloads/tmp-artifacts --source-path=/path/to/es/repo
    ```

 4. Check that the files in `~/Downloads/tmp-artifacts` look reasonable
 5. Upload the files to GCS

    ```
    gsutil -m rsync . gs://kibana-ci-tmp-artifacts/
    ```

 6. Once the artifacts are uploaded, modify `packages/kbn-es/src/custom_snapshots.js` in a PR to use a URL formatted like:

    ```
    // force use of manually created snapshots until ReindexPutMappings fix
    if (!process.env.KBN_ES_SNAPSHOT_URL && !process.argv.some(isVersionFlag)) {
      // return undefined;
      return 'https://storage.googleapis.com/kibana-ci-tmp-artifacts/{name}-{version}-{os}-x86_64.{ext}';
    }
    ```

    For 6.8, the format of the url should look like:

    ```
    'https://storage.googleapis.com/kibana-ci-tmp-artifacts/{name}-{version}.{ext}';
    ```