ENGINEERING NOTE / 18 SQL SERVERPOSTGRESQLOBSERVABILITY

A Finding Needs an Identity Before It Can Have a History

Every health report found the same problems as the last one, and none of them knew it. Giving findings a memory turned out to be two data-modelling decisions: what makes two sightings the same finding, and what counts as proof that it has gone.

8 MIN READ

OBSERVABILITYPROMETHEUSDATA-MODELLINGPLATFORM-ENGINEERINGMCP

TABLE OF CONTENTS
  1. The key is the design
  2. Fold per host, not per series
  3. A lifecycle, not a list
  4. Resolving is the hard half
  5. Metrics that only exist while something fails
  6. A combined rule needs its companion
  7. Narrowing what feeds it
  8. Production findings for people outside production
  9. What I would take from it

The operations portal I built for our database estate had two ways of telling you what was wrong: a health report built from the exporter’s threshold breaches, and analysis runs that captured an instance and ran rules over it. Both were accurate. Neither had a memory. Every report and every run rediscovered the same breaches from scratch, so the first question anyone asks about a problem, have we seen this before, and since when?, had no answer.

The command center note covers this in a few paragraphs. This is the longer version, because the interesting part was not the table or the page. It was deciding what a finding is.

The key is the design§

A tracker needs to know when two sightings are the same finding. Get that wrong in one direction and every sighting opens a new item, which is just the report again with extra steps. Get it wrong in the other and different problems merge into one.

The rule I settled on: one item per host, port and finding. For a threshold breach the finding is the metric plus the labels that name an object: a volume, a job, a node. Two things are deliberately left out of the key.

Environment and engine. They describe the host, not the problem, so a relabelled host keeps its items.

Labels that describe a condition. A database’s state and access, a cluster node’s role, a volume’s display name. These change while the problem stays the same. A database that goes from RESTORING to OFFLINE is still one unavailable database, not a resolved finding and a new one. So those labels go into the item’s evidence, not its key.

VERIFIED what goes where (illustrative)
series:   database_unavailable{host="db-a", port="1433", env="qa",
                             database="app_01", state="RESTORING"}

key:      metric + host + port + naming labels      -> database_unavailable|db-a|1433|{}
evidence: worst value, threshold, state="RESTORING", databases breaching, worst five
ignored:  env, engine                               (they describe the host)

Fold per host, not per series§

Some metrics are published per database: backup age, log space used, database unavailable. On instances that hold thousands of databases, one item per breaching series would bury everything else. So a database-scoped metric folds into one item per host, with the number of breaching databases counted and the worst five named in the evidence.

Breaching backup-age series
19,036
Backup-age items after folding
9
Threshold items in all
39

That is the whole difference between a list someone reads and a list someone filters out.

A lifecycle, not a list§

Once a finding has a key, it can have a life. An item opens on its first sighting. Every later sighting counts it, refreshes when it was last seen and replaces the evidence with the latest. If it was resolved and comes back, it reopens with its history intact rather than starting again.

The history lives in its own table of events (opened, reopened, resolved), each with a copy of the evidence at the time, so the record outlives the raw rows it came from. A plain re-sighting is not an event: it updates the count and the last-seen time. A host is checked every few minutes, and a history that logs every check is not a history anyone reads.

The findings tracker list: one row per finding and host, with severity, state, the metric and its latest value against the threshold, how many databases breach, how many times it has been seen, how long it has been open and when it was last seen.
The tracker: each row is a finding with a key, so it can show a sighting count and an age.

Two smaller rules keep the lifecycle honest.

  • Out-of-order feeds change nothing. A feed older than an item’s last sighting, or older than the last feed for that host, leaves the item alone. Late data cannot reopen something resolved after it, or move last_seen backwards.
  • One feed per host at a time. A transaction-scoped advisory lock per host makes the feed serial for that host.

Resolving is the hard half§

Opening an item is easy: a breach is evidence. Resolving one is where a tracker either earns trust or loses it, because not seeing a breach is not the same as seeing that it is gone. A check that failed to connect also sees no breaches.

So an item resolves by itself only on evidence that it has gone: the series no longer breaches and that check actually collected the metric on that host. If the metric has no samples this time, because a query failed after a restart or the host was not covered, nothing resolves.

  1. 01 CHECK FAILED

    It can open and re-see items, but it resolves nothing. What it left behind may be the previous check's values.

  2. 02 METRIC NOT COLLECTED

    No samples of the metric on this host this time. Absence proves nothing, so the item stays open.

  3. 03 METRIC COLLECTED, NOT BREACHING OBSERVED

    The check looked and found it under the threshold. The item resolves.

