-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Add Policy Server for Rate Limiting #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a major architectural enhancement to the Postfix adapter for Userli, adding a new Policy Server for rate limiting alongside the existing lookup functionality. The codebase has been refactored to use a shared TCP server infrastructure with a clean ConnectionHandler interface pattern, improving code reusability and maintainability.
Key changes:
- Added Policy Server (
:10003) implementing Postfix SMTP Access Policy Delegation for rate limiting outgoing mail - Introduced sliding-window rate limiter with per-sender quota tracking (hourly/daily limits)
- Refactored to shared
tcpserver.gowith connection pooling, graceful shutdown, and TCP keep-alive - Renamed
SocketmapAdaptertoLookupServerfor clarity and consistency
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
tcpserver.go |
New shared TCP server infrastructure with connection pooling and graceful shutdown support |
policy.go |
New Policy Server implementing Postfix policy delegation protocol for rate limiting |
ratelimit.go |
Sliding window rate limiter with timestamp tracking and background cleanup |
lookup.go |
Refactored lookup server (formerly adapter.go), now implements ConnectionHandler interface |
userli.go |
Added GetQuota() method to fetch per-user rate limit quotas from Userli API |
prometheus.go |
Added policy server metrics (requests, duration, quota checks, tracked senders) |
config.go |
Added POLICY_LISTEN_ADDR configuration with default :10003 |
main.go |
Initialize both lookup and policy servers with shared context and WaitGroup |
policy_test.go |
Comprehensive test coverage for policy server functionality |
ratelimit_test.go |
Unit tests for rate limiter logic including edge cases |
lookup_test.go |
Migrated tests from server_test.go with updated naming |
docker-compose.yml |
Added port 10003 and policy delegation configuration for Postfix |
README.md |
Documented new policy server and rate limiting configuration |
.github/copilot-instructions.md |
Updated architecture documentation with new server patterns |
Comments suppressed due to low confidence (1)
lookup.go:53
- The
OnConnectionPoolFullcallback is defined in theTCPServerConfigstruct but is never set when creating configs in eitherStartLookupServerorStartPolicyServer. This means when the connection pool is full, the corresponding metric won't be updated.
For consistency and observability, you should add callbacks for both servers. For the lookup server, this could increment a connectionPoolFull metric similar to how the old server.go would have handled it.
0472fee to
c82557d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
c82557d to
a55749c
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.



This pull request introduces a major architectural refactor and new features to the Postfix adapter for Userli. The most significant change is the addition of a new Policy Server for rate limiting via Postfix SMTP Access Policy Delegation, alongside the original lookup server. The documentation, configuration, metrics, and codebase have been updated to reflect this expanded functionality and improved structure. The code now uses a shared TCP server infrastructure, separates lookup and policy logic, and enhances observability with new metrics.
New Features and Architecture:
policy.go) for Postfix rate limiting using SMTP Access Policy Delegation, configurable viaPOLICY_LISTEN_ADDRand documented in both.github/copilot-instructions.mdandREADME.md. [1] [2] [3] [4] [5] [6] [7]tcpserver.go) and aConnectionHandlerinterface, withLookupServerhandling socketmap requests andPolicyServerhandling policy requests. Documentation and diagrams updated accordingly. [1] [2]