|
| 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 |
0 commit comments