Tiny URL
- Rust 91.3%
- Nix 8.7%
| src | feat: add start of load testing | |
| .env | feat: add set return of set endpoint | |
| .env.example | feat: add start of load testing | |
| .envrc | chore: update envrc watches | |
| .gitattributes | initial skeleton | |
| .gitignore | wip: custom errors nicer with thiserror | |
| Cargo.toml | chore: add clippy lints | |
| flake.lock | flake.lock: Update | |
| flake.nix | feat: add start of load testing | |
| LICENSE | Initial commit | |
| README.md | wip: add notes todo | |
| rust-toolchain.toml | bug: bacon not a rust-toolchain component | |
turl
Tiny URL shortener.
Quick start
# Optionally, remove existing database
# rm ./turl.redb
export TURL=http://localhost:1443
# Set our first URL
curl "${TURL}/set/https%3A%2F%2Fexample.com%2Ffoo" -v
# View all stored URLs
curl $TURL -v
# Try out our redirect
curl "${TURL}/5ea6a25e" -vL
# Load test it
oha --rand-regex-url "${TURL}/set/http%3A%2F%2F[a-z][a-z][0-9]" -z 5s
Notes
The automatic key generation is a lossy hack, they will collide at some point. This is endemic to this solution but arguable solved with allowing longer yet more memorable keys.
I'd prefer to set the default autogenerated names to something like what3words or XKCD password but the crate that exposes it is very stale. What3words crates seem to be API bindings rather than an implementation. Passphrase generators broadly seem toy CLI projects. Also while generated names are more memorable it's more sparse for an equivalent combinatoric space. We'll park this for now.
The retrieve all feature is problematic. Easy DoS attack vector and could tie the database and networking up.
- Add set-with-key feature.
- Add option to log to file
- Add option to send traces to otel collector
- Do some whole-system testing,
(削除) perhaps drill (削除ここまで) - Add punycode, unicode tests. Less happy-pathing.
(削除) Instrument more thoroughly using tracing. (削除ここまで)(削除) Change data store from vector of struct to hashmap (削除ここまで)Switched to embedded Key-Value storeredb(削除) Use a proper backend, ideally decoupled (削除ここまで)As above.- Tests written, needs more granularity but is good.
(削除) Write tests - in progress. ref 1 ref 2 (削除ここまで) - Mostly JSON responses now.
(削除) Fix return on set mismatched content-type (削除ここまで) - Pull config and state management out into its own struct and use MPLS to interact with it. This will avoid littering implementation with Arc<Mutex<_>>.
- Pull WoL and SSH shutdown into its own struct and use MPLS to RPC. The new struct can handle retries maybe, and hopefully makes swapping out machine stop/start implementations easier (use trait).
- Code is 200 presently as clients don't need to know it was already set.
This will definitely change when set with key is introduced.
http code discussion
(削除) Change HTTP response code when attempting to mutate immutable store (削除ここまで)