forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] [es] disable wildcards in destructive actions (elastic#88986) (e…
…lastic#90804) Co-authored-by: spalger <spalger@users.noreply.github.com>
- Loading branch information
Showing
50 changed files
with
229 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
export function EsDeleteAllIndicesProvider({ getService }: FtrProviderContext) { | ||
const es = getService('es'); | ||
const log = getService('log'); | ||
|
||
async function deleteConcreteIndices(indices: string[]) { | ||
try { | ||
await es.indices.delete({ | ||
index: indices, | ||
ignore_unavailable: true, | ||
}); | ||
} catch (error) { | ||
log.debug(`Failed to delete indices [${indices}], but ignoring error: ${error.message}`); | ||
} | ||
} | ||
|
||
return async (patterns: string | string[]) => { | ||
for (const pattern of [patterns].flat()) { | ||
for (let attempt = 1; ; attempt++) { | ||
if (attempt > 5) { | ||
throw new Error(`Failed to delete all indices with pattern [${pattern}]`); | ||
} | ||
|
||
// resolve pattern to concrete index names | ||
const resp = await es.indices.getAlias( | ||
{ | ||
index: pattern, | ||
}, | ||
{ | ||
ignore: [404], | ||
} | ||
); | ||
const indices = Object.keys(resp.body) as string[]; | ||
|
||
// if no indexes exits then we're done with this pattern | ||
if (resp.statusCode === 404 || !indices.length) { | ||
if (attempt === 1) { | ||
log.debug(`No indices to delete [pattern=${pattern}]`); | ||
} | ||
break; | ||
} | ||
|
||
log.debug( | ||
`Deleting indices [attempt=${attempt}] [pattern=${pattern}] "${indices.join('", "')}"` | ||
); | ||
|
||
// delete the concrete indexes we found and try again until this pattern resolves to no indexes | ||
await deleteConcreteIndices(indices); | ||
} | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.