---
metadata:
  - name: generator
    content: Diplodoc Platform v5.71.0
alternate:
  - https://ytsaurus.tech/docs/en/flow/contributor/flow-agent.md
  - https://ytsaurus.tech/docs/ru/flow/contributor/flow-agent.md
  - href: https://ytsaurus.tech/docs/en/flow/contributor/flow-agent.md
    type: text/markdown
    title: Markdown version
  - href: https://ytsaurus.tech/docs/en/llms.txt?revision=60d71fa73aad7d6925bf6544d501272ddd130efa
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://ytsaurus.tech/docs/en/llms.txt?revision=60d71fa73aad7d6925bf6544d501272ddd130efa

# Flow Agent

Flow Agent keeps an inventory of Flow pipelines for each configured target cluster and
periodically stores their status. It runs as the standalone `yt/yt/flow/bin/flow_agent`
binary. The agent discovers pipelines from the target cluster's snapshot export, polls
every discovered pipeline, and writes the results to a dynamic table. Read that table
directly to inspect the results.

## Configuration

The agent reaches every cluster through an RPC proxy. Credentials come from the
`YT_TOKEN` environment variable (and optionally `YT_USER`) and are shared by all clusters.
Do not put the token into the configuration file.

The required `state` section names the state cluster and the state root that hold the state of
all target clusters; the required `clusters` section lists the target clusters:

```yson
{
    state = {
        rpc_proxy = {cluster_url = "state-cluster";};
        root = "//home/flow-agent";
    };
    clusters = {
        cluster_a = {};
        cluster_b = {
            rpc_proxy = {cluster_url = "cluster-b.example.com";};
            agent = {poll_period = 60000;};
        };
    };
}
```

- The key of `clusters` is the target cluster name. `clusters.<name>.rpc_proxy` is optional:
  by default the agent connects to the cluster URL `<name>`.
- `clusters.<name>.agent` holds the polling options: `snapshot_period` and `poll_period`
  (five minutes by default), `scan_batch_size` (500 rows per inventory page and per snapshot export batch), and
  `poll_concurrency` (16 pipelines polled in parallel).
- `clusters.<name>.election_manager` holds the leader election options, except `lock_path`.
- State-cluster operations: inventory reads and writes and leader election.
- Target-cluster operations: the snapshot export read, the per-pipeline `get #<id>`, and
  `describe-pipeline`.
- All target clusters share one inventory table, `<root>/pipelines`; each cluster's rows
  carry its name in the `cluster` key column. Each target cluster has its own lock
  `<root>/agent_leader_locks/<cluster>` and leader, which reads and writes only the rows of
  its cluster. Both paths are derived from `state.root`; `election_manager.lock_path` must
  not be set.
- A configured cluster name must match `//sys/@cluster_connection/cluster_name` of the
  target cluster. A cluster that has not initialized yet is retried every
  `cluster_initialization_retry_period` (five seconds by default) and does not block the
  other clusters.

## Inventory table {#inventory-table}

| Column | Type | Description |
|---|---|---|
| `cluster` | `string`, key | Target cluster name, the key in `clusters`. |
| `pipeline_id` | `string`, key | Cypress object ID of the pipeline. |
| `live_path` | `string` | Current pipeline path. |
| `pipeline_format_version` | `int64` | Pipeline format marker. |
| `pipeline_name` | `string` | Pipeline name, if known. |
| `summary` | `any` | Last full result: status returned by `describe-pipeline` with `status_only=%true`. |
| `last_successful_poll_time` | `int64` | Time when `summary` was received, in microseconds. |
| `partial_summary` | `any` | Last partial result; null after a full result. |
| `partial_poll_time` | `int64` | Time when `partial_summary` was received, in microseconds. |
| `poll_error` | `any` | Last poll error; null after a full or partial result. |
| `poll_error_time` | `int64` | Time when `poll_error` was received, in microseconds. |
| `access_denied` | `boolean` | Whether the agent's user lacks `read` permission on the pipeline. |

