Skip to content

Backend

Pradyuman edited this page Oct 26, 2024 · 13 revisions

Back-end of the CtrlB Control-Plane offers a set of APIs to control the associated agents. Currently the Back-end supports APIs to start, stop, update config, get current config and get current status. When an agent is initialized it registers itself to the back-end and informs about its configuration.

Database Operations

The Back-end uses SQLite to store the agent information and status into two tables.

        Untitled

  • The agents table stores the configuration of a particular agent, its type (fluent-bit/otel), version, hostname, and platform. While registering an agent, it assigns them an UUID as the primary key, and also a Name using its type, version and hostname.

  • The agent_info table stores the status of an agent at any particular time that includes its uptime, total data exported/lost and any status information.

Flow of Operation

  1. The back-end loads the env variables, specifically the Port to run and the worker count.
  2. Initializes the SQLite database - creates the agents table that stores the agent's registration data (name, type, version, hostname, platform and config), and also a agent_info table that stores agent's status when requested, containing data about the current status, exported data volume, uptime, and dropped records.
  3. Back-end initializes the agent queue with the worker count, and the agent repository with the db context. Agent repository is responsible for all the database communications (read/write).
  4. The agent service is initialized using the agent queue and agent repository. The agent services handles all the API request after being forwarded from the application routers.
  5. Back-end server starts running on the port specified by the env variable.

API Reference

API Endpoint Structure

Authentication APIs (authAPIsV1)

  • POST /api/auth/v1/register: Creates a new user registration.
  • POST /api/auth/v1/login: Authenticates the user.

Agent APIs (agentAPIsV1)

  • PUT /api/agent/v1/agents: Creates or updates an agent.

Frontend Agent APIs (frontendAgentAPIsV1)

Agents

  • GET /api/frontend/v1/agents: Fetches all agents.
  • GET /api/frontend/v1/agents/{id}: Fetches a specific agent by ID.
  • DELETE /api/frontend/v1/agents/{id}: Deletes a specific agent by ID.
  • POST /api/frontend/v1/agents/{id}/start: Starts the agent.
  • POST /api/frontend/v1/agents/{id}/stop: Stops the agent.
  • GET /api/frontend/v1/agents/{id}/metrics: Retrieves metrics for the agent.
  • POST /api/frontend/v1/agents/{id}/restart-monitoring: Restarts monitoring for the agent.

Pipelines

  • GET /api/frontend/v1/pipelines: Fetches all pipelines.
  • GET /api/frontend/v1/pipelines/{id}: Fetches a specific pipeline by ID.
  • DELETE /api/frontend/v1/pipelines/{id}: Deletes a specific pipeline.
  • POST /api/frontend/v1/pipelines/{id}/start: Starts the pipeline.
  • POST /api/frontend/v1/pipelines/{id}/stop: Stops the pipeline.
  • GET /api/frontend/v1/pipelines/{id}/metrics: Retrieves metrics for the pipeline.
  • POST /api/frontend/v1/pipelines/{id}/restart-monitoring: Restarts monitoring for the pipeline.

Configs

  • GET /api/frontend/v1/configs: Fetches all configs.
  • POST /api/frontend/v1/configs: Creates a new config.
  • GET /api/frontend/v1/configs/{id}: Fetches a specific config by ID.
  • DELETE /api/frontend/v1/configs/{id}: Deletes a specific config.
  • PATCH /api/frontend/v1/configs/{id}: Updates a specific config.

Environment Variables

To run the backend server, following environment variables shall be configured to the .env file

PORT: Port to use for running the collector agent ((No default value, this is required to be set)

WORKER_COUNT : Number of workers to run (No default value, this is required to be set)