task-record-replay

Benchmarks and profiles KHI DAG tasks using record-and-replay fixtures with pprof analysis.

2.1k|97|Updated Jan 22, 2025
One-click install
npx skills add https://github.com/GoogleCloudPlatform/khi --skill task-record-replay-googlecloudplatform
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: task-record-replay
Source: https://github.com/GoogleCloudPlatform/khi/tree/main/.agents/skills/task_record_replay
Command: npx skills add https://github.com/GoogleCloudPlatform/khi --skill task-record-replay-googlecloudplatform

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Benchmarking individual KHI inspection tasks is difficult because they run inside a concurrent DAG with external dependencies like the Cloud Logging API, making measurements noisy and slow. This Skill provides recipes to isolate a single task, record its upstream inputs as fixtures, and replay them for fast, repeatable microbenchmarks and pprof profiling. ## Core Features & Use Cases - Record & Replay Benchmarks: Capture live upstream task output as JSON fixtures with KHI_RECORD_TASK_RESULTS=1, then replay them offline via JobTestHarness without GCP credentials. - Task Isolation: Configure JobTestConfig with RecordedTasks and TargetTask to benchmark exactly one task (log ingester, log grouper, or timeline mapper) without downstream execution. - CPU & Memory Profiling: Generate pprof CPU and heap profiles scoped strictly to the target task using KHI_TASK_CPUPROFILE and KHI_TASK_MEMPROFILE. - Use Case: You want to reduce allocations in the Kubernetes audit log ingester. Record the upstream log query task once, then run go test -bench locally to measure ns/op and allocs/op improvements after each optimization. ## Quick Start Ask the AI to create a benchmark for a specific KHI task using the JobTestHarness boilerplate, then record fixtures and run the benchmark with profiling enabled.

Frequently Asked Questions about task-record-replay

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I benchmark a single KHI inspection task?▼

Use taskrecord.NewJobTestHarness with a JobTestConfig that lists upstream tasks in RecordedTasks and the task under test in TargetTask. Run with KHI_RECORD_TASK_RESULTS=1 once to capture fixtures, then replay with go test -bench for fast local benchmarks.

How to generate a pprof CPU profile for one Go task?▼

Set KHI_TASK_CPUPROFILE=1 when running the benchmark to write a CPU profile scoped strictly to TargetTask execution into pprof/<BenchmarkName>/cpu.pprof. Analyze it with go tool pprof -http=:8080.

Can KHI benchmarks run without GCP credentials?▼

Yes, replay mode runs fully offline using previously recorded JSON fixtures. Run make download-fixtures to pull cached fixtures from gs://khi-fixtures, then execute go test -bench without any Cloud Logging credentials.

Why does the benchmark fail with fixture file not found?▼

The JSON fixture has not been downloaded or recorded yet. Run make download-fixtures to fetch cached fixtures from GCS, or record new ones with KHI_RECORD_TASK_RESULTS=1 using live GCP credentials.

Should unit tests depend on taskrecord fixtures?▼

No, fixtures and JobTestHarness are intended only for local benchmarks (Benchmark*) and performance analysis. Standard unit tests (Test*) must not depend on external fixture files.