The first live test showed why this matters. One report was taken just after an exporter restart, with 22 of 26 hosts covered. It opened 18 items and resolved nothing on the four hosts it could not see. The next report covered all 26: it saw the same 18 again, opened 21 more and resolved none. A naive “not in this report, so fixed” rule would have closed and reopened items on four hosts for no reason.

Metrics that only exist while something fails§

Three metrics broke the simple rule: recent job failures and the two “database unavailable” gauges. Their series exist only while something is wrong; the exporter removes a job step’s series once it succeeds and a database’s once it is usable again. When the problem is fixed, there are no samples at all, which looks exactly like a query that never ran.

For these, absence counts as evidence only when every collection signal of the host is healthy (database, SSH, WinRM, error log) and the specific collector step that publishes the metric reported success in the same check. That needed a new gauge from the collectors, one per step, because nothing else could prove the query had run. Review had already rejected the first alternative: a retry counter in the check queue, which resets on reschedule and so proves nothing.

A combined rule needs its companion§

Some rules are two conditions: swap used above a threshold while pages are being swapped in faster than a floor. The home page’s query joins the two series, so without the swap-in rate nothing matches. The tracker evaluated the same rule through shared code that falls back to the first condition alone when the companion series is missing. That fallback is right for a report’s text, which should never drop a real problem.

It was wrong for the tracker. The swap-in rate is a rate between two checks, so it has no value on a host’s first check after the exporter starts. Once the tracker was fed on every check, every Linux host holding any swap opened an item after a restart, and the home page showed none of them. Now the tracker requires the companion, as the home page does, and an item of a combined rule does not resolve on a check without it either. Otherwise a restart would resolve the real items and then reopen them.

Narrowing what feeds it§

The first version was fed by health reports and finished analysis runs. Analysis findings needed their own coverage logic (a rule’s finding could only resolve if that rule had been evaluated on complete data, and a capture with any gaps resolved nothing), and it worked, but it made the tracker two systems with one page.

Two and a half weeks later I narrowed it: only the exporter’s own checks feed the tracker. After every queue check of a host, the worker reads that host’s series and feeds them. A check updates only its own host’s items. Analysis findings stay on their run pages. The resolution rules did not change; the evidence just arrives every few minutes per host rather than once per report, and from one source whose coverage is easy to reason about.

Production findings for people outside production§

Production has no inbound access, so nobody outside it could see what the production portal saw. The relay closes that gap without opening one. The production portal publishes its current problems and open tracked findings as a single findings.json file, committed to an orphan data branch of a repository. A small read-only server outside production reads that file and serves it two ways: as a page, and as an MCP server with three read-only tools. An agent can ask what is wrong in production and get an answer without holding any production credentials.

VERIFIED the relay's shape
production portal  --commit-->  data branch: findings.json  <--read--  read-only server
                                                                       |-- page
                                                                       |-- MCP: summary, current problems, findings list

The publisher runs every 10 minutes by default and commits only when the content changed. That raised the same question as the tracker, one level up: what counts as a change?

  • Values that grow on their own are not a change. Each current problem carries the series that breach, with their values. A backup’s age in hours grows every minute, so a hash over the values would commit every 10 minutes forever. The content hash leaves series values out. A new failing job or database still changes it; the values shown refresh with the next real commit.
  • Re-sightings are not a change. Every check re-sees items and updates last_seen, the count and the evidence. Those fields are left out of the hash too. An item opening, resolving, reopening, or changing state or severity does commit.
  • Silence is distinguishable from “stopped”. A heartbeat commit at least every six hours lets a reader tell “nothing changed” from “the publisher died”.
  • Replicas are not separate problems. The same series from each exporter replica differs only in a label the page hides. Those collapse into one row with the worst value, so a failing job shows once rather than once per replica.

Every value in the file is data from the hosts, so the page escapes all of it and its content security policy blocks outside resources.

What I would take from it§

A findings tracker looks like a UI feature and is really a schema. The two decisions that made it work were both about data: a key that stays stable while the problem stays the same, and a resolution rule that demands positive evidence rather than accepting absence. The relay’s change hash is the same decision again: decide what identifies a state, leave out what merely moves, and the noise goes with it.