Agent adapters

This page describes the extension points for telemetry sources and collector destinations. It is for contributors changing the Tier source tree. Adapters are not dynamically loaded plugins: a collector sink must be compiled into tier-agent, and a separately built adapter cannot be installed and enabled at runtime.

Current status

  • The agent can run a periodic source command.
  • The collector registers only the built-in local file store as a sink. There are no built-in Prometheus, InfluxDB, or OTLP sinks yet.
  • The query socket and the web dashboard read from the local store; a new sink does not automatically become visible through them.
  • persistence = "keeper" is accepted by the config parser but ignored; it does not enable a Keeper backend.

Telemetry source

To collect data from another local program, set the agent's exec. The command runs periodically and its standard output is parsed as one sample per line (see Samples). Keys and values are strings. The packaged host-metrics.sh is a working example. This is a command-line integration, not a storage adapter, and delivery stays online-only.

Collector sink

Implement a C++ class deriving from tier::agent::Sink in apps/agent/src/sink.hpp. The collector calls write(sender_hex, envelope) for each accepted telemetry envelope, after message-type filtering, the accept_from check, duplicate filtering, and envelope decoding.

  • sender_hex is the authenticated sender's Tier user ID in hexadecimal.
  • Envelope holds a sender sequence number, a capture timestamp, and samples. Each sample has a kind (gauge or event), a key, and an opaque string value.
  • Gauges are the latest value per sender and key; events are append-only history. An adapter must document how it maps these semantics to its backend.
#include <string>

#include "sink.hpp"

namespace tier::agent {

class ExampleSink final : public Sink {
 public:
  void write(const std::string& sender_hex,
             const Envelope& envelope) override;
  void flush() override;
};

}  // namespace tier::agent

Contract

  • write() runs synchronously on the collector's receive loop. Do not block on network I/O there: use a bounded, drop-oldest queue and a worker for remote backends.
  • write() has no error return. Make drops and backend failures observable.
  • flush() is called during collector shutdown. Workers must stop cleanly, and shutdown flushing should have a bounded wait.
  • Delivery is not exactly-once: agents do not spool while offline, and the duplicate filter is bounded in-memory state. Do not promise durable retries or exactly-once delivery unless the adapter implements and tests them.
  • Treat keys and values as input data, not backend syntax: escape or encode them for the target protocol, and do not assume gauge values are numeric.

Add a sink to Tier

  1. Add the implementation under apps/agent/src/ and its source file to apps/agent/CMakeLists.txt.
  2. If operators configure it, add typed fields to Config, parse and validate them in config.cpp, update apps/agent/integrations/collector.toml and apps/agent/tier-agent.example.toml, and add parser tests. Do not commit credentials; document a safe way to provide secrets.
  3. Construct the sink in run_collector() in apps/agent/src/main.cpp and add it to the sinks collection next to the local store. It must stay alive until all calls to write() and flush() have completed.
  4. Add focused tests: sample-to-backend mapping, queue bounds and drops, shutdown flushing, configuration validation, and backend failures. Prefer a local mock endpoint to a live service.
  5. Build tier-agent, run the relevant CTest tests, and document setup, configuration, limitations, and verification.
std::vector<tier::agent::Sink*> sinks{&store};
sinks.push_back(&remote_sink);

remote_sink must be constructed in the same scope as store and live for the whole collector loop.

Build and test

git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build build --target tier-agent test_agent_core -j2
ctest --test-dir build --output-on-failure

Add adapter tests to tests/ and register them in tests/CMakeLists.txt. Use a mock backend so tests need no external services or credentials.

Contribution ideas

Possible independent contributions, not commitments or supported features:

  • Prometheus remote-write sink
  • OTLP metrics sink
  • InfluxDB line-protocol sink
  • More source-command examples for common host metrics

Before implementing a remote sink, describe its mapping for gauges and events, configuration and secret handling, retry and drop behavior, and how operators can verify delivery.