Repository navigation
Preserve mailroom metrics privacy - #1754
Conversation
Coverage Report for CI Build 36592281424Coverage increased (+0.2%) to 87.266%Details
Uncovered Changes
Coverage Regressions2 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
118bf7c to
05217e8
Compare
|
CI failing because the .#release devShell cannot build & the Docker job fails only because it waits on that one. NixOS/nixpkgs#563137 has the fix |
05217e8 to
80b88b1
Compare
|
rebased to get past the ci issues fixed by temporary measure in 251f6a0 seeking review |
benalleng
left a comment
There was a problem hiding this comment.
CACK There is one thing that kind of smells after I gave it a pass with the AI it found something noteworthy. The lock + fswrite jumped out at me as we have had scaling problems in the past so I am just concerned this could become a DOS vector over time.
Everything else looks good though.
| let mut windows = windows.lock().expect("windows lock poisoned"); | ||
| // Every collection runs every gauge callback, so flushing | ||
| // from this one persists the buckets once per export. | ||
| windows.flush(); |
There was a problem hiding this comment.
Since we lock ExportWindows here I think there is too much happening in this callback while this is locked. Namely the file writes within flush() as write_atomically() are doing more than we probably should in this lock.
What do you think about something like where we take a snapshot of the windows for writing later without holding onto it too long.
It possible this isn't really a problem but it did jump out at me as we have had scaling problems in the past.
Logging switched to structured JSON whenever a [telemetry] section was present, so the section did two jobs: it named the OTLP endpoint and it chose the log format. An operator who wanted JSON logs had to configure an export, and one who configured an export got JSON logs whether or not a collector was reading them. Add a top-level log_format key, "text" by default or "json", and build the subscriber from it before any telemetry is set up. The section no longer touches logging. Operators who relied on it for JSON logs add log_format = "json" when they upgrade.
Add settled-window gauges for the four counts eligible to leave the operator boundary: completed requests, started requests, mailbox writes, and tunnel sheds. Each covers the most recently completed Monday-to-Monday UTC week and carries no attributes. Releasing only completed fixed weeks means there is no live value for a prober to watch move and no overlapping windows to difference for daily traffic. The gauges carry exact counts. Rounding to a bin buys nothing. A few units of noise on a counter hides nothing from someone who can send known traffic and subtract it back out. Withholding small counts protects nothing either. A passive viewer would lose only a handful of small values, and the same subtraction recovers them. Remove the unique_short_ids gauge, the HyperLogLog sketches behind it, and the hyperloglogplus dependency. Both lockfiles lose the crate. Every mailbox request fed the sketches a mailbox ID chosen by the client, so they were the one piece of metrics state a client could grow. Beyond what db_entries already counts, they mostly measured mailboxes that were polled and never written, which is also what a flood of made-up IDs looks like. Mailbox writes are the better measure of use and cannot be inflated without storing payloads. Nothing wires the gauges to an exporter yet; the precise instruments registered by MetricsService::new are otherwise unchanged.
Route the OTLP export through the settled-window gauges. With a [telemetry] section present, the export provider now carries only the four coarse weekly gauges; the precise per-request counters and live gauges are registered on a provider with no reader and never leave the process. The export provider is no longer installed as the global meter provider, so no instrument can reach it through the global API and bypass the export-surface test. The exported resource is built from an empty resource, not the SDK default, so the environment detector cannot add hostnames or other attributes through OTEL_RESOURCE_ATTRIBUTES. It carries exactly the service name and operator.domain, and a test pins that key set. The operator_domain config key is unchanged: the label is operator-chosen, the operator's public domain is the expected value, and the Foundation's dashboards group by it. The value is an OperatorDomain newtype that cannot be blank, so a section that would write the same unlabelled series as every other blank one fails at config parse and no code path can build a provider under an empty label. Pushes happen hourly instead of every minute. Every push in a week carries the same frozen settled-week value, so pushing more often adds delivery attempts, not resolution. Hourly still lands the value within an hour of a restart or of an outage ending. Omitting the section exports nothing; there is no separate switch.
80b88b1 to
c1ab704
Compare
The four counter buckets behind the exported weekly gauges lived only in memory. A redeploy mid-week zeroed the settled week, and that week reported as empty. Operators redeploy, so the buckets now live in weekly_counts.txt under storage_dir: eight integers keyed by week in a small text format with a version header, loaded at boot, written by renaming a process-specific temporary file into place so a reader never sees a partial file. The buckets are written once per export collection, from the first gauge callback, and again when the process receives SIGINT or SIGTERM. The serve loops now return on those signals instead of dying in the default handler; connections are dropped as before, the only added work is the write. Writing on every request would cost a syscall per request on a busy node for no benefit, since the export only reads the settled week once an hour, and writing only at shutdown would lose the week on a crash. Between the two, a crash costs at most the counts recorded since the last hourly export. Every request takes the windows lock to count itself, so the write never holds it. The writer copies the counts under that lock, releases it, and only then touches the disk, so a slow fsync delays the writer and nothing else. A separate lock around the storage directory keeps two writers, the hourly export and shutdown, from interleaving or landing an older copy over a newer one. The file is rewritten in full each time; at eight integers there is nothing to gain from tracking which buckets changed. A missing file is a fresh install. An unreadable one is logged and ignored rather than refusing to start; the next write replaces it. Two processes sharing a storage directory cannot corrupt the file, because each renames its own temporary file, but the last writer wins and each exports only its own share of the week. One process per operator_domain is the supported deployment.
Describe in the README what leaves an operator's machine once a [telemetry] section is configured: four settled-week counts, exact and including zero, no attributes on the data points, and a resource of exactly the service name and operator.domain, each rule pinned by a test. Say plainly that operator_domain is chosen by the operator and that their public domain is the expected value, that one process per value is the supported deployment, that precise metrics have no local sink in this release, and what a restart or an outage does to the weekly buckets. Record that logs are never exported. Update config.example.toml to match, fix the README's link to it, and add the changelog entry.
Once a minute, log one INFO line under the target payjoin_mailroom::heartbeat with the requests in flight, the open bootstrap tunnels, and on Linux the process's open file descriptor count and soft limit. The in-flight and tunnel gauges are OpenTelemetry up-down counters, which can only be pushed to a metrics sink, and the export path sends none of them. A descriptor leak announces itself as long-lived tunnels climbing toward the limit over hours, and the structured log every operator already has is the right place to see that curve. The service keeps atomic copies of both counts, updated in the same calls as the instruments, so the heartbeat reads them without touching the meter. The interval is a constant and the line is not gated on the telemetry feature or config: local logs are always there. The descriptor fields come from /proc/self and are omitted on other platforms.
c1ab704 to
007a11e
Compare
|
Good catch. The export callback now copies the counts under the lock, drops it, and writes after, so requests never wait on the fsync. A separate lock around the storage path keeps the hourly write and the shutdown write from stepping on each other, and the request path never takes it. |
Make the mailroom's exported metrics coarse enough that or anyone who sees it cannot follow an individual operator or user's traffic.
Before this change, every node with a
[telemetry]section pushes precise per-request counters and live gauges to Grafana Cloud every minute, labelled with the operator's domain. Operators get no view of those metrics themselves and the only reader is the Foundation's stack. The README did not say what is sent.What the branch does
Read the README diff first; it is the spec. Then the two tests that enforce it (
export_surface_is_windowed_gauges_with_allowed_attributes_onlyinsrc/metrics.rsandexport_resource_carries_only_allowlisted_attributesinsrc/telemetry.rs). The commits add one thing at a time.Two things a reviewer might ask:
Known limits, stated in the README: precise metrics are not observable anywhere while export is on (a local sink is a separate feature TBD); one process per
operator_domain, since two would each write their own share of the week to the same series.Out of scope
_totalcounters to the_weeklygauges. Grafana-side work after merge; theoperator.domainlabel is unchanged so nothing else moves.service.instance.idbranch. This PR pins the resource to two attributes, the opposite design; that branch is parked, not rebased.Disclosure: co-authored by Claude Code