Skip to content

Commit e8457ea

Browse files
authored
Merge pull request ait-detectmate#14 from annaerdi/docs
Add documentation
2 parents 550604f + b366f84 commit e8457ea

12 files changed

Lines changed: 427 additions & 21 deletions

File tree

.github/workflows/publish-docs.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish Docs
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
deploy:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Set up uv (Python 3.12)
17+
uses: astral-sh/setup-uv@v5
18+
with:
19+
python-version: "3.12"
20+
enable-cache: true
21+
22+
- name: Install dependencies
23+
run: uv pip install -e .[dev]
24+
25+
- name: Configure Git user
26+
run: |
27+
git config --global user.name "${{ github.actor }}"
28+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
29+
30+
- name: Deploy docs
31+
run: |
32+
# Extract version from tag (remove 'v' prefix if present)
33+
VERSION=${GITHUB_REF_NAME#v}
34+
echo "Deploying version $VERSION"
35+
uv run mike deploy --push --update-aliases $VERSION latest
36+
# Optional: make the released version the default shown when visiting the site
37+
# it's enough to run this once
38+
# uv run mike set-default --push latest

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ service = DemoService()
5858

5959
with service:
6060
with pynng.Req0(dial=service.settings.manager_addr) as req:
61-
for cmd in ("ping", "status", "pause", "status", "resume", "status", "stop"):
61+
for cmd in ("ping", "status", "stop"):
6262
print(f">>> {cmd}")
6363
req.send(cmd.encode("utf-8"))
6464
reply = req.recv().decode("utf-8", "ignore")
@@ -75,17 +75,7 @@ Example configuration files can be found in the `tests/config` directory.
7575
Start the service:
7676

7777
```bash
78-
detectmate start --settings tests/config/service_settings.yaml --config tests/config/detector_config.yaml
79-
```
80-
81-
Reconfigure the service:
82-
83-
```bash
84-
# Update parameters in memory only
85-
detectmate reconfigure --settings tests/config/service_settings.yaml --config tests/config/new_config.yaml
86-
87-
# Update parameters and persist to file. This overwrites the originally provided config file.
88-
detectmate reconfigure --settings tests/config/service_settings.yaml --config tests/config/new_config.yaml --persist
78+
detectmate start --settings tests/config/service_settings.yaml
8979
```
9080

9181
Get the service status:

demo/docker-compose.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ services:
33
build:
44
context: ..
55
dockerfile: demo/Dockerfile
6-
args:
7-
GITHUB_TOKEN: ${GITHUB_TOKEN} # must be set in .env or export
86
container_name: detectmate_reader
97
command: >
108
detectmate start
@@ -22,8 +20,6 @@ services:
2220
build:
2321
context: ..
2422
dockerfile: demo/Dockerfile
25-
args:
26-
GITHUB_TOKEN: ${GITHUB_TOKEN}
2723
container_name: detectmate_parser
2824
command: >
2925
detectmate start
@@ -44,8 +40,6 @@ services:
4440
build:
4541
context: ..
4642
dockerfile: demo/Dockerfile
47-
args:
48-
GITHUB_TOKEN: ${GITHUB_TOKEN}
4943
container_name: detectmate_detector
5044
command: >
5145
detectmate start
@@ -65,8 +59,6 @@ services:
6559
build:
6660
context: ..
6761
dockerfile: demo/Dockerfile
68-
args:
69-
GITHUB_TOKEN: ${GITHUB_TOKEN}
7062
container_name: detectmate_demo
7163
command: python demo/manual_demo_run_tcp.py
7264
volumes:

docs/configuration.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Configuration
2+
3+
DetectMateService can be configured using a YAML settings file or environment variables. Environment variables take precedence over the YAML file.
4+
5+
## Service settings
6+
7+
These settings control the service infrastructure.
8+
9+
| Setting | Env Variable | Default | Description |
10+
| :---------------------------- | :--------------------------------------- | :--------------------------------- |:----------------------------------------------------------------------------------------------------------|
11+
| `component_name` | `DETECTMATE_COMPONENT_NAME` | `None` | A human-readable name for the service instance. |
12+
| `component_id` | `DETECTMATE_COMPONENT_ID` | `None` (computed) | Unique identifier for the component; computed automatically if not provided. |
13+
| `component_type` | `DETECTMATE_COMPONENT_TYPE` | `core` | Python import path for the component class (e.g., `detectors.MyDetector`). |
14+
| `component_config_class` | `DETECTMATE_COMPONENT_CONFIG_CLASS` | `None` | Python import path of the configuration class used by the component (e.g., `detectors.MyDetectorConfig`). |
15+
| `log_level` | `DETECTMATE_LOG_LEVEL` | `INFO` | Logging level (`DEBUG`, `INFO`, `WARNING`, `ERROR`). |
16+
| `log_dir` | `DETECTMATE_LOG_DIR` | `./logs` | Directory for log files. |
17+
| `log_to_console` | `DETECTMATE_LOG_TO_CONSOLE` | `true` | Whether logs are written to stdout/stderr. |
18+
| `log_to_file` | `DETECTMATE_LOG_TO_FILE` | `true` | Whether logs are written to files in `log_dir`. |
19+
| `manager_addr` | `DETECTMATE_MANAGER_ADDR` | `ipc:///tmp/detectmate.cmd.ipc` | Address for management commands (REQ/REP). |
20+
| `manager_recv_timeout` | `DETECTMATE_MANAGER_RECV_TIMEOUT` | `100` | Receive timeout (ms) for the manager command channel. |
21+
| `manager_thread_join_timeout` | `DETECTMATE_MANAGER_THREAD_JOIN_TIMEOUT` | `1.0` | Timeout (s) when waiting for the manager thread to stop. |
22+
| `engine_addr` | `DETECTMATE_ENGINE_ADDR` | `ipc:///tmp/detectmate.engine.ipc` | Address for data processing (PAIR0/1). |
23+
| `engine_autostart` | `DETECTMATE_ENGINE_AUTOSTART` | `true` | Whether the engine channel is started automatically. |
24+
| `engine_recv_timeout` | `DETECTMATE_ENGINE_RECV_TIMEOUT` | `100` | Receive timeout (ms) for the engine channel. |
25+
| `out_addr` | `DETECTMATE_OUT_ADDR` | `[]` | List of output addresses (strongly typed NNG URLs). |
26+
| `out_dial_timeout` | `DETECTMATE_OUT_DIAL_TIMEOUT` | `1000` | Timeout (ms) for connecting to output addresses. |
27+
28+
29+
### YAML files
30+
31+
You can provide a YAML file containing the service settings. Below is an example `settings.yaml`:
32+
33+
```yaml
34+
component_name: "my-detector"
35+
log_level: "DEBUG"
36+
log_dir: "./logs"
37+
38+
# Manager Interface (Command Channel)
39+
manager_addr: "ipc:///tmp/detectmate.cmd.ipc"
40+
41+
# Engine Interface (Data Channel)
42+
engine_addr: "ipc:///tmp/detectmate.engine.ipc"
43+
engine_autostart: true
44+
45+
# Output Destinations (where processed data is sent)
46+
out_addr:
47+
- "tcp://127.0.0.1:5000"
48+
- "ipc:///tmp/output.ipc"
49+
50+
out_dial_timeout: 1000
51+
```
52+
53+
54+
### Environment variables
55+
56+
Environment variables override values in the YAML file. They are prefixed with `DETECTMATE_`.
57+
58+
Example:
59+
```bash
60+
export DETECTMATE_LOG_LEVEL=DEBUG
61+
export DETECTMATE_COMPONENT_NAME=worker-1
62+
detectmate start
63+
```
64+
65+
## Component configuration
66+
67+
In addition to the service settings (which configure the *runner*), you can also pass a separate configuration file for the specific component logic (e.g., detector parameters) using the `--config` flag in the CLI. This file is specific to the implementation of the component you are running.
68+
69+
70+
71+
```yaml
72+
# detector-config.yaml
73+
threshold: 0.85
74+
sensitivity: high
75+
enabled: true
76+
```
77+
78+
You can read more about Components in the [Using a Library Component](library.md) section.

docs/index.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# DetectMate Service Framework
2+
3+
Welcome to the DetectMate Service Framework documentation. DetectMate is a flexible, component-based framework for
4+
building distributed detection and processing services.
5+
6+
It uses NNG's messaging architecture to process data in real-time.
7+
8+
## Key features
9+
10+
- **Modular design**: easily extensible with custom processors and components.
11+
- **Resilient networking**: built on top of [`pynng`](https://pynng.readthedocs.io/en/latest/) (NNG) for high-performance messaging.
12+
- **Configurable**: fully configurable via YAML files or environment variables.
13+
- **Service management**: built-in CLI for starting, stopping, and monitoring the service.
14+
- **Scalable**: run multiple independent service instances.
15+
16+
## Getting started
17+
18+
Check out the [Installation](installation.md) guide to set up the service, and then proceed to
19+
[Configuration](configuration.md) and [Usage](usage.md) to learn how to run it.

docs/installation.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Installation
2+
3+
First, clone DetectMateService and navigate into the repository:
4+
5+
```bash
6+
git clone https://github.com/ait-detectmate/DetectMateService.git
7+
cd DetectMateService
8+
```
9+
10+
## Setup with uv (recommended)
11+
12+
We recommend using [uv](https://github.com/astral-sh/uv) to manage the environment
13+
and dependencies.
14+
15+
### 1. Create and activate a virtual environment with uv
16+
17+
```bash
18+
uv venv
19+
source .venv/bin/activate
20+
```
21+
22+
### 2. Install the project
23+
24+
```bash
25+
uv pip install .
26+
```
27+
28+
## Alternative setup with pip
29+
30+
If you prefer plain `pip`, you can set things up like this instead:
31+
32+
```bash
33+
# Create a virtual environment
34+
python -m venv .venv
35+
# Activate it
36+
source .venv/bin/activate
37+
# Install the project in editable mode with dev dependencies
38+
pip install .
39+
```
40+
41+
42+
## Developer setup
43+
44+
For development, you can install with optional dependencies:
45+
46+
```bash
47+
pip install -e ".[dev]"
48+
```
49+
50+
We recommend using [`prek`](https://github.com/j178/prek) to manage Git
51+
pre-commit hooks. `prek` is configured via the existing `.pre-commit-config.yaml`
52+
and can be installed as part of the `dev` extras. To ensure pre-commit hooks run before each commit, run:
53+
```bash
54+
prek install
55+
```

docs/library.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
## Using a Library Component
2+
3+
The Service can be run as any component imported from the [DetectMateLibrary](https://github.com/ait-detectmate/DetectMateLibrary).
4+
For this, ensure that the library is installed in the same activated virtual environment, where the service is installed.
5+
6+
### 1. Update settings
7+
8+
Modify `settings.yaml` to use a library component:
9+
10+
```yaml
11+
component_name: random-detector
12+
component_type: detectors.RandomDetector
13+
component_config_class: detectors.RandomDetectorConfig
14+
config_file: detector-config.yaml
15+
log_level: INFO
16+
manager_addr: ipc:///tmp/detectmate.cmd.ipc
17+
engine_addr: ipc:///tmp/detectmate.engine.ipc
18+
```
19+
20+
### 2. Create component configuration
21+
22+
Create `detector-config.yaml`:
23+
24+
```yaml
25+
threshold: 0.75
26+
window_size: 10
27+
enabled: true
28+
```
29+
30+
### 3. Start with configuration
31+
32+
```bash
33+
detectmate start --settings settings.yaml --config detector-config.yaml
34+
```
35+
36+
### 4. Reconfigure at runtime
37+
38+
Create `new-config.yaml`:
39+
40+
```yaml
41+
threshold: 0.85
42+
window_size: 15
43+
enabled: true
44+
```
45+
46+
The service supports dynamic reconfiguration with two modes:
47+
48+
#### 1. In-memory update (default)
49+
Changes are applied to the running service but not saved to disk. The changes will be lost when the service restarts.
50+
51+
```bash
52+
detectmate reconfigure --settings settings.yaml --config new-config.yaml
53+
```
54+
55+
#### 2. Persistent update (with --persist flag)
56+
Changes are applied to the running service AND saved to the original parameter file. The changes persist across service restarts.
57+
58+
```bash
59+
detectmate reconfigure --settings settings.yaml --config new-config.yaml --persist
60+
```
61+
62+
**Note:** The `--persist` flag will overwrite the original parameter file specified in your service configuration with the new values from the `--params` file.

docs/pipeline.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Running the Docker Pipeline
2+
3+
There is a containerized demonstration of the DetectMate log analysis pipeline. The demo runs three services (reader, parser,
4+
detector) that process audit logs to detect anomalies, with a test script that feeds log lines through the complete
5+
pipeline and reports detected anomalies. Each component runs in its own Docker container and the components communicate via TCP.
6+
7+
This document explains how to run the example pipeline using Docker, located in the `demo` folder.
8+
9+
10+
## Components
11+
12+
The pipeline consists of the following services defined in `demo/docker-compose.yml`:
13+
14+
1. **Reader (`detectmate_reader`)**:
15+
* reads log lines from a source file (`demo/data/audit.log`)
16+
* uses `demo/config/reader_config.yaml`
17+
* listens on internal port **8001**
18+
19+
2. **Parser (`detectmate_parser`)**:
20+
* receives raw log data, parses it into a structured format
21+
* uses `demo/config/parser_config.yaml`
22+
* listens on internal port **8011**
23+
* depends on the Reader
24+
25+
3. **Detector (`detectmate_detector`)**:
26+
* analyzes structured logs to detect anomalies
27+
* uses `demo/config/detector_config.yaml`
28+
* listens on internal port **8021**
29+
* depends on the Parser
30+
31+
4. **Demo Driver (`detectmate_demo`)**:
32+
* Acts as the orchestrator/client. It executes the `demo/manual_demo_run_tcp.py` script. It does the following:
33+
1. count lines in the audit log
34+
2. for each line, it sends a request to the **Reader** to get a log line
35+
3. forwards the log line to the **Parser** for processing
36+
4. forwards the parsed data to the **Detector** for analysis
37+
5. prints any detected anomalies to the console
38+
39+
40+
## How to Run
41+
42+
Prerequisites: **Docker** and **Docker Compose** installed.
43+
44+
**Terminal 1** (keep running to see service logs):
45+
```bash
46+
cd demo
47+
docker compose up reader parser detector
48+
```
49+
50+
**Terminal 2** (run after services are up):
51+
```bash
52+
cd demo
53+
docker compose up demo
54+
```
55+
56+
57+
## Directory Structure
58+
59+
* `demo/Dockerfile`: The Docker definition used by all services.
60+
* `demo/docker-compose.yml`: Defines the multi-container application.
61+
* `demo/config/`: Contains YAML configuration files for Reader, Parser, and Detector.
62+
* `demo/data/`: Contains sample data (e.g., `audit.log`) used by the Reader.
63+
* `demo/manual_demo_run_tcp.py`: The Python script running inside the `demo` container that drives the flow.

0 commit comments

Comments
 (0)