Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/docker-stress-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
workflow_dispatch:
inputs:
push_image:
description: 'Push images to registry'
description: "Push images to registry"
required: false
default: 'false'
default: "false"

env:
REGISTRY: ghcr.io
Expand Down Expand Up @@ -181,7 +181,7 @@ jobs:
with:
version: v0.12.0
driver: docker-container

- name: Build with SBOM and provenance
uses: docker/build-push-action@v5
with:
Expand Down Expand Up @@ -246,7 +246,7 @@ jobs:
dockerfile = "Dockerfile"
tags = ["test/bake:latest"]
}

target "production" {
inherits = ["default"]
tags = ["test/bake:prod"]
Expand Down Expand Up @@ -453,7 +453,7 @@ jobs:
target: base
tags: test/base:latest
outputs: type=docker

- name: Second build - production image
uses: docker/build-push-action@v5
with:
Expand All @@ -462,4 +462,4 @@ jobs:
tags: test/production:latest
build-args: |
BASE_IMAGE=test/base:latest
outputs: type=docker
outputs: type=docker
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions src/metrics-implementation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# V2 Metrics Implementation

This document describes the implementation of two new V2 metrics for the setup-docker-builder action.

## Implemented Metrics

### 1. BPA_V2_DEBUG_WORKERS_AVAILABLE_MS

- **Description**: Time taken (in milliseconds) for the `debug workers` command to become available after starting buildkitd
- **Type**: Integer (milliseconds)
- **When reported**: During builder startup, after buildkitd is started
- **Implementation**: Implemented in `setup_builder.ts` - tracks the time from when we start checking for workers until they become available
- **Protobuf enum value**: 7

### 2. BPA_V2_PRUNE_BYTES

- **Description**: Number of bytes pruned from the buildkit cache when running the prune command
- **Type**: Integer (bytes)
- **When reported**: During cleanup phase, when pruning the buildkit cache
- **Implementation**: Implemented in `setup_builder.ts` - parses the output of the `buildctl prune` command to extract bytes reclaimed
- **Protobuf enum value**: 8

## Status

✅ **COMPLETED** - Both metrics are now:

1. Added to the protobuf definition in `/Users/adityamaru/fa/agent/stickydisk/v1/stickydisk.proto`
2. Generated using `buf generate`
3. Integrated into the setup-docker-builder action in `main.ts`

## Implementation Details

### Debug Workers Metric

The `startAndConfigureBuildkitd` function now returns an object containing:

- `addr`: The buildkit daemon address
- `debugWorkersTimeMs`: Time taken for debug workers to become available

This metric helps track how quickly the buildkitd daemon becomes fully operational.

### Prune Bytes Metric

The `pruneBuildkitCache` function now:

- Returns the number of bytes pruned (or undefined if unable to parse)
- Includes a `parsePruneOutput` helper function that parses the prune command output
- Handles various output formats (KB, MB, GB, TB)
- Looks for "Total:" or "reclaimed" patterns in the output

This metric helps track the effectiveness of cache pruning and storage reclamation.

## Testing

Once the protobuf changes are in place:

1. Uncomment the metric reporting calls
2. Run the action with a builder that has cached data
3. Verify metrics are reported to the gRPC endpoint
4. Check that debug workers time is reasonable (typically < 5 seconds)
5. Verify prune bytes are correctly parsed and reported
26 changes: 25 additions & 1 deletion src/setup_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export async function startAndConfigureBuildkitd(
// Check that buildkit instance is ready by querying workers for up to 30s
const startTimeBuildkitReady = Date.now();
const timeoutBuildkitReady = buildkitdTimeoutMs;
let debugWorkersAvailableTime: number | undefined;

while (Date.now() - startTimeBuildkitReady < timeoutBuildkitReady) {
try {
Expand All @@ -247,9 +248,14 @@ export async function startAndConfigureBuildkitd(
// We only need 1 worker for setup-docker-builder
const requiredWorkers = 1;
if (lines.length > requiredWorkers) {
// Record and log the time when debug workers became available
debugWorkersAvailableTime = Date.now() - startTimeBuildkitReady;
core.info(
`Found ${lines.length - 1} workers, required ${requiredWorkers}`,
);
core.info(
`Debug workers became available after ${debugWorkersAvailableTime}ms`,
);
break;
}
} catch (error) {
Expand All @@ -272,6 +278,13 @@ export async function startAndConfigureBuildkitd(
`buildkit workers not ready after ${buildkitdTimeoutMs}ms timeout. Found ${lines.length - 1} workers, required ${requiredWorkers}`,
);
}
// If we didn't record the time earlier (edge case), record and log it now
if (!debugWorkersAvailableTime) {
debugWorkersAvailableTime = Date.now() - startTimeBuildkitReady;
core.info(
`Debug workers became available after ${debugWorkersAvailableTime}ms (after timeout check)`,
);
}
} catch (error) {
core.warning(
`Error checking buildkit workers: ${(error as Error).message}`,
Expand All @@ -292,9 +305,20 @@ export async function startAndConfigureBuildkitd(
export async function pruneBuildkitCache(): Promise<void> {
try {
const sevenDaysInHours = 7 * 24;
await execAsync(
const { stdout } = await execAsync(
`sudo buildctl --addr ${BUILDKIT_DAEMON_ADDR} prune --keep-duration ${sevenDaysInHours}h --all`,
);

// Log the prune output for analysis
if (stdout) {
core.info("BuildKit prune output:");
stdout.split("\n").forEach((line) => {
if (line.trim()) {
core.info(` ${line}`);
}
});
}

core.debug("Successfully pruned buildkit cache");
} catch (error) {
core.warning(`Error pruning buildkit cache: ${(error as Error).message}`);
Expand Down