How skyapm/r3 works
Project Type & Purpose
• R3 is a backend-focused microservice that provides REST endpoint pattern recognition via a gRPC/HTTP API.
• It bundles a core algorithm (URIDrain) under models/uri_drain, a simple multiprocess server in servers/simple, and demo/test clients.
• It supports containerized deployment (Dockerfile, demo/docker-compose) and local Python execution.
File Structure
Top-level components:
• models/uri_drain: the core ML/log-clustering algorithm and its config, masking, template miner, persistence, and post-processing modules.
• servers/simple: a producer-consumer multiprocessing server exposing the gRPC/HTTP endpoint, worker processes, results manager, and configuration (uri_drain.ini).
• servers/protos: gRPC service definition (ai_http_uri_recognition.proto).
• demo: sample URIs, Python scripts (demo_big_file_uri.py, demo_gradio.py), and a Docker Compose for stress testing.
• test & servers/tests: E2E and unit tests, mock clients, expected outputs.
• Tools & config: tools/grpc_gen.py (auto-gen from proto), Dockerfile, CI workflows, Makefile, pyproject.toml & Poetry.
Key Architectural Insights from README
• The service exposes a gRPC/HTTP interface (port 17128) to classify URIs into patterns.
• A simple multiprocess design: a producer feeds incoming URIs into a queue; multiple workers consume, apply URIDrain, and send results to a ResultsManager.
• Persistence is pluggable (handlers in persistence_handler.py) and can log/record patterns.
Main Components & Their Interactions
a. Clients & Entry Points
• gRPC/HTTP client (in-production SkyWalking pipeline or demo scripts).
• E2E test client (test/e2e/client.py).
b. API Layer (servers/simple/run.py → server.py)
• Listens on port 17128, decodes incoming requests via generated gRPC stubs.
• Publishes URI strings into a multiprocessing Queue.
c. Worker Pool (servers/simple/worker.py)
• Each worker pulls URIs from the Queue, invokes models/uri_drain.uri_drain.URI_Drain to detect patterns, and forwards results to ResultsManager.
d. Core Algorithm (models/uri_drain/*)
• Word splitting, masking, template mining, post-processing (NLTK), and persistence.
• Configurable via template_miner_config.py and uri_drain.ini.
e. Results Manager & Persistence (servers/simple/results_manager.py & models/uri_drain/persistence_handler.py)
• Aggregates results, writes to storage or in-memory structures.
f. Demo & Testing
• Gradio demo (demo/demo_gradio.py) for interactive algorithm exploration.
• Bulk URI processing script (demo/demo_big_file_uri.py).
• Automated E2E Docker Compose harness.
Important Architectural Patterns & Principles
• Producer-consumer multiprocessing for concurrency and isolation.
• Layered separation: API layer, processing layer, persistence layer.
• Pluggable modules: algorithm steps can be extended via add_ons/ and template_miner_config.py.
• Container-first deployment: Dockerfile + CI pipeline for image publishing.
• Strict interface definition via Protocol Buffers.