Skip to content

Commit 715d03f

Browse files
committed
feat: update how report backend works
1 parent b7a3663 commit 715d03f

File tree

21 files changed

+919
-509
lines changed

21 files changed

+919
-509
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
22
/.idea/
3-
/bin/
3+
**/bin/
44
data-dir/
55
output/
66
.vercel

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
1919
LDFLAGSSTRING +=-X main.Version=$(VERSION)
2020
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"
2121

22+
# Include .env file if it exists
23+
-include .env
24+
2225
# first so that make defaults to building the benchmark
2326
.PHONY: build
2427
build:
@@ -50,3 +53,19 @@ build-rbuilder:
5053

5154
.PHONY: build-binaries
5255
build-binaries: build-reth build-geth build-rbuilder
56+
57+
.PHONY: build-backend
58+
build-backend:
59+
cd report/backend && env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) CGO_ENABLED=0 go build -v $(LDFLAGS) -o ../../bin/base-bench-api cmd/main.go
60+
61+
.PHONY: run-backend
62+
run-backend:
63+
./bin/base-bench-api --enable-s3=true --s3-bucket ${BASE_BENCH_API_S3_BUCKET}
64+
65+
.PHONY: run-backend
66+
run-backend:
67+
./bin/base-bench-api --s3-bucket ${BASE_BENCH_API_S3_BUCKET}
68+
69+
.PHONY: run-backfill
70+
run-backfill:
71+
./bin/base-bench backfill-benchmark-run-id --enable-s3=true --s3-bucket ${BASE_BENCH_API_S3_BUCKET} metadata.json

benchmark/flags/flags.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ func prefixEnvVars(name string) []string {
1515
}
1616

1717
const (
18-
ConfigFlagName = "config"
19-
RootDirFlagName = "root-dir"
20-
OutputDirFlagName = "output-dir"
21-
EnableS3FlagName = "enable-s3"
22-
S3BucketFlagName = "s3-bucket"
23-
TxFuzzBinFlagName = "tx-fuzz-bin"
24-
ProxyPortFlagName = "proxy-port"
18+
ConfigFlagName = "config"
19+
RootDirFlagName = "root-dir"
20+
OutputDirFlagName = "output-dir"
21+
EnableS3FlagName = "enable-s3"
22+
S3BucketFlagName = "s3-bucket"
23+
TxFuzzBinFlagName = "tx-fuzz-bin"
24+
ProxyPortFlagName = "proxy-port"
25+
BenchmarkRunIDFlagName = "benchmark-run-id"
2526
)
2627

2728
// TxFuzz defaults
@@ -77,6 +78,12 @@ var (
7778
Usage: "S3 bucket name for storing benchmark results",
7879
EnvVars: prefixEnvVars("S3_BUCKET"),
7980
}
81+
82+
BenchmarkRunIDFlag = &cli.StringFlag{
83+
Name: BenchmarkRunIDFlagName,
84+
Usage: "Custom benchmark run ID (auto-generated if not provided)",
85+
EnvVars: prefixEnvVars("BENCHMARK_RUN_ID"),
86+
}
8087
)
8188

8289
// Flags contains the list of configuration options available to the binary.
@@ -90,6 +97,7 @@ var RunFlags = []cli.Flag{
9097
ProxyPortFlag,
9198
EnableS3Flag,
9299
S3BucketFlag,
100+
BenchmarkRunIDFlag,
93101
}
94102

