Skip to content

API Reference

mirazola-ik edited this page Dec 9, 2025 · 5 revisions

API Reference

It documents the public application entry points and the internal modules used by the Serverless Runtime.

Main Application (app/main.py)

The FastAPI application is defined in app/main.py and configures logging, Prometheus metrics, and RabbitMQ consumer startup (when run directly).

Routes

  • GET /: Returns a string with the main route hint.
  • POST /control/stop-consuming: Gracefully stops the RabbitMQ consumer if running.
  • Router prefix /v1/faas: Additional FaaS endpoints provided by faas_router in app/api/v1/faas.py.

Runtime & Metrics

  • Initializes Prometheus metrics and starts a metrics HTTP server on port 9100.
  • Integrates Uvicorn logging with the custom CognitLogger (app/modules/_logger.py).
  • When executed directly (python app/main.py):
    • Starts a RabbitMQClient (app/modules/_rabbitmq_client.py) in a background thread.
    • Runs Uvicorn with host/port arguments.

CLI Arguments

  • --host (default 127.0.0.1): API host address.
  • --flavour (required): RabbitMQ queue name. Must match an existing FLAVOUR within the COGNIT framework.
  • --broker (required): RabbitMQ broker address.
  • --port (default 8000): API server port.

Core Modules

Internal modules are located under app/modules/ and implement logging, execution, parsing, storage, and messaging.

  • _logger.py: CognitLogger providing structured logging used across the runtime and integrated with Uvicorn.
  • _executor.py: Base execution logic for running offloaded functions (supports Python and C paths).
  • _pyexec.py: Extends the base executor with Python-specific execution behaviour.
  • _faas_parser.py: Serialization/deserialization of offloaded functions and returned results.
  • _minio_client.py: Client utilities for CRUD operations against MinIO.
  • _rabbitmq_client.py: RabbitMQ producer/consumer used to communicate with the Edge Cluster broker.

API Layer

Defined under app/api/v1/:

  • faas.py: Declares faas_router and exports Prometheus metrics and collectors consumed by main.py.
  • nano_pb2.py / nanopb_pb2.py: Protocol Buffer-related modules used for message or payload structures.

Data Models

Defined under app/models/:

  • faas.py: FaaS request/response data structures and internal communication models between function calls.
  • daas.py: DaaS-related models complementing FaaS flows.

Tests

Located under app/test/:

  • test_faas.py, test_pyexec.py, test_cexec.py, test_rabbitmq_client.py: Unit tests validating API and core module behaviours.

Entry Scripts

  • app/entrypoint.sh: Shell entrypoint for container or runtime startup sequencing.

Clone this wiki locally