Skip to content

Commit 0a7d1a6

Browse files
committed
update docs.
1 parent afba502 commit 0a7d1a6

3 files changed

Lines changed: 172 additions & 52 deletions

File tree

README.md

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ A SMTP server that receives emails from any domain without authentication and fo
3939
### Webhook Integration
4040
- 🔐 **HTTP Basic Auth**: Secure webhook authentication
4141
- 📨 **Rich Payload**: Complete email data including headers and attachments
42-
- 🔁 **Error Handling**: Robust webhook delivery with retry logic
42+
- 🔁 **Reliability Features**: Automatic retry with exponential backoff, rate limiting, and circuit breaker
43+
- 🛡️ **Fault Tolerance**: Circuit breaker pattern prevents cascading failures
44+
-**Rate Limiting**: Configurable requests per second to protect downstream endpoints
4345
- ✂️ **Content Processing**: Parsed text and HTML content extraction
4446

4547
## Quick Start
@@ -116,6 +118,12 @@ Usage of ./inboundparse:
116118
-webhook string Webhook URL for email payloads (required)
117119
-webhook-user string Basic auth username for webhook (optional)
118120
-webhook-pass string Basic auth password for webhook (optional)
121+
-webhook-max-retries int Maximum webhook retry attempts (default 3)
122+
-webhook-retry-delay int Initial webhook retry delay in seconds (default 1)
123+
-webhook-max-retry-delay int Maximum webhook retry delay in seconds (default 30)
124+
-webhook-retry-multiplier float Webhook retry delay multiplier (default 2.0)
125+
-webhook-rate-limit int Webhook requests per second rate limit (default 10)
126+
-webhook-rate-burst int Webhook rate limit burst capacity (default 20)
119127
-name string SMTP server name (default "mx.inboundparse.com")
120128
-max-size int Max message size bytes (default 10485760)
121129
-read-timeout int Read timeout (seconds, default 30)
@@ -143,49 +151,50 @@ Usage of ./inboundparse:
143151

144152
You can configure InboundParse using environment variables or command line flags:
145153

146-
#### Core Configuration
147-
- `WEBHOOK_URL` - Webhook URL (required)
148-
- `WEBHOOK_USER` - Basic auth username for webhook
149-
- `WEBHOOK_PASS` - Basic auth password for webhook
150-
- `LISTEN_ADDR` - SMTP server listen address (default: "0.0.0.0:25")
151-
- `LISTEN_ADDR_TLS` - TLS server listen address (default: "0.0.0.0:587")
152-
- `SERVER_NAME` - SMTP server name (default: "mx.inboundparse.com")
153-
154-
#### TLS Configuration
155-
- `CERT_FILE` - TLS certificate file path
156-
- `KEY_FILE` - TLS private key file path
157-
158-
#### Feature Toggles
159-
- `ENABLE_SPF` - Enable SPF validation (default: true)
160-
- `ENABLE_DKIM` - Enable DKIM validation (default: true)
161-
- `ENABLE_DMARC` - Enable DMARC validation (default: true)
162-
- `VERBOSE` - Enable verbose logging (default: false)
163-
164-
#### Logging Configuration
165-
- `LOG_LEVEL` - Log level (debug, info, warn, error) (default: "info")
166-
- `LOG_FORMAT` - Log format (json, console) (default: "json")
167-
- `LOG_OUTPUT` - Log output destination (default: "stdout")
168-
169-
#### Metrics Configuration
170-
- `ENABLE_METRICS` - Enable Prometheus metrics collection (default: false)
171-
- `METRICS_ADDR` - Metrics server listen address (default: "0.0.0.0:9090")
172-
- `METRICS_API_KEY` - Metrics API key
173-
- `METRICS_USERNAME` - Metrics username
174-
- `METRICS_PASSWORD` - Metrics password
175-
176-
#### Sentry Configuration
177-
- `ENABLE_SENTRY` - Enable Sentry error tracking (default: false)
178-
- `SENTRY_DSN` - Sentry DSN for error tracking
179-
- `SENTRY_ENV` - Sentry environment (default: "production")
180-
- `SENTRY_RELEASE` - Sentry release version
181-
182-
#### Automatic Certificate Management
183-
- `ACME_SH_EMAIL` - Email for Let's Encrypt account registration
184-
- `MXDOMAIN` - Domain for SSL certificate (default: "mx.inboundparse.com")
185-
- `DNS_API` - DNS API provider (default: "dns_cf")
186-
- `CF_Token` - Cloudflare API token (required for dns_cf)
187-
- `CF_Zone_ID` - Cloudflare Zone ID (required for dns_cf)
154+
#### Core Environment Variables
188155

