> ## Documentation Index
> Fetch the complete documentation index at: https://docs.akua.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Parallel Log Analysis

> 35,000 log lines across 11 containers in 506ms, one tool call

<Frame>
  <img className="block dark:hidden" src="https://mintcdn.com/akua-1dce587a/AEEz0U2s7Do2sYaM/images/heros/ai-parallel-log-analysis-light.svg?fit=max&auto=format&n=AEEz0U2s7Do2sYaM&q=85&s=2e83163ae8fb833c3f3aa632b9b22b0a" alt="One execute call in a sandbox fanning out to many parallel pod log streams and folding them into a single ranked summary of 35,498 lines across 11 containers" width="1536" height="864" data-path="images/heros/ai-parallel-log-analysis-light.svg" />

  <img className="hidden dark:block" src="https://mintcdn.com/akua-1dce587a/AEEz0U2s7Do2sYaM/images/heros/ai-parallel-log-analysis-dark.svg?fit=max&auto=format&n=AEEz0U2s7Do2sYaM&q=85&s=5089d38deb0f250fb1d8830e0c909d31" alt="One execute call in a sandbox fanning out to many parallel pod log streams and folding them into a single ranked summary of 35,498 lines across 11 containers" width="1536" height="864" data-path="images/heros/ai-parallel-log-analysis-dark.svg" />
</Frame>

An agent asked to "count log lines across all pods in my cluster" produced this in a single `execute` call. No sequential tool calls, no raw logs in the context window.

<Frame caption="One execute call: listed all pods, fetched logs from 11 containers in parallel, counted 35,498 lines, and returned a sorted summary, in 506ms.">
  <img src="https://mintcdn.com/akua-1dce587a/EmuDFPjYhQISRlUo/images/ai/code-mode-parallel-logs.png?fit=max&auto=format&n=EmuDFPjYhQISRlUo&q=85&s=c3397031211a8963ba45075f01b9387e" alt="Agent counting log lines across all pods in a single Code Mode execution" width="2048" height="1416" data-path="images/ai/code-mode-parallel-logs.png" />
</Frame>

## The Numbers

| Metric                               | Value     |
| ------------------------------------ | --------- |
| Total time                           | **506ms** |
| List all pods                        | 139ms     |
| Parallel log fetches (11 containers) | 367ms     |
| Total log lines counted              | 35,498    |
| API calls made inside sandbox        | 12        |
| Tool calls seen by the LLM           | **1**     |

The agent even self-instrumented the timing with `Date.now()` inside the sandbox.

## The Code

```js expandable theme={null}
async () => {
  const clusterId = "cls_abc123"; // resolved by the agent from conversation

  const kube = (path) => platform.request({
    method: "GET",
    path: `/v1/clusters/${clusterId}/kube_proxy/${path}`
  }).then(r => r.body);

  // Get all pods across all namespaces
  const allPods = await kube("api/v1/pods");

  // Fetch logs for all running containers in parallel
  const results = await Promise.all(
    allPods.items
      .filter(p => p.status.phase === "Running")
      .flatMap(p =>
        p.spec.containers.map(c => ({
          namespace: p.metadata.namespace,
          pod: p.metadata.name,
          container: c.name
        }))
      )
      .map(async ({ namespace, pod, container }) => {
        try {
          const logs = await kube(
            `api/v1/namespaces/${namespace}/pods/${pod}/log?container=${container}`
          );
          const lines = typeof logs === "string"
            ? logs.split("\n").filter(Boolean).length : 0;
          return { namespace, pod, container, lines };
        } catch {
          return { namespace, pod, container, lines: 0, error: true };
        }
      })
  );

  const total = results.reduce((sum, r) => sum + r.lines, 0);
  results.sort((a, b) => b.lines - a.lines);
  return { total_lines: total, per_pod: results };
}
```

## Why this matters

With traditional MCP tools, this would be 12+ sequential round trips: one to list pods, then one per container to fetch logs. Each round trip adds network latency, and every raw response gets dumped into the LLM's context window.

Code Mode does it in **one** tool call. The agent's code filters, aggregates, and formats the data inside the sandbox before returning. Only the summary hits the context window, not 35,000 lines of raw logs.

## What the agent does

1. Lists all pods across all namespaces
2. Filters for running pods, expands to per-container list
3. Fans out `Promise.all()` across 11 log fetches in parallel
4. Counts lines per container, handles errors gracefully
5. Sorts by line count, returns a clean summary

The heaviest pod (api-proxy, 24,828 lines) took 367ms. Small pods (\~10 lines) came back in \~89ms. The parallel fan-out means total time equals the slowest fetch, not the sum.

## Related topics

<CardGroup cols={2}>
  <Card title="Code Mode in action" icon="bolt" href="/ai/code-mode-in-action">
    More examples of the parallel fan-out pattern.
  </Card>

  <Card title="Incident debugging" icon="bug" href="/ai/examples/incident-debugging">
    Adaptive SRE triage: logs, events, rollout history.
  </Card>

  <Card title="Resource audit" icon="gauge" href="/ai/examples/resource-audit">
    Cluster-wide CPU and memory report in a single API call.
  </Card>

  <Card title="Kubernetes access" icon="dharmachakra" href="/ai/kubernetes-access">
    The kube proxy log endpoint used in this example.
  </Card>
</CardGroup>
