Skip to content

Event log: durable store and read endpoint with labels, severity and error episodes #4432

Backlog
0 of 4 issues completed

Description

@pithead-architect

What's the problem

Part of #4431, the Event log. The dashboard has no store for system events with a label and a severity, and no single read path:

  • The events table (ts, type, detail, no id) is a chart-marker store. It is held in memory and fed to chart.events, so it cannot hold error episodes that need updating, and it should not grow with non-chart entries.
  • Payouts, shares, blocks, raffle wins and settings changes live in their own tables.
  • On develop-v2.1.0, build_mining_activity (dashboard/mining_dashboard/web/views/overview_views.py:72, called at web/views/views.py:305) merges some of them for Overview, with a browser fallback in web/static/sovereign/overview-model.mjs:200.

What it impacts

Every later Event log piece (#4433, #4434, #4435) and #3735's donation entries need this store and endpoint first.

How I found it

A read-only read of develop-v2.1.0 at bfd061f:

  • storage_schema.py: the events table;
  • service/storage_service.py:309: add_event;
  • overview_views.py:72: build_mining_activity;
  • config/config.py:535: HISTORY_RETENTION_SEC, 30 days.

How important is it

Medium. It is the first piece of #4431, and the other three wait for it.

Acceptance criteria

Store

  • A new event_log table, separate from events, with these columns: id, ts, end_ts, count, kind, subject, label, severity (info, warning or error) and text.

  • Producers call one helper, record_event(kind, subject, label, severity, text_template, slots).

  • add_event keeps feeding the chart unchanged. The legacy hashrate_loss and hashrate_recovered rows are shown under the System label at read time.

  • Error episodes are keyed by (kind, subject):

    • the first failure opens an episode;
    • each repeat increments its count and updates its last time;
    • the episode closes at the first success of that check, or after 30 minutes with no repeat, whichever comes first.
    • Fake-clock tests cover open, repeat, close by success, close by timeout, and a re-open after close.
  • Retention is 30 days (HISTORY_RETENTION_SEC) or 5,000 rows, whichever comes first, oldest first, with at most one new entry per (kind, subject) per minute. A test inserts 20,000 events in one minute, then asserts there are at most 5,000 rows and that the last hour's error entries are still present.

  • Entry text comes from fixed sentence templates, never from free text. It never contains:

    • a wallet or onion address, view key, password or token;
    • a transaction id, IP address, user name or rig hostname;
    • a raw exception class name, raw config key or URL.

    Payout text may state the chain and the amount. A test feeds each forbidden kind of value through record_event and asserts none of them appears in the stored text or in the response.

Read endpoint

  • GET /api/events?range=day|week|month|all&label=<l>[&label=<l>]&severity=error returns {entries, counts}:
    • range is the only time control, with no from/to;
    • at most 500 entries, newest first, each with id, ts, end_ts, count, label, severity and text;
    • counts has one figure per label for the selected range.
  • Existing rows appear through the read merge, with their labels and the same templates. They are not copied into event_log, so one payout gives exactly one entry, and a test proves it:
    • payouts: one entry per saved payout, "Payout received: XMR reached your wallet" (or XTM), label Payouts;
    • shares and blocks: label Shares and blocks;
    • raffle_wins: label XvB;
    • audit_events: label Settings, in plain words with no raw keys.
  • Settings entries are returned only where and to whom /api/audit is available today. A test covers both cases.
  • /api/events replaces build_mining_activity and its browser fallback as the single source for the Overview Activity list.
  • Endpoint tests cover each label, several labels at once, severity=error, each range, an empty result and the 500 cap.
  • docs/dashboard.md documents the endpoint and the labels.
  • make test, make test-patch-coverage and make lint-file-budget pass.

Possible solutions

  • A new event_log table and a read merge over the existing tables (recommended). Nothing is written twice, and history from before the upgrade shows up.
  • Extend events with label and severity. It has no id, so episodes cannot be updated in place. It is also loaded into memory and into the chart payload, so non-chart rows would bloat both.

Sub-issues

Sub-issues

0 of 4 Issues completed
Loading 4 sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    dashboardenhancementsize:Ltracker

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions