-
Notifications
You must be signed in to change notification settings - Fork 1
Worker: /v1/events + /v1/stats/summary (KV-backed, free tier) #6
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a53d3b
worker: move from wick-pro, add /v1/events + /v1/stats/summary
myleshorton 0c5d844
worker: switch /v1/events to KV (drop Analytics Engine dependency)
myleshorton 47936ee
Merge remote-tracking branch 'origin/main' into worker-analytics-engine
myleshorton 1c6d726
Address PR #6 review comments
myleshorton e646567
worker: remove /pro/* Stripe subscription flow
myleshorton b02d8a9
Address PR #6 review comments (round 2)
myleshorton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # wick-releases Worker | ||
|
|
||
| Cloudflare Worker backing `releases.getwick.dev`. Handles: | ||
|
|
||
| - **Release distribution** — signed downloads of prebuilt binaries from R2. | ||
| - **Usage telemetry ingest** — two endpoints: | ||
| - `POST /ping` (legacy) — daily usage pings + failure reports, aggregated into KV. | ||
| - `POST /v1/events` — per-fetch telemetry `{host, strategy, ok, status, timing_ms, …}` stored in KV. | ||
| - **Public stats** — `GET /v1/stats/summary` aggregates 7 days of KV-stored events. The renderer (`site/stats.html`) ships in a follow-up PR; this endpoint is usable on its own in the meantime. Cached 5 min in KV. | ||
| - **Legacy analytics dashboard** — `GET /analytics/:key` (KV-based, auth-gated). | ||
|
|
||
| Everything here runs on Workers Free — no Analytics Engine, no paid Workers plan required. If Wick grows past the free KV limits, the `/v1/events` handler can be swapped for Analytics Engine by flipping a binding. | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| cd worker | ||
| npx wrangler dev # local preview | ||
| npx wrangler tail # live logs from the deployed worker | ||
| ``` | ||
|
|
||
| ## Deployment | ||
|
|
||
| ```bash | ||
| npx wrangler deploy | ||
| ``` | ||
|
|
||
| ### One-time setup | ||
|
|
||
| Bindings declared in `wrangler.toml`: | ||
|
|
||
| - `RELEASES` — R2 bucket `wick-releases` | ||
| - `SUBSCRIPTIONS` — KV namespace (holds Pro keys, legacy ping counters, per-fetch event counters under `evt:` prefix, and the 5-min stats cache) | ||
|
|
||
| Secrets (set via `wrangler secret put`): | ||
|
|
||
| - `API_KEYS` — JSON object of Pro customer keys (legacy, kept for existing customers). | ||
|
|
||
| No additional secrets needed for the telemetry endpoints. | ||
|
|
||
| ## Telemetry schema | ||
|
|
||
| `POST /v1/events` accepts JSON: | ||
|
|
||
| ```json | ||
| { | ||
| "host": "nytimes.com", | ||
| "strategy": "cef", | ||
| "escalated_from": "cronet", | ||
| "ok": true, | ||
| "status": 200, | ||
| "timing_ms": 1840, | ||
| "version": "0.9.2", | ||
| "os": "macos" | ||
| } | ||
| ``` | ||
|
|
||
| Stored in `SUBSCRIPTIONS` KV as one key per `(date, host, strategy)`: | ||
|
|
||
| | Field | Format | | ||
| |---|---| | ||
| | Key | `evt:YYYY-MM-DD:{host}:{strategy}` | | ||
| | Value | `{"fetches": N, "successes": M, "total_ms": T}` (JSON) | | ||
| | TTL | 30 days | | ||
|
|
||
| Increments are read-modify-write, same pattern as the legacy `/ping` counters. Under heavy concurrency a small number of increments may be lost; this is fine for telemetry. | ||
|
|
||
| What's **not** stored: URL paths or query strings, request/response bodies, page titles, caller IP (Cloudflare sees it at ingest, but it's never persisted as a data point), user identifier, machine ID. | ||
|
|
||
| ## Querying | ||
|
|
||
| `GET /v1/stats/summary` does the aggregation and returns shaped JSON. The public renderer (`site/stats.html`) ships in a follow-up PR. | ||
|
|
||
| For ad-hoc debugging you can list KV keys directly: | ||
|
|
||
| ```bash | ||
| npx wrangler kv key list --binding=SUBSCRIPTIONS --prefix='evt:' | head -20 | ||
| npx wrangler kv key get --binding=SUBSCRIPTIONS 'evt:2026-04-21:example.com:cronet' | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.