-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI] Archive logs from
yarn es
docker runs (#189231)
## Summary The problem we're trying to solve here is to get access to `elasticsearch-serverless` logs when they're started in docker containers in the background (and `elasticsearch`, although currently we don't test against that in docker for now). ## Solution In essence: - we needed to remove the `--rm` flag, this would allow for the containers to stay present after they're done. - after this, we can run `docker logs ...` on FTR post-hooks, save these, then archive these files to buildkite - because the containers are not removed upon finishing, we need to clean up dangling containers before starting up Backporting is probably not necessary, because this is only applicable for serverless - and serverless is only supposed to run on main. Solves: #191505 (cherry picked from commit bce4a17)
- Loading branch information
Showing
6 changed files
with
111 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import type { ToolingLog } from '@kbn/tooling-log'; | ||
|
||
import execa from 'execa'; | ||
import Fsp from 'fs/promises'; | ||
import { join } from 'path'; | ||
|
||
import { REPO_ROOT } from '@kbn/repo-info'; | ||
|
||
/** | ||
* Extracts logs from Docker nodes, writes them to files, and returns the file paths. | ||
*/ | ||
export async function extractAndArchiveLogs({ | ||
outputFolder, | ||
log, | ||
nodeNames, | ||
}: { | ||
log: ToolingLog; | ||
nodeNames?: string[]; | ||
outputFolder?: string; | ||
}) { | ||
outputFolder = outputFolder || join(REPO_ROOT, '.es'); | ||
const logFiles: string[] = []; | ||
|
||
if (!nodeNames) { | ||
const { stdout: nodeNamesString } = await execa('docker', [ | ||
'ps', | ||
'-a', | ||
'--format', | ||
'{{.Names}}', | ||
]); | ||
nodeNames = nodeNamesString.split('\n').filter(Boolean); | ||
} | ||
|
||
if (!nodeNames.length) { | ||
log.info('No Docker nodes found to extract logs from'); | ||
return; | ||
} else { | ||
log.info(`Attempting to extract logs from Docker nodes to ${outputFolder}`); | ||
} | ||
|
||
for (const name of nodeNames) { | ||
const { stdout: nodeId } = await execa('docker', [ | ||
'ps', | ||
'-a', | ||
'--quiet', | ||
'--filter', | ||
`name=${name}`, | ||
]); | ||
if (!nodeId) { | ||
continue; | ||
} | ||
|
||
const { stdout } = await execa('docker', ['logs', name]); | ||
const targetFile = `${name}-${nodeId}.log`; | ||
const targetPath = join(outputFolder, targetFile); | ||
|
||
await Fsp.writeFile(targetPath, stdout); | ||
logFiles.push(targetFile); | ||
|
||
log.info(`Archived logs for ${name} to ${targetPath}`); | ||
} | ||
|
||
return logFiles; | ||
} |
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