Skip to content

Commit

Permalink
v0.0.24: Add HTTP/3 support and update server configuration - Add HTT…
Browse files Browse the repository at this point in the history
…P/3 (QUIC) protocol support with configuration options - Update server to handle both HTTP/1.1 and HTTP/3 concurrently - Add comprehensive HTTP/3 tests with realistic scenarios - Change default port from 8080 to 8081 in Docker and tests - Update README with HTTP/3 configuration examples - Fix queue persistence bug in middleware - Add graceful shutdown for both HTTP/1.1 and HTTP/3 servers
  • Loading branch information
teilomillet committed Jan 3, 2025
1 parent 33a4420 commit 26c2931
Show file tree
Hide file tree
Showing 14 changed files with 966 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
go install golang.org/x/tools/cmd/goimports@latest
- name: Run tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ COPY prometheus.yml ./prometheus.yml
USER hapax

# Expose ports
EXPOSE 8080
EXPOSE 8081

# Set healthcheck
HEALTHCHECK --interval=10s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
CMD curl -f http://localhost:8081/health || exit 1

# Run the application
ENTRYPOINT ["./hapax"]
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ docker run -p 8080:8080 \

Default configuration is provided but can be customized via `config.yaml`:
```yaml
server:
port: 8080
read_timeout: 30s
write_timeout: 45s
max_header_bytes: 2097152 # 2MB
shutdown_timeout: 30s
http3: # Optional HTTP/3 support
enabled: true
port: 443 # Default HTTPS/QUIC port
tls_cert_file: "/path/to/cert.pem"
tls_key_file: "/path/to/key.pem"
idle_timeout: 30s
max_bi_streams_concurrent: 100
max_uni_streams_concurrent: 100
max_stream_receive_window: 6291456 # 6MB
max_connection_receive_window: 15728640 # 15MB

circuitBreaker:
maxRequests: 100
interval: 30s
Expand Down Expand Up @@ -113,9 +130,23 @@ The health monitoring system operates with enterprise-grade configurability. Che
### Production Safeguards
System integrity is maintained through multiple safeguards: request deduplication prevents redundant processing, automatic failover ensures continuous operation, circuit breaker patterns protect against cascade failures, and structured JSON logging with correlation IDs enables thorough debugging.

### Protocol Support
The server supports both HTTP/1.1 and HTTP/3 (QUIC) protocols:
- HTTP/1.1 for universal compatibility
- HTTP/3 for improved performance:
- Reduced latency through 0-RTT connections
- Better multiplexing with independent streams
- Improved congestion control
- Automatic connection migration
- Built-in TLS 1.3 encryption

## Technical Requirements

Running Hapax requires a Docker-compatible environment with network access to AI providers. The system operates efficiently with 1GB RAM, though 4GB is recommended for production deployments. Access credentials (API keys) are required for supported providers: OpenAI, Anthropic, etc./.
Running Hapax requires:
- Docker-compatible environment with network access to AI providers
- 1GB RAM minimum (4GB recommended for production)
- TLS certificates for HTTP/3 support (if enabled)
- Access credentials (API keys) for supported providers: OpenAI, Anthropic, etc.

## Documentation

Expand Down
Binary file added bin/golangci-lint
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/hapax/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
version = flag.Bool("version", false, "Print version and exit")
)

const Version = "v0.0.23"
const Version = "v0.0.24"

func main() {
flag.Parse()
Expand Down
80 changes: 80 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,42 @@ type ServerConfig struct {
// ShutdownTimeout specifies how long to wait for the server to shutdown
// gracefully before forcing termination (default: 30s)
ShutdownTimeout time.Duration `yaml:"shutdown_timeout"`

// HTTP3 configuration (optional)
HTTP3 *HTTP3Config `yaml:"http3,omitempty"`
}

// HTTP3Config holds configuration specific to the HTTP/3 server.
// HTTP/3 requires TLS, so certificate configuration is mandatory.
type HTTP3Config struct {
// Enable HTTP/3 support
Enabled bool `yaml:"enabled"`

// Port for HTTP/3 (QUIC) traffic (default: 443)
Port int `yaml:"port"`

// TLSCertFile is the path to the TLS certificate file
TLSCertFile string `yaml:"tls_cert_file"`

// TLSKeyFile is the path to the TLS private key file
TLSKeyFile string `yaml:"tls_key_file"`

// IdleTimeout is the maximum time to wait for the next request when keep-alives are enabled
IdleTimeout time.Duration `yaml:"idle_timeout"`

// MaxBiStreamsConcurrent is the maximum number of concurrent bidirectional streams
// that a peer is allowed to open. The default is 100.
MaxBiStreamsConcurrent int64 `yaml:"max_bi_streams_concurrent"`

// MaxUniStreamsConcurrent is the maximum number of concurrent unidirectional streams
// that a peer is allowed to open. The default is 100.
MaxUniStreamsConcurrent int64 `yaml:"max_uni_streams_concurrent"`

// MaxStreamReceiveWindow is the stream-level flow control window for receiving data
MaxStreamReceiveWindow uint64 `yaml:"max_stream_receive_window"`

// MaxConnectionReceiveWindow is the connection-level flow control window for receiving data
MaxConnectionReceiveWindow uint64 `yaml:"max_connection_receive_window"`
}

// LLMConfig holds LLM-specific configuration.
Expand Down Expand Up @@ -275,6 +311,15 @@ func DefaultConfig() *Config {
WriteTimeout: 45 * time.Second,
MaxHeaderBytes: 2 << 20, // 2MB for larger headers
ShutdownTimeout: 30 * time.Second,
HTTP3: &HTTP3Config{
Enabled: false, // Disabled by default
Port: 443, // Default HTTPS/QUIC port
IdleTimeout: 30 * time.Second,
MaxBiStreamsConcurrent: 100,
MaxUniStreamsConcurrent: 100,
MaxStreamReceiveWindow: 6 * 1024 * 1024, // 6MB
MaxConnectionReceiveWindow: 15 * 1024 * 1024, // 15MB
},
},

LLM: LLMConfig{
Expand Down Expand Up @@ -531,6 +576,41 @@ func (c *Config) Validate() error {
return fmt.Errorf("negative shutdown timeout: %v", c.Server.ShutdownTimeout)
}

// HTTP/3 validation
if c.Server.HTTP3 != nil && c.Server.HTTP3.Enabled {
if c.Server.HTTP3.Port < 0 || c.Server.HTTP3.Port > 65535 {
return fmt.Errorf("invalid HTTP/3 port: %d", c.Server.HTTP3.Port)
}
if c.Server.HTTP3.TLSCertFile == "" {
return fmt.Errorf("HTTP/3 enabled but TLS certificate file not specified")
}
if c.Server.HTTP3.TLSKeyFile == "" {
return fmt.Errorf("HTTP/3 enabled but TLS key file not specified")
}
if c.Server.HTTP3.IdleTimeout < 0 {
return fmt.Errorf("negative HTTP/3 idle timeout: %v", c.Server.HTTP3.IdleTimeout)
}
if c.Server.HTTP3.MaxBiStreamsConcurrent < 0 {
return fmt.Errorf("negative HTTP/3 max bidirectional streams: %d", c.Server.HTTP3.MaxBiStreamsConcurrent)
}
if c.Server.HTTP3.MaxUniStreamsConcurrent < 0 {
return fmt.Errorf("negative HTTP/3 max unidirectional streams: %d", c.Server.HTTP3.MaxUniStreamsConcurrent)
}
if c.Server.HTTP3.MaxStreamReceiveWindow == 0 {
return fmt.Errorf("HTTP/3 max stream receive window must be positive")
}
if c.Server.HTTP3.MaxConnectionReceiveWindow == 0 {
return fmt.Errorf("HTTP/3 max connection receive window must be positive")
}
// Check if TLS files exist and are readable
if _, err := os.Stat(c.Server.HTTP3.TLSCertFile); err != nil {
return fmt.Errorf("HTTP/3 TLS certificate file not accessible: %w", err)
}
if _, err := os.Stat(c.Server.HTTP3.TLSKeyFile); err != nil {
return fmt.Errorf("HTTP/3 TLS key file not accessible: %w", err)
}
}

// LLM validation
if c.LLM.Provider == "" {
return fmt.Errorf("empty LLM provider")
Expand Down
Loading

0 comments on commit 26c2931

Please sign in to comment.