good stuff
This commit is contained in:
parent
ea8389ef40
commit
f4de0eeb9f
39 changed files with 5165 additions and 348 deletions
|
|
@ -44,11 +44,69 @@ pub async fn track_metrics(request: Request<Body>, next: Next) -> Response {
|
|||
}
|
||||
|
||||
/// Normalize paths to avoid high cardinality from dynamic segments.
|
||||
///
|
||||
/// Groups dynamic segments into parameterized placeholders and collapses
|
||||
/// static assets, PocketBase proxy paths, and unknown paths to prevent
|
||||
/// Prometheus label cardinality explosion from bot scans and unique URLs.
|
||||
fn normalize_path(path: &str) -> String {
|
||||
// Tiles: /api/tiles/5/16/10 → /api/tiles/:z/:x/:y
|
||||
if path.starts_with("/api/tiles/") && !path.ends_with("style.json") {
|
||||
return "/api/tiles/:z/:x/:y".to_string();
|
||||
}
|
||||
path.to_string()
|
||||
// Invite API: /api/invite/abc123 → /api/invite/:code
|
||||
if path.starts_with("/api/invite/") {
|
||||
return "/api/invite/:code".to_string();
|
||||
}
|
||||
// PocketBase proxy: /pb/api/files/... → /pb/api/files/:path
|
||||
if path.starts_with("/pb/api/files/") {
|
||||
return "/pb/api/files/:path".to_string();
|
||||
}
|
||||
// PocketBase proxy: /pb/api/... → keep collection-level granularity
|
||||
if path.starts_with("/pb/api/collections/") {
|
||||
// /pb/api/collections/users/auth-with-password → keep as-is (bounded set)
|
||||
// /pb/api/collections/saved_searches/records/abc → /pb/api/collections/saved_searches/records/:id
|
||||
let parts: Vec<&str> = path.splitn(6, '/').collect();
|
||||
if parts.len() >= 6 && parts[4] == "records" {
|
||||
return format!("/pb/api/collections/{}/records/:id", parts[3]);
|
||||
}
|
||||
return path.to_string();
|
||||
}
|
||||
// Short URLs: /s/abc → /s/:code
|
||||
if path.starts_with("/s/") {
|
||||
return "/s/:code".to_string();
|
||||
}
|
||||
// Invite pages: /invite/abc → /invite/:code
|
||||
if path.starts_with("/invite/") {
|
||||
return "/invite/:code".to_string();
|
||||
}
|
||||
// Static assets: /assets/* → /assets/:file
|
||||
if path.starts_with("/assets/") {
|
||||
return "/assets/:file".to_string();
|
||||
}
|
||||
// Known application routes and API endpoints — keep as-is
|
||||
if path.starts_with("/api/")
|
||||
|| matches!(
|
||||
path,
|
||||
"/" | "/health"
|
||||
| "/metrics"
|
||||
| "/dashboard"
|
||||
| "/pricing"
|
||||
| "/account"
|
||||
| "/saved"
|
||||
| "/invites"
|
||||
| "/learn"
|
||||
| "/bundle.js"
|
||||
| "/main.css"
|
||||
| "/favicon.ico"
|
||||
| "/house.png"
|
||||
| "/robots.txt"
|
||||
| "/sitemap.xml"
|
||||
)
|
||||
{
|
||||
return path.to_string();
|
||||
}
|
||||
// Everything else (bot scans, probes, etc.) → /other
|
||||
"/other".to_string()
|
||||
}
|
||||
|
||||
/// Handler for the /metrics endpoint.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue