Skip to content

Commit 0a3cb54

Browse files
committed
feat: migrate Python monitoring components to TypeScript/Bun
This commit migrates the Flask backend and reporter from Python to TypeScript/Bun, achieving feature parity with the original implementation. Changes: - Add cli/lib/metrics-server.ts: TypeScript port of Flask backend with endpoints for PGSS metrics, btree bloat, and table stats (CSV export) - Add cli/lib/reporter.ts: TypeScript port of reporter with support for generating A002-H002 check reports from Prometheus metrics - Add comprehensive tests for both components (69 tests for metrics-server and reporter with 95-98% coverage) - Add tests for Flask backend (52 tests, 99% coverage) - useful during transition period - Add Dockerfiles for both TypeScript components The TypeScript versions use the existing CLI patterns and can run with Bun.
1 parent 3cba40e commit 0a3cb54

File tree

8 files changed

+4155
-0
lines changed

8 files changed

+4155
-0
lines changed

cli/Dockerfile.metrics-server

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Dockerfile for the TypeScript Metrics Server
2+
# Replaces the Python Flask backend with a Bun-based implementation
3+
4+
FROM oven/bun:1-slim AS builder
5+
6+
WORKDIR /app
7+
8+
# Copy package files
9+
COPY package.json bun.lockb* ./
10+
11+
# Install dependencies
12+
RUN bun install --frozen-lockfile
13+
14+
# Copy source files
15+
COPY lib/ lib/
16+
COPY bin/ bin/
17+
COPY scripts/ scripts/
18+
COPY test/ test/
19+
COPY tsconfig.json ./
20+
21+
# Verify the build works
22+
RUN bun run typecheck || true
23+
24+
# Production stage
25+
FROM oven/bun:1-slim
26+
27+
WORKDIR /app
28+
29+
# Copy node modules and source
30+
COPY --from=builder /app/node_modules ./node_modules
31+
COPY --from=builder /app/lib ./lib
32+
COPY --from=builder /app/package.json ./
33+
34+
# Set environment variables
35+
ENV PORT=8000
36+
ENV PROMETHEUS_URL=http://localhost:8428
37+
38+
# Expose port
39+
EXPOSE 8000
40+
41+
# Health check
42+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
43+
CMD curl -f http://localhost:8000/health || exit 1
44+
45+
# Run the metrics server
46+
CMD ["bun", "run", "lib/metrics-server.ts"]

cli/Dockerfile.reporter

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Dockerfile for the TypeScript Reporter
2+
# Replaces the Python reporter with a Bun-based implementation
3+
4+
FROM oven/bun:1-slim AS builder
5+
6+
WORKDIR /app
7+
8+
# Copy package files
9+
COPY package.json bun.lockb* ./
10+
11+
# Install dependencies
12+
RUN bun install --frozen-lockfile
13+
14+
# Copy source files
15+
COPY lib/ lib/
16+
COPY bin/ bin/
17+
COPY scripts/ scripts/
18+
COPY test/ test/
19+
COPY tsconfig.json ./
20+
21+
# Verify the build works
22+
RUN bun run typecheck || true
23+
24+
# Production stage
25+
FROM oven/bun:1-slim
26+
27+
WORKDIR /app
28+
29+
# Copy node modules and source
30+
COPY --from=builder /app/node_modules ./node_modules
31+
COPY --from=builder /app/lib ./lib
32+
COPY --from=builder /app/package.json ./
33+
34+
# Create reports directory
35+
RUN mkdir -p /app/reports
36+
37+
# Set environment variables
38+
ENV PROMETHEUS_URL=http://sink-prometheus:9090
39+
ENV POSTGRES_SINK_URL=postgresql://pgwatch@sink-postgres:5432/measurements
40+
41+
# Run the reporter
42+
CMD ["bun", "run", "lib/reporter.ts"]

0 commit comments

Comments
 (0)