generated from threeal/action-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add verbose option for detailed cache logging #20
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
Open
adityamaru
wants to merge
2
commits into
main
Choose a base branch
from
add-verbose-cache-logging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -5,6 +5,8 @@ import { promisify } from "util"; | |
import * as TOML from "@iarna/toml"; | ||
import * as reporter from "./reporter"; | ||
import { execa } from "execa"; | ||
// TODO: Uncomment when updating to @buf/[email protected]+ | ||
// import { Metric_MetricType } from "@buf/blacksmith_vm-agent.bufbuild_es/stickydisk/v1/stickydisk_pb.js"; | ||
|
||
// Constants for configuration. | ||
const BUILDKIT_DAEMON_ADDR = "tcp://127.0.0.1:1234"; | ||
|
@@ -250,6 +252,13 @@ export async function startAndConfigureBuildkitd( | |
core.info( | ||
`Found ${lines.length - 1} workers, required ${requiredWorkers}`, | ||
); | ||
// TODO: Report how long it took for workers to be available | ||
// Uncomment when updating to @buf/[email protected]+ | ||
// const workersAvailableDuration = Date.now() - startTimeBuildkitReady; | ||
// await reporter.reportMetric( | ||
// Metric_MetricType.BPA_V2_DEBUG_WORKERS_AVAILABLE_MS, | ||
// workersAvailableDuration, | ||
// ); | ||
break; | ||
} | ||
} catch (error) { | ||
|
@@ -287,14 +296,121 @@ export async function startAndConfigureBuildkitd( | |
* We don't specify any keep bytes here since we are | ||
* handling the ceph volume size limits ourselves in | ||
* the VM Agent. | ||
* @param verbose - If true, logs detailed cache information | ||
* @throws Error if buildctl prune command fails | ||
*/ | ||
export async function pruneBuildkitCache(): Promise<void> { | ||
export async function pruneBuildkitCache(verbose = false): Promise<void> { | ||
try { | ||
// Log cache state before pruning using docker buildx du | ||
if (verbose) { | ||
try { | ||
const { stdout: cacheBeforePrune } = await execAsync( | ||
`sudo docker buildx du --builder default 2>/dev/null || true`, | ||
); | ||
if (cacheBeforePrune) { | ||
core.info("BuildKit cache details before prune:"); | ||
cacheBeforePrune | ||
.split("\n") | ||
.filter((line) => line.trim()) | ||
.forEach((line) => { | ||
core.info(` ${line}`); | ||
}); | ||
} | ||
|
||
// Also get a summary view with more details | ||
const { stdout: detailedCacheBefore } = await execAsync( | ||
`sudo docker buildx du --builder default --verbose 2>/dev/null || true`, | ||
); | ||
if (detailedCacheBefore) { | ||
const lines = detailedCacheBefore | ||
.split("\n") | ||
.filter((line) => line.trim()); | ||
// Log the summary line and first few cache entries for context | ||
const summaryLine = lines.find( | ||
(line) => line.includes("Total:") || line.includes("TOTAL"), | ||
); | ||
if (summaryLine) { | ||
core.info(`Total cache size before prune: ${summaryLine}`); | ||
} | ||
} | ||
} catch (error) { | ||
core.info( | ||
`Could not get cache details before prune: ${(error as Error).message}`, | ||
); | ||
} | ||
} | ||
|
||
const sevenDaysInHours = 7 * 24; | ||
await execAsync( | ||
const pruneOutput = await execAsync( | ||
`sudo buildctl --addr ${BUILDKIT_DAEMON_ADDR} prune --keep-duration ${sevenDaysInHours}h --all`, | ||
); | ||
|
||
// Parse prune output to get bytes freed | ||
// buildctl prune typically outputs something like "Total: 1.2GB" | ||
if (pruneOutput.stdout && verbose) { | ||
const match = pruneOutput.stdout.match( | ||
/Total:\s*([0-9.]+)\s*([KMGT]?B)/i, | ||
); | ||
if (match) { | ||
// TODO: When updating to @buf/[email protected]+ | ||
// Parse the size and unit, convert to bytes, and report metric: | ||
// const size = parseFloat(match[1]); | ||
// const unit = match[2].toUpperCase(); | ||
// let bytes = size; | ||
// switch (unit) { | ||
// case 'KB': bytes = size * 1024; break; | ||
// case 'MB': bytes = size * 1024 * 1024; break; | ||
// case 'GB': bytes = size * 1024 * 1024 * 1024; break; | ||
// case 'TB': bytes = size * 1024 * 1024 * 1024 * 1024; break; | ||
// } | ||
// await reporter.reportMetric( | ||
// Metric_MetricType.BPA_V2_PRUNE_BYTES, | ||
// Math.round(bytes), | ||
// ); | ||
|
||
core.info(`Pruned ${match[0]} from BuildKit cache`); | ||
} | ||
} | ||
|
||
// Log cache state after pruning using docker buildx du | ||
if (verbose) { | ||
try { | ||
const { stdout: cacheAfterPrune } = await execAsync( | ||
`sudo docker buildx du --builder default 2>/dev/null || true`, | ||
); | ||
if (cacheAfterPrune) { | ||
core.info("BuildKit cache details after prune:"); | ||
cacheAfterPrune | ||
.split("\n") | ||
.filter((line) => line.trim()) | ||
.forEach((line) => { | ||
core.info(` ${line}`); | ||
}); | ||
} | ||
|
||
// Also get a summary view with more details | ||
const { stdout: detailedCacheAfter } = await execAsync( | ||
`sudo docker buildx du --builder default --verbose 2>/dev/null || true`, | ||
); | ||
if (detailedCacheAfter) { | ||
const lines = detailedCacheAfter | ||
.split("\n") | ||
.filter((line) => line.trim()); | ||
// Log the summary line | ||
const summaryLine = lines.find( | ||
(line) => line.includes("Total:") || line.includes("TOTAL"), | ||
); | ||
if (summaryLine) { | ||
core.info(`Total cache size after prune: ${summaryLine}`); | ||
} | ||
} | ||
} catch (error) { | ||
core.info( | ||
`Could not get cache details after prune: ${(error as Error).message}`, | ||
); | ||
} | ||
} | ||
|
||
core.debug("Successfully pruned buildkit cache"); | ||
} catch (error) { | ||
core.warning(`Error pruning buildkit cache: ${(error as Error).message}`); | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Post-Action Fails to Retrieve Inputs
The post-action attempts to retrieve the
verbose
input usingstateHelper.getInputs()
, but the inputs are not saved to state during the main action. This meansstateHelper.getInputs()
returns an empty object, so theverbose
setting isn't respected during cleanup.Additional Locations (1)
src/main.ts#L333-L335