The leader reads every new export referenced by `//sys/admin/snapshots/snapshot_exports/latest`.
The export must contain the `id`, `path`, `pipeline_format_version`,
`cypress_transaction_id`, and `orphaned` columns. The `pipeline_name` column is
optional: if it is missing, the agent does not overwrite stored names. Every node with an
integer `pipeline_format_version` is a pipeline; an unsupported version shows up as a poll
error. Data freshness is bounded by the export period.

Each new export fully syncs the rows of its cluster: the leader upserts every exported
pipeline and deletes the cluster's rows absent from the export. After a leader change the
latest export is applied again, so the row of a pipeline deleted since that export may
reappear until the next poll.

The export is the standard master snapshot export produced by the YT cluster, not by the
agent: after each master snapshot, the cluster writes rows of Cypress nodes with a
whitelisted set of attributes under `//sys/admin/snapshots/snapshot_exports`, and `latest`
points to the newest export. The agent only reads it. The `pipeline_format_version`
attribute, and optionally `pipeline_name`, must be in the export attribute whitelist of the
target cluster; the cluster administrators configure it.


Polling deletes the row of a pipeline that no longer exists or no longer carries the
Flow pipeline marker. Each poll result goes to one of three layers:

- Full: `describe-pipeline` returns a complete description built from the controller's flow
  view (`partial` is `%false` or absent). The agent writes `summary` and clears the partial and
  error layers.
- Partial: the controller responds with `partial=%true` because it has no flow view yet, for
  example right after a start, or
  the agent reads the pipeline node, but `describe-pipeline` fails, for example because the
  controller is stopped or unreachable. In the first case, `partial_summary` is the
  controller's response; in the second case, it is a map with `live_path`, `pipeline_name`,
  `leader_controller_address` (if the controller has published it), and `describe_error`. The
  agent keeps `summary` and clears the error layer.
- Error: the agent cannot read the pipeline node, `read` on it is denied, or the response is
  malformed. The agent writes `poll_error` and keeps `summary` and `partial_summary`.

## Inaccessible pipelines

The agent's user may lack `read` permission on some pipelines. The agent keeps such
pipelines in the inventory and sets `access_denied=%true`. Their path and name come
from the snapshot export, and `summary` keeps its last known value. `access_denied` is set
only when the error denies `read` on the object itself. Other authorization errors, such
as a missing permission on an RPC proxy role, do not change `access_denied`. After
access is granted, the next successful `get` sets `access_denied=%false`.

## Who can see the state

Anyone who can read the inventory table sees the paths, names, statuses, controller
messages and addresses, authentication data, and errors of all inventoried pipelines, regardless of the
target clusters' ACLs. Grant `read` on the state root only to a trusted group.
ACLs are inherited from the state root; the agent does not set them.

## State initialization

Before the first start, a user with `mount` permission on the state root creates the
state. Each target cluster's agent creates its own lock node
`<root>/agent_leader_locks/<cluster>`, so the state does not depend on the list of target
clusters.


Create the following objects by hand, without setting ACLs:

- the `<root>/pipelines` sorted dynamic table with the schema from the
  [Inventory table](#inventory-table) section: key columns `cluster` and `pipeline_id`,
  strict schema, unique keys; mount the table;
- the `<root>/agent_leader_locks` map node.


The agent's user does not need `mount`, so after bundle maintenance the table is
remounted by a person.

Preconditions:

- the agent's user has `read`, `write`, and `remove` on the state root;
- the agent's user has `use` on the tablet cell bundle;
- the account of the state root has tablet quota;
- the agent's user can read the snapshot export on every target cluster.

## Diagnostics

The agent has no RPC API. Component status is published in Orchid on the monitoring HTTP
port under `/orchid/clusters/<cluster>/{status,polling,snapshot_reconciliation}`.