95103
func init() {

report/backend/Dockerfile

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,49 @@
1-
# Build stage
2-
FROM golang:1.21-alpine AS builder
3-
4-
# Install build dependencies
5-
RUN apk add --no-cache git ca-certificates
1+
FROM ubuntu:22.04 AS base
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
ENV PATH="/root/.cargo/bin:${PATH}"
5+
6+
# Install system dependencies
7+
RUN apt-get update && apt-get install -y --no-install-recommends \
8+
build-essential \
9+
curl \
10+
git \
11+
make \
12+
cmake \
13+
pkg-config \
14+
libssl-dev \
15+
libpq-dev \
16+
libclang-dev \
17+
ca-certificates \
18+
sudo \
19+
&& rm -rf /var/lib/apt/lists/*
620

721
WORKDIR /app
822

9-
# Copy go mod files
10-
COPY go.mod go.sum ./
23+
# Install Go manually using curl
24+
RUN curl -fsSL https://go.dev/dl/go1.23.0.linux-amd64.tar.gz | tar -C /usr/local -xz
25+
ENV PATH="/usr/local/go/bin:$PATH"
1126

12-
# Download dependencies
27+
COPY go.mod go.sum ./
1328
RUN go mod download
1429

15-
# Copy source code
1630
COPY . .
31+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o base-bench-api ./cmd/main.go
1732

18-
# Build the application
19-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
33+
FROM ubuntu:22.04 AS runtime
2034

21-
# Final stage
22-
FROM alpine:latest
35+
# Install minimal runtime dependencies
36+
RUN apt-get update && apt-get install -y --no-install-recommends \
37+
ca-certificates && \
38+
rm -rf /var/lib/apt/lists/*
2339

24-
# Install ca-certificates for HTTPS requests
25-
RUN apk --no-cache add ca-certificates
26-
27-
WORKDIR /root/
40+
WORKDIR /app
2841

29-
# Copy the binary from builder stage
30-
COPY --from=builder /app/main .
42+
COPY --from=base /app/base-bench-api .
3143

32-
# Expose port
3344
EXPOSE 8080
3445

35-
# Health check
3646
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
3747
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/v1/health || exit 1
3848

39-
# Run the binary
40-
CMD ["./main"]
49+
ENTRYPOINT ["./base-bench-api"]

report/backend/README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Benchmark Report API
2+
3+
A Go-based REST API for serving benchmark data from AWS S3 storage.
4+
5+
## Project Structure
6+
7+
This project follows the standard Go project layout:
8+
9+
```
10+
benchmark/report/backend/
11+
├── cmd/
12+
│ └── api/ # Application entrypoints
13+
│ └── main.go # Main application entry point
14+
├── internal/ # Private application code
15+
│ ├── config/ # Configuration, middleware, and errors
16+
│ │ └── config.go # Config, CORS, logging, and error handling
17+
│ ├── handlers/ # HTTP handlers
18+
│ │ ├── health.go # Health check endpoint
19+
│ │ ├── metadata.go # Metadata endpoint handler
20+
│ │ └── metrics.go # Metrics endpoint handler
21+
│ └── services/ # Business logic and data models
22+
│ ├── cache.go # In-memory caching with CacheItem model
23+
│ └── s3.go # AWS S3 service with Benchmark models
24+
├── bin/ # Compiled binaries (gitignored)
25+
├── flags/ # CLI flags for the API server
26+
│ └── flags.go # Command-line flag definitions
27+
├── go.mod # Go module definition
28+
├── go.sum # Go module checksums
29+
├── Makefile # Build automation
30+
├── Dockerfile # Docker container definition
31+
├── docker-compose.yml # Docker Compose configuration
32+
└── README.md # This file
33+
```
34+
35+
## Features
36+
37+
- **REST API** for benchmark data retrieval
38+
- **AWS S3 integration** with intelligent caching
39+
- **Structured logging** with configurable levels
40+
- **Health checks** for monitoring
41+
- **CORS support** for frontend integration
42+
- **Graceful shutdown** handling
43+
- **Docker support** for containerized deployment
44+
45+
## Environment Variables
46+
47+
| Variable | Description | Default |
48+
|----------|-------------|---------|
49+
| `PORT` | Server port | `8080` |
50+
| `S3_BUCKET` | AWS S3 bucket name | **Required** |
51+
| `AWS_REGION` | AWS region | `us-east-1` |
52+
| `AWS_ACCESS_KEY_ID` | AWS access key | From AWS credentials |
53+
| `AWS_SECRET_ACCESS_KEY` | AWS secret key | From AWS credentials |
54+
| `CACHE_TTL` | Cache time-to-live | `5m` |
55+
| `ENABLE_CACHE` | Enable/disable caching | `true` |
56+
| `ALLOWED_ORIGINS` | CORS allowed origins (comma-separated) | `*` |
57+
| `LOG_LEVEL` | Logging level (debug, info, warn, error) | `info` |
58+
59+
## API Endpoints
60+
61+
### Health Check
62+
```
63+
GET /api/v1/health
64+
```
65+
Returns the service health status.
66+
67+
### Metadata
68+
```
69+
GET /api/v1/metadata
70+
```
71+
Returns benchmark run metadata from S3.
72+
73+
### Metrics
74+
```
75+
GET /api/v1/metrics/:runId/:outputDir/:nodeType
76+
```
77+
Returns metrics data for a specific benchmark run and node type.
78+
79+
## Development
80+
81+
### Prerequisites
82+
83+
- Go 1.23 or later
84+
- Docker (optional, for containerized development)
85+
- Make (optional, for build automation)
86+
87+
### Quick Start
88+
89+
1. **Set up environment variables:**
90+
```bash
91+
export S3_BUCKET=your-bucket-name
92+
export AWS_REGION=us-east-1
93+
# ... other environment variables
94+
```
95+
96+
2. **Run in development mode:**
97+
```bash
98+
make run-backend
99+
```
100+
101+
## Architecture
102+
103+
### Layers
104+
105+
1. **Handlers Layer** (`internal/handlers/`): HTTP request handling and response formatting
106+
2. **Services Layer** (`internal/services/`): Business logic, external service integration, and data models
107+
3. **Configuration Layer** (`internal/config/`): Application configuration, middleware, and error handling
108+
109+
### Key Components
110+
111+
- **S3Service**: Handles AWS S3 interactions with intelligent caching (includes BenchmarkRuns/BenchmarkRun models)
112+
- **MemoryCache**: Provides in-memory caching with TTL support (includes CacheItem model)
113+
- **Configuration**: Environment-based configuration with validation, CORS, and logging setup
114+
- **Handlers**: Clean HTTP handlers following single responsibility principle
115+
- **Flags**: CLI flag definitions for server configuration

report/backend/benchmark-api

-16.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)