kibana es add --use-cached cli flag (#119149)

This commit is contained in:
Esteban Beltran 2021-11-19 14:39:56 -05:00 committed by GitHub
parent 998a0db2cf
commit a1e441401d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View file

@ -194,11 +194,23 @@ exports.Artifact = class Artifact {
* @param {string} dest
* @return {Promise<void>}
*/
async download(dest) {
async download(dest, { useCached = false }) {
await retry(this._log, async () => {
const cacheMeta = cache.readMeta(dest);
const tmpPath = `${dest}.tmp`;
if (useCached) {
if (cacheMeta.exists) {
this._log.info(
'use-cached passed, forcing to use existing snapshot',
chalk.bold(cacheMeta.ts)
);
return;
} else {
this._log.info('use-cached passed but no cached snapshot found. Continuing to download');
}
}
const artifactResp = await this._download(tmpPath, cacheMeta.etag, cacheMeta.ts);
if (artifactResp.cached) {
return;

View file

@ -29,6 +29,7 @@ exports.help = (defaults = {}) => {
-E Additional key=value settings to pass to Elasticsearch
--download-only Download the snapshot but don't actually start it
--ssl Sets up SSL on Elasticsearch
--use-cached Skips cache verification and use cached ES snapshot.
Example:
@ -51,11 +52,12 @@ exports.run = async (defaults = {}) => {
installPath: 'install-path',
dataArchive: 'data-archive',
esArgs: 'E',
useCached: 'use-cached',
},
string: ['version'],
boolean: ['download-only'],
boolean: ['download-only', 'use-cached'],
default: defaults,
});

View file

@ -29,6 +29,7 @@ exports.downloadSnapshot = async function installSnapshot({
basePath = BASE_PATH,
installPath = path.resolve(basePath, version),
log = defaultLog,
useCached = false,
}) {
log.info('version: %s', chalk.bold(version));
log.info('install path: %s', chalk.bold(installPath));
@ -36,7 +37,7 @@ exports.downloadSnapshot = async function installSnapshot({
const artifact = await Artifact.getSnapshot(license, version, log);
const dest = path.resolve(basePath, 'cache', artifact.getFilename());
await artifact.download(dest);
await artifact.download(dest, { useCached });
return {
downloadPath: dest,
@ -62,6 +63,7 @@ exports.installSnapshot = async function installSnapshot({
installPath = path.resolve(basePath, version),
log = defaultLog,
esArgs,
useCached = false,
}) {
const { downloadPath } = await exports.downloadSnapshot({
license,
@ -69,6 +71,7 @@ exports.installSnapshot = async function installSnapshot({
basePath,
installPath,
log,
useCached,
});
return await installArchive(downloadPath, {