156+
- `WEBHOOK_URL` Webhook URL to receive email payloads (**required**)
157+
- `WEBHOOK_USER` Basic auth username for the webhook (optional)
158+
- `WEBHOOK_PASS` Basic auth password for the webhook (optional)
159+
160+
#### Webhook Reliability Configuration
161+
162+
- `WEBHOOK_MAX_RETRIES` Maximum retry attempts (default: `3`)
163+
- `WEBHOOK_RETRY_DELAY` Initial retry delay in seconds (default: `1`)
164+
- `WEBHOOK_MAX_RETRY_DELAY` Maximum retry delay in seconds (default: `30`)
165+
- `WEBHOOK_RETRY_MULTIPLIER` Exponential backoff multiplier (default: `2.0`)
166+
- `WEBHOOK_RATE_LIMIT` Requests per second rate limit (default: `10`)
167+
- `WEBHOOK_RATE_BURST` Rate limit burst capacity (default: `20`)
168+
- `LISTEN_ADDR` SMTP listen address (default: `0.0.0.0:25`)
169+
- `LISTEN_ADDR_TLS` TLS listen address (default: `0.0.0.0:587`)
170+
- `SERVER_NAME` SMTP service name for banner (default: `mx.inboundparse.com`)
171+
172+
#### TLS Settings
173+
174+
- `CERT_FILE` Path to TLS certificate file (optional)
175+
- `KEY_FILE` Path to TLS private key file (optional)
176+
177+
#### Feature Flags
178+
179+
- `ENABLE_SPF` Enable SPF checking (`true`/`false`, default: `true`)
180+
- `ENABLE_DKIM` Enable DKIM checking (`true`/`false`, default: `true`)
181+
- `ENABLE_DMARC` Enable DMARC checking (`true`/`false`, default: `true`)
182+
- `VERBOSE` Enable verbose (debug) logging (`true`/`false`, default: `false`)
183+
184+
#### Metrics (Prometheus)
185+
186+
- `ENABLE_METRICS` Enable Prometheus metrics endpoint (`true`/`false`, default: `false`)
187+
- `METRICS_ADDR` Metrics endpoint listen address (default: `0.0.0.0:9090`)
188+
- `METRICS_API_KEY` Bearer token used for metrics endpoint authentication (optional)
189+
- `METRICS_USERNAME` Username for metrics endpoint basic auth (optional)
190+
- `METRICS_PASSWORD` Password for metrics endpoint basic auth (optional)
191+
192+
#### Sentry Error Tracking
193+
194+
- `ENABLE_SENTRY` Enable Sentry error tracking (`true`/`false`, default: `false`)
195+
- `SENTRY_DSN` Sentry DSN (project key, required if Sentry enabled)
196+
- `SENTRY_ENV` Sentry environment name (default: `production`)
197+
- `SENTRY_RELEASE` Sentry release version (optional)
189198

190199
## Webhook Payload
191200

@@ -240,7 +249,7 @@ The service sends a JSON payload to your webhook with comprehensive email data:
240249

241250
## 🤝 Contributing
242251

243-
Contributions of all kinds are welcome! See [CONTRIBUTING.md](./docs/CONTRIBUTING.md) for guidelines, and don’t hesitate to open issues, fork, or create PRs.
252+
Contributions of all kinds are welcome! See [CONTRIBUTE.md](./docs/CONTRIBUTE.md) for guidelines, and don’t hesitate to open issues, fork, or create PRs.
244253

245254
---
246255

docs/CONTRIBUTE.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ We appreciate all kinds of contributions:
3434

3535
### 2. Set Up Your Environment
3636

37-
- **Ensure you have Go >= 1.20 installed.**
37+
- **Ensure you have Go >= 1.24 installed.**
3838
- Install dependencies:
3939
```bash
4040
make deps
@@ -44,6 +44,12 @@ We appreciate all kinds of contributions:
4444
make build
4545
```
4646

47+
**Key Dependencies:**
48+
- `github.com/failsafe-go/failsafe-go` - Webhook resilience patterns (retry, rate limiting, circuit breaker)
49+
- `github.com/rs/zerolog` - High-performance structured logging
50+
- `github.com/getsentry/sentry-go` - Error tracking and performance monitoring
51+
- `github.com/prometheus/client_golang` - Metrics collection
52+
4753
### 3. Run Tests
4854

4955
- To run all tests:
@@ -62,14 +68,18 @@ We appreciate all kinds of contributions:
6268
- **Keep your branch up to date**:
6369
Rebase or merge `upstream/main` regularly to minimize conflicts.
6470

65-
- **Follow Go formatting**:
66-
Run `go fmt ./...` and `go vet ./...` before submitting.
71+
- **Format your code**:
72+
```bash
73+
make format
74+
```
6775

6876
- **Lint your code**:
6977
```bash
7078
make lint
7179
```
7280

81+
_We also have `make fl` which does both._
82+
7383
- **Include tests**:
7484
Add or update tests for new features and bug fixes.
7585

@@ -91,7 +101,7 @@ We appreciate all kinds of contributions:
91101

92102
## 📝 Code Style & Guidelines
93103

