Skip to content

Commit b4bc0bd

Browse files
committed
Add services
1 parent 9f2590d commit b4bc0bd

26 files changed

+1143
-21
lines changed

.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# App config
2+
export CONFIG_PATH=./config/config.toml
3+
4+
# RabbitMQ
5+
export RABBITMQ_USER=admin
6+
export RABBITMQ_PASSWORD=admin

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ dmypy.json
7575
# IDE
7676
.idea/
7777
.vscode/
78+
79+
# config
80+
config/config.toml

.pre-commit-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ repos:
2323
- id: mixed-line-ending
2424
- id: trailing-whitespace
2525

26-
- repo: https://github.com/python-formate/flake8-dunder-all
27-
rev: v0.4.0
28-
hooks:
29-
- id: ensure-dunder-all
30-
exclude: "tests*"
31-
args: ["--use-tuple"]
32-
3326
- repo: https://github.com/astral-sh/ruff-pre-commit
3427
rev: v0.4.4
3528
hooks:

Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Use the official Python image as the base image
2+
FROM python:3.12-slim-bookworm as python-base
3+
4+
# Set environment variables to non-interactive
5+
ENV PYTHONUNBUFFERED=1 \
6+
PYTHONDONTWRITEBYTECODE=1 \
7+
PIP_NO_CACHE_DIR=off \
8+
PIP_DISABLE_PIP_VERSION_CHECK=on \
9+
PIP_DEFAULT_TIMEOUT=100 \
10+
PDM_HOME="/opt/pdm" \
11+
PDM_PEP582="1" \
12+
PYSETUP_PATH="/opt/pysetup" \
13+
VENV_PATH="/opt/pysetup/.venv" \
14+
PYTHONPATH="/app"
15+
16+
# Update PATH to include PDM and the virtual environment binaries
17+
ENV PATH="$PDM_HOME/bin:$VENV_PATH/bin:$PATH"
18+
19+
# Setup the builder base with system dependencies
20+
FROM python-base as builder-base
21+
RUN apt-get update && apt-get install -y git curl
22+
23+
# Setup work directory and copy pyproject.toml (PDM uses the same pyproject.toml as Poetry)
24+
WORKDIR $PYSETUP_PATH
25+
26+
# Copy dependencies
27+
COPY ./pyproject.toml .
28+
COPY ./pdm.lock .
29+
30+
RUN pip install --no-cache-dir --upgrade pip \
31+
&& pip install --no-cache-dir setuptools wheel \
32+
&& pip install --no-cache-dir pdm
33+
34+
# Install dependencies using PDM
35+
RUN pdm install --check --prod --no-editable
36+
37+
# Setup the production environment
38+
FROM python-base as production
39+
COPY --from=builder-base $PYSETUP_PATH $PYSETUP_PATH
40+
RUN apt-get update
41+
42+
# Set the working directory and copy your application code
43+
WORKDIR app/
44+
COPY ./src /app

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center">
22

3-
# PyProject
3+
# FastStream Monitoring Example
44

