Skip to content

Commit 477a759

Browse files
committed
feat: add backend middleware analytics for prometheus
* Add custom metrics to estimate unique visitors. * Add custom metrics to estimate usefull client information (browser, os, device) * Add PRIVACY.md file Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent 3c9ac93 commit 477a759

10 files changed

Lines changed: 959 additions & 0 deletions

File tree

PRIVACY.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Privacy Policy
2+
3+
This Privacy Policy explains what data the KernelCI Dashboard collects when you
4+
use it, why, and how we protect it. It is written for users of the service.
5+
Operators deploying the Dashboard are responsible for keeping this document
6+
accurate for their own instance and for surfacing it to their users.
7+
8+
## Summary
9+
10+
The KernelCI Dashboard collects **anonymous, aggregate usage analytics** only.
11+
We do **not** build user profiles, do **not** sell data, and do **not** store
12+
any personal identifier.
13+
14+
## What we collect
15+
16+
When you make requests to the Dashboard API (`/api/`), the backend records
17+
aggregate usage metrics. These are stored only as counts (Prometheus counters),
18+
never as per-user records or per-user timestamps:
19+
20+
- **Request attributes**: the API endpoint name, HTTP method, response status
21+
class (e.g. `2xx`), and coarse client buckets derived from your browser's
22+
User-Agent (e.g. browser family `Chrome`, operating system `Linux`, device
23+
type `desktop`). Automated clients are bucketed as `bot`.
24+
- **Referrer domain**: only the external domain that linked you to the
25+
Dashboard (e.g. `example.org`). Same-site and direct visits are recorded as
26+
`direct_or_internal`. The full referring URL is never stored.
27+
- **Unique visitor estimates**: daily de-duplicated visit counts, in total and
28+
per endpoint.
29+
30+
## What we do NOT collect or store
31+
32+
- Your raw IP address.
33+
- Your raw, full User-Agent string.
34+
- The full referrer URL or any query parameters.
35+
- Any account, name, email, or other directly identifying information.
36+
- Any cross-day or long-term tracking identifier.
37+
38+
## How unique visitors are counted
39+
40+
To estimate unique visitors without identifying you, the backend:
41+
42+
1. Computes a one-way fingerprint as
43+
`HMAC-SHA256(daily_salt, "<your_ip>|<your_user_agent>")`.
44+
2. Uses a `daily_salt` — a random 32-byte secret generated fresh each UTC day,
45+
held only in an in-memory cache (Redis) with a ~25 hour lifetime, never
46+
written to disk.
47+
3. Uses only the resulting hash as a short-lived de-duplication key. Your raw
48+
IP and User-Agent are discarded immediately after the hash is computed and
49+
are never written to any metric or to disk.
50+
51+
Because the salt is secret and rotates every day, fingerprints cannot be linked
52+
across days, and the hash cannot be reversed back to your IP/User-Agent in
53+
practice.
54+
55+
## Legal basis and retention
56+
57+
- **Purpose**: understanding aggregate usage and load to operate and improve
58+
the service.
59+
- **Legal basis** (where GDPR applies): legitimate interest in operating and
60+
improving the service, using the most privacy-preserving design we can.
61+
- **Retention**: the transient daily fingerprints and salt expire automatically
62+
within ~25 hours. Only anonymous aggregate counters are retained beyond that;
63+
these contain no personal data.
64+
65+
## Your rights
66+
67+
Because we retain only anonymous, aggregate counts and hold no identifier that
68+
can single you out beyond a single day, we cannot link any stored data to a
69+
specific person and therefore cannot act on individual access/deletion requests
70+
against the aggregate metrics. If you have questions about privacy on a specific
71+
deployment, contact that deployment's operator.
72+
73+
## Changes
74+
75+
We may update this policy as the service evolves. Changes are tracked in the
76+
repository's git history.
77+
78+
## Technical reference
79+
80+
For implementation details, see
81+
[`docs/monitoring.md`](docs/monitoring.md#client-analytics).

backend/kernelCI/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def get_json_env_var(name, default):
8989
"django.contrib.messages.middleware.MessageMiddleware",
9090
"django.middleware.clickjacking.XFrameOptionsMiddleware",
9191
"kernelCI_app.middleware.logServerErrorMiddleware.LogServerErrorMiddleware",
92+
"kernelCI_app.middleware.backendRequestMetricsMiddleware.BackendRequestMetricsMiddleware",
9293
"django_prometheus.middleware.PrometheusAfterMiddleware",
9394
]
9495

0 commit comments

Comments
 (0)