Skip to content

Commit 503fa08

Browse files
feat(api): configure ClickHouse connection and enhance logging schema; add Docker support
1 parent cb45781 commit 503fa08

File tree

7 files changed

+54
-11
lines changed

7 files changed

+54
-11
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
npm-debug.log
3+
.env
4+
.git
5+
dist
6+
coverage

api/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
npm-debug.log
3+
.env
4+
.git
5+
dist
6+
coverage

api/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /app
4+
5+
COPY package*.json ./
6+
7+
RUN npm install
8+
9+
COPY . .

api/config/env.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const envSchema = z.object({
77
PORT: z.string().default("3000").transform(Number),
88
KAFKA_BROKER: z.string().min(1),
99
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
10-
CLICKHOUSE_PASSWORD: z.string().default(""),
10+
CLICKHOUSE_PASSWORD: z.string().default("password"),
11+
CLICKHOUSE_HOST: z.string().default("http://localhost:8123"),
1112
});
1213

1314
const _env = envSchema.safeParse(process.env);

api/lib/clickhouse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createClient } from "@clickhouse/client";
22
import { env } from "../config/env.js";
33

44
export const clickhouse = createClient({
5-
url: 'http://localhost:8123',
5+
url: env.CLICKHOUSE_HOST,
66
username: 'default',
77
password: env.CLICKHOUSE_PASSWORD,
88
database: 'default',

api/schemas/log.schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import z from 'zod';
22

33
export const logSchema = z.object({
44
service: z.string().min(1, "Service name is required"),
5-
level: z.enum(['INFO', 'WARN', 'ERROR', 'DEBUG']),
5+
level: z.enum(['INFO', 'WARN', 'ERROR', 'DEBUG', 'FATAL']),
66
message: z.string().min(1, "Log message cannot be empty"),
77
metadata: z.record(z.string(), z.any()).optional(),
88
});

docker-compose.yml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
version: '3'
2-
31
services:
4-
# 1. Kafka (KRaft Mode - No Zookeeper required)
52
kafka:
6-
image: confluentinc/cp-kafka:7.6.1 # Pinned for stability
3+
image: confluentinc/cp-kafka:7.6.1
74
hostname: kafka
85
container_name: logstream-kafka
96
ports:
@@ -18,16 +15,13 @@ services:
1815
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
1916
KAFKA_JMX_PORT: 9101
2017
KAFKA_JMX_HOSTNAME: localhost
21-
# KRaft Specific Settings
2218
KAFKA_PROCESS_ROLES: 'broker,controller'
2319
KAFKA_CONTROLLER_QUORUM_VOTERS: '1@kafka:29093'
2420
KAFKA_LISTENERS: 'PLAINTEXT://kafka:29092,CONTROLLER://kafka:29093,PLAINTEXT_HOST://0.0.0.0:9092'
2521
KAFKA_INTER_BROKER_LISTENER_NAME: 'PLAINTEXT'
2622
KAFKA_CONTROLLER_LISTENER_NAMES: 'CONTROLLER'
27-
# Using a static Cluster ID to avoid "format" errors on startup
2823
CLUSTER_ID: 'MkU3OEVBNTcwNTJENDM2Qk'
2924

30-
# 2. ClickHouse (The Database)
3125
clickhouse:
3226
image: clickhouse/clickhouse-server
3327
container_name: logstream-clickhouse
@@ -41,4 +35,31 @@ services:
4135
environment:
4236
- CLICKHOUSE_USER=default
4337
- CLICKHOUSE_PASSWORD=password
44-
- CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
38+
- CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
39+
40+
api:
41+
build: ./api
42+
container_name: logstream-api
43+
command: npx tsx server.ts
44+
ports:
45+
- "3000:3000"
46+
depends_on:
47+
- kafka
48+
- clickhouse
49+
environment:
50+
- PORT=3000
51+
- KAFKA_BROKER=kafka:29092
52+
- CLICKHOUSE_HOST=http://clickhouse:8123
53+
- CLICKHOUSE_PASSWORD=password
54+
55+
worker:
56+
build: ./api
57+
container_name: logstream-worker
58+
command: npx tsx worker/index.ts
59+
depends_on:
60+
- kafka
61+
- clickhouse
62+
environment:
63+
- KAFKA_BROKER=kafka:29092
64+
- CLICKHOUSE_HOST=http://clickhouse:8123
65+
- CLICKHOUSE_PASSWORD=password

0 commit comments

Comments
 (0)