94-
- Write clean, idiomatic Go (see `make lint`).
104+
- Write clean, idiomatic Go (see `make fl`).
95105
- Prefer clarity over cleverness.
96106
- Use descriptive variable and function names.
97107
- Keep functions short and focused.
@@ -106,13 +116,22 @@ We appreciate all kinds of contributions:
106116
| ------------------- | ------------------------------ |
107117
| `make deps` | Install dependencies |
108118
| `make build` | Build binaries |
109-
| `make run` | Run server (prod config) |
110119
| `make run-dev` | Run with development settings |
111-
| `make lint` | Run linter |
112120
| `make test` | Run tests |
113-
| `make test-coverage`| Run tests with coverage report |
121+
| `make coverage` | Run tests with coverage report |
122+
| `make format` | Format code |
123+
| `make lint` | Run linter and vulnerability scan |
124+
| `make vet` | Vet the code |
125+
| `make fl` | Format, lint, and vet code |
126+
| `make check` | Run deps, linters, and vulncheck |
127+
| `make clean` | Clean build artifacts |
114128
| `make up` | Start dev stack (Docker) |
115129
| `make down` | Stop dev stack |
130+
| `make dev` | Restart dev stack |
131+
| `make status` | Show service status |
132+
| `make verify-deps` | Verify dependency status |
133+
| `make docker-build` | Build Docker image |
134+
| `make ci` | Run CI workflow |
116135

117136

118137
---

docs/OBSERVABILITY.md

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,99 @@ CaptureError(err, map[string]interface{}{
111111
- **Message processing errors**: Parse failures, read errors
112112
- **Server errors**: TLS certificate issues, startup failures
113113

114-
## 3. Prometheus Metrics
114+
## 3. Webhook Reliability
115+
116+
### Implementation
117+
118+
- **Library**: failsafe-go (resilience patterns for Go)
119+
- **Features**:
120+
- Automatic retry with exponential backoff
121+
- Rate limiting with token bucket algorithm
122+
- Circuit breaker pattern for fault tolerance
123+
- Configurable retry and rate limit policies
124+
125+
### Retry Logic
126+
127+
Webhook requests automatically retry on failure with exponential backoff:
128+
129+
- **Max Retries**: Configurable maximum retry attempts (default: 3)
130+
- **Initial Delay**: Starting delay between retries (default: 1 second)
131+
- **Max Delay**: Maximum delay cap (default: 30 seconds)
132+
- **Multiplier**: Exponential backoff multiplier (default: 2.0)
133+
134+
Example retry sequence with defaults:
135+
- Attempt 1: Immediate
136+
- Attempt 2: 1 second delay
137+
- Attempt 3: 2 second delay
138+
- Attempt 4: 4 second delay
139+
140+
### Rate Limiting
141+
142+
Smooth rate limiting using token bucket algorithm:
143+
144+
- **Rate Limit**: Requests per second (default: 10)
145+
- **Burst Capacity**: Burst allowance (default: 20)
146+
- **Algorithm**: Token bucket for smooth rate limiting
147+
148+
### Circuit Breaker
149+
150+
Automatic service degradation to prevent cascading failures:
151+
152+
- **Failure Threshold**: 5 consecutive failures trigger circuit open
153+
- **Success Threshold**: 3 consecutive successes reset circuit
154+
- **States**: Closed (normal), Open (failing), Half-Open (testing)
155+
156+
### Configuration
157+
158+
```bash
159+
# Retry configuration
160+
WEBHOOK_MAX_RETRIES=5
161+
WEBHOOK_RETRY_DELAY=2
162+
WEBHOOK_MAX_RETRY_DELAY=60
163+
WEBHOOK_RETRY_MULTIPLIER=1.5
164+
165+
# Rate limiting
166+
WEBHOOK_RATE_LIMIT=20
167+
WEBHOOK_RATE_BURST=50
168+
```
169+
170+
Or via flags:
171+
172+
```bash
173+
./inboundparse \
174+
-webhook-max-retries=5 \
175+
-webhook-retry-delay=2 \
176+
-webhook-max-retry-delay=60 \
177+
-webhook-retry-multiplier=1.5 \
178+
-webhook-rate-limit=20 \
179+
-webhook-rate-burst=50
180+
```
181+
182+
### Use Cases
183+
184+
**High Volume Processing:**
185+
```bash
186+
WEBHOOK_RATE_LIMIT=100
187+
WEBHOOK_RATE_BURST=200
188+
WEBHOOK_MAX_RETRIES=5
189+
```
190+
191+
**Sensitive Downstream Services:**
192+
```bash
193+
WEBHOOK_RATE_LIMIT=5
194+
WEBHOOK_RATE_BURST=10
195+
WEBHOOK_MAX_RETRIES=10
196+
WEBHOOK_RETRY_DELAY=5
197+
```
198+
199+
**Fast Recovery:**
200+
```bash
201+
WEBHOOK_MAX_RETRIES=3
202+
WEBHOOK_RETRY_DELAY=1
203+
WEBHOOK_RETRY_MULTIPLIER=1.2
204+
```
205+
206+
## 4. Prometheus Metrics
115207

116208
### Implementation
117209

0 commit comments

Comments
 (0)