55
[![python](https://img.shields.io/badge/python-3.12-blue)](https://www.python.org/)
66
[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm-project.org)
@@ -10,11 +10,16 @@
1010

1111
</div>
1212

13-
## Minimal infrastructure settings for a quick start of a Python project.
13+
## Example of monitoring settings for FastStream
1414

15-
## Highlights of features
15+
The example consists of three services and demonstrates support for distributed tracing.
1616

17-
- [PDM](https://pdm-project.org/en/latest/) `package` manager
18-
- Configured `CI` with `tests` and `lints`
19-
- [Just](https://github.com/casey/just) for project `commands`
20-
- Configured `pre-commit`
17+
1. Start application
18+
```shell
19+
just up
20+
```
21+
2. Open **Grafana** on `http://127.0.0.1:3000` with login `admin` and password `admin`
22+
3. Go to **Explore** - **Tempo**
23+
4. Enter TraceQL query `{}`
24+
25+
![Trace example](https://imgur.com/EziQgpy.png)

config/config.template.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[rabbit]
2+
user = "admin"
3+
password = "admin"
4+
port = 5672
5+
host = "127.0.0.1"
6+
7+
[trace]
8+
otlp_endpoint = "http://127.0.0.1:4317"

docker-compose.yaml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
services:
2+
order:
3+
profiles: [ "exchange" ]
4+
container_name: example.order
5+
build:
6+
context: .
7+
restart: unless-stopped
8+
depends_on:
9+
rabbit:
10+
condition: service_healthy
11+
networks:
12+
- example.grafana.network
13+
- example.rabbit.network
14+
volumes:
15+
- ./config:/app/config:ro
16+
environment:
17+
- CONFIG_PATH=$CONFIG_PATH
18+
command: [ "python", "-m", "exchange.order_service.main" ]
19+
20+
trade:
21+
profiles: [ "exchange" ]
22+
container_name: example.trade
23+
build:
24+
context: .
25+
restart: unless-stopped
26+
depends_on:
27+
rabbit:
28+
condition: service_healthy
29+
networks:
30+
- example.grafana.network
31+
- example.rabbit.network
32+
volumes:
33+
- ./config:/app/config:ro
34+
environment:
35+
- CONFIG_PATH=$CONFIG_PATH
36+
command: [ "python", "-m", "exchange.trade_service.main" ]
37+
38+
notification:
39+
profiles: [ "exchange" ]
40+
container_name: example.notification
41+
build:
42+
context: .
43+
restart: unless-stopped
44+
depends_on:
45+
rabbit:
46+
condition: service_healthy
47+
networks:
48+
- example.grafana.network
49+
- example.rabbit.network
50+
volumes:
51+
- ./config:/app/config:ro
52+
environment:
53+
- CONFIG_PATH=$CONFIG_PATH
54+
command: [ "python", "-m", "exchange.notification_service.main" ]
55+
56+
rabbit:
57+
profiles: [ "exchange" ]
58+
image: rabbitmq:3.11-management-alpine
59+
container_name: example.rabbit
60+
hostname: example.rabbit
61+
restart: unless-stopped
62+
expose:
63+
- "5672"
64+
- "15672"
65+
ports:
66+
- "127.0.0.1:5671:5671"
67+
- "127.0.0.1:5672:5672"
68+
- "127.0.0.1:15672:15672"
69+
networks:
70+
- example.rabbit.network
71+
volumes:
72+
- example.rabbit.data:/var/lib/rabbitmq/:rw
73+
environment:
74+
- RABBITMQ_DEFAULT_USER=${RABBITMQ_USER:-admin}
75+
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD:-admin}
76+
healthcheck:
77+
test: [ "CMD-SHELL", "rabbitmq-diagnostics check_running -q" ]
78+
interval: 10s
79+
timeout: 60s
80+
retries: 5
81+
start_period: 10s
82+
83+
grafana:
84+
profiles: [ "grafana" ]
85+
image: grafana/grafana:latest
86+
container_name: example.grafana
87+
hostname: example.grafana
88+
restart: unless-stopped
89+
expose:
90+
- "3000"
91+
ports:
92+
- "127.0.0.1:3000:3000"
93+
networks:
94+
- example.grafana.network
95+
volumes:
96+
- example.grafana.data:/var/lib/grafana:rw
97+
- ./grafana/provisioning:/etc/grafana/provisioning:rw
98+
environment:
99+
- GF_SECURITY_ADMIN_USER=${GRAFANA_USER:-admin}
100+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD:-admin}
101+
- GF_USERS_ALLOW_SIGN_UP=false
102+
- GF_DATABASE_WAL=true
103+
- VIRTUAL_HOST=example.grafana
104+
- NETWORK_ACCESS=internal
105+
- VIRTUAL_PORT=3000
106+
107+
tempo:
108+
profiles: [ "grafana" ]
109+
image: grafana/tempo:2.0.1
110+
container_name: example.tempo
111+
hostname: example.tempo
112+
command: [ "--target=all", "--storage.trace.backend=local", "--storage.trace.local.path=/var/tempo", "--auth.enabled=false" ]
113+
restart: unless-stopped
114+
ports:
115+
- "14250:14250"
116+
- "4317:4317"
117+
expose:
118+
- "14250"
119+
- "4317"
120+
networks:
121+
- example.grafana.network
122+
123+
volumes:
124+
example.grafana.data: {}
125+
example.rabbit.data: {}
126+
127+
128+
networks:
129+
example.grafana.network: {}
130+
example.rabbit.network: {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- uid: tempo
5+
orgId: 1
6+
name: Tempo
7+
type: tempo
8+
typeName: Tempo
9+
access: proxy
10+
url: http://example.tempo
11+
password: ""
12+
user: ""
13+
database: ""
14+
basicAuth: false
15+
isDefault: false
16+
readOnly: false
17+
editable: true

justfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,11 @@
1515
# Run pre-commit
1616
@lint:
1717
pre-commit run --all-files
18+
19+
# Run app in docker container
20+
@up:
21+
docker compose --profile exchange --profile grafana up --build -d
22+
23+
# Stop docker containers
24+
@down:
25+
docker compose --profile exchange --profile grafana down

0 commit comments

Comments
 (0)