-
Notifications
You must be signed in to change notification settings - Fork 24
fix(dgw)!: switch traffic audit IDs from INTEGER to ULID #1597
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
fix(dgw)!: switch traffic audit IDs from INTEGER to ULID #1597
Conversation
Replace INTEGER PRIMARY KEY with 16-byte BLOB (ULID) for traffic audit event IDs to avoid overflow issues with persisted, ever-increasing IDs. - Auto-detect old INTEGER schema via PRAGMA table_info and reset database - Store ULIDs as 16-byte BLOBs (lexicographically sortable) Issue: DGW-321
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 migrates the traffic audit database from using auto-incrementing INTEGER PRIMARY KEYs to ULIDs (Universally Unique Lexicographically Sortable Identifiers) stored as 16-byte BLOBs to prevent ID overflow issues with persisted, ever-increasing integer values.
Key Changes:
- Replaced INTEGER PRIMARY KEY with BLOB PRIMARY KEY (16-byte ULID) in the database schema
- Implemented automatic detection of old INTEGER schema with database reset on first startup
- Updated API endpoints to use ULID string format instead of i64 integers
Reviewed changes
Copilot reviewed 27 out of 28 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/traffic-audit-libsql/migrations/01_traffic_events.sql | Changed id column from INTEGER to BLOB with 16-byte length constraint |
| crates/traffic-audit-libsql/src/lib.rs | Added ULID generator, old schema detection logic, database reset functionality, and ULID/BLOB conversion utilities |
| crates/traffic-audit-libsql/Cargo.toml | Added ulid crate dependency |
| crates/traffic-audit/src/lib.rs | Updated ClaimedEvent struct and TrafficAuditRepo trait to use Ulid instead of i64 |
| crates/traffic-audit/Cargo.toml | Added ulid crate dependency |
| crates/traffic-audit-libsql/tests/integration.rs | Updated all integration tests to use Ulid instead of i64 for event IDs |
| devolutions-gateway/src/traffic_audit.rs | Updated TrafficAuditMessage enum and handle methods to use Ulid |
| devolutions-gateway/src/api/traffic.rs | Changed AckRequest and ClaimedTrafficEvent to use Ulid type with OpenAPI schema annotations |
| devolutions-gateway/Cargo.toml | Added ulid crate with serde feature |
| devolutions-gateway/tests/traffic.rs | Updated all API tests to use Ulid instead of i64 |
| testsuite/tests/cli/dgw/traffic_audit.rs | Added new test for old schema detection and automatic migration |
| testsuite/tests/cli/dgw/mod.rs | Added traffic_audit test module |
| testsuite/Cargo.toml | Added libsql dependency for test schema verification |
| devolutions-gateway/openapi/gateway-api.yaml | Updated OpenAPI spec to use string type for IDs instead of int64 |
| devolutions-gateway/openapi/ts-angular-client/model/*.ts | Updated TypeScript client types from number to string for IDs |
| devolutions-gateway/openapi/dotnet-client/src/Devolutions.Gateway.Client/Model/*.cs | Updated .NET client types from long to string for IDs |
| devolutions-gateway/openapi/dotnet-client/Devolutions.Gateway.Client.csproj | Bumped version to 2025.12.2 |
| devolutions-gateway/openapi/dotnet-client/config.json | Updated package version |
| devolutions-gateway/openapi/dotnet-client/Client/Configuration.cs | Updated version constants |
| devolutions-gateway/openapi/dotnet-client/docs/*.md | Updated documentation to reflect string IDs |
| devolutions-gateway/openapi/doc/index.adoc | Updated API documentation with ULID format |
| docs/COOKBOOK.md | Updated example event IDs to ULID format and added ULID documentation notes |
| devolutions-gateway/src/openapi.rs | Consolidated imports (stylistic cleanup, no functional change) |
| Cargo.lock | Added ulid dependency with serde support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
pacmancoder
left a comment
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.
Looks good overall, disabled auto-merge due to Copilot comments
| thread_local! { | ||
| /// Per-thread monotonic ULID generator. | ||
| /// | ||
| /// Using a thread-local generator provides several benefits: | ||
| /// - **Strict monotonicity within a thread**: ULIDs generated in sequence on the same | ||
| /// thread are guaranteed to be strictly increasing, even when generated within the | ||
| /// same millisecond. This ensures predictable ordering in tests and deterministic | ||
| /// FIFO behavior for events pushed from the same thread. | ||
| /// - **No contention**: Each thread has its own generator instance, eliminating mutex | ||
| /// overhead that would occur with a shared generator. | ||
| /// - **Lock-free push operations**: The `push` method can generate IDs without acquiring | ||
| /// any locks beyond the thread-local cell borrow. | ||
| static MONOTONIC_ULID_GENERATOR: std::cell::RefCell<ulid::Generator> = const { std::cell::RefCell::new(ulid::Generator::new()) }; | ||
| } |
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.
@pacmancoder Here is a likely better approach 👍
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 27 out of 28 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Replace INTEGER PRIMARY KEY with 16-byte BLOB (ULID) for traffic audit event IDs to avoid overflow issues with persisted, ever-increasing IDs.
Issue: DGW-321
BREAKING CHANGE: The traffic audit HTTP endpoints are now expecting ULIDs instead of integers.