Commit 78d1c29
feat(mcp): add monitor L2 read tools — per-table events, configs, and schema-change audit (TG-1092)
Three drill-down tools on top of the L1 group / table inventory:
- list_monitor_events(table_group_id, table_name, monitor_type, monitor_id?,
include_predictions?, limit?, page?) — per-table event history scoped to one
monitor type. monitor_id is required when monitor_type="metric" (Metric is
the only multi-instance type — singletons reject monitor_id with a clear
pointer). Per-type column shapes:
* Volume: Time | Status | Row count | Lower bound | Upper bound
* Freshness: Time | Status | Update detected | Detail
(parsed from the SQL template's structured message)
* Schema: Time | Status | Table change | Columns added | Columns dropped | Columns modified
* Metric: Time | Status | Value | Lower bound | Upper bound
(metric name in the heading, not as a column)
include_predictions=True appends a separate `## Forecast` section listing
future timestamps with predicted bounds — never interleaved into the
historical events. Schema short-circuits to "not applicable"; non-
Prediction-Model monitors render a "not available" note.
- list_monitors(table_group_id, table_name) — configured monitors for a
table. Per row: monitor_id, type (Title Case, reuses _MONITOR_LABEL),
metric_name, threshold mode (derived from history_calculation:
"PREDICT" → Prediction; non-empty otherwise and not Freshness →
Historical; empty → Static), bounds, and the metric expression for
Metric monitors. Sensitivity is surfaced as a top-level "Prediction
model sensitivity" field.
- list_monitor_schema_changes(table_group_id, table_name?, since?,
limit?, page?) — newest-first audit log of column-level schema events
(added / dropped / modified), independent of monitor-run results.
All three follow the L1 contract: gated on view, resolve_monitored_table_group
returns the literal "This table group is not monitored." when the group has
no linked monitor suite, and never expose internal test_type codes,
test_definition_id, or test_suite_id on the surface.
Backing model methods:
- DataStructureLog ORM wraps the existing data_structure_log audit table
(no ORM mapping until now) and exposes list_for_table_group(*, table_name,
since, until, page, limit). The dashboard's get_data_structure_logs
delegates here.
- TestDefinition.list_monitor_configs_for_table returns MonitorConfig with
threshold_mode derived per row.
- TestDefinition.get_singleton_monitor(suite, table, type) for the non-
metric forecast lookup path.
- forecast_points_from_prediction(prediction, sensitivity) — standalone
helper that reads forecast rows from the prediction JSONB using epoch-ms
keys with numeric comparison (matches the dashboard's reader).
- TestResult.list_monitor_events_for_table runs the dashboard's CTE under
the ORM with optional monitor_type filtering. ORDER BY includes
results.id NULLS LAST, active_runs.id as a stable tiebreaker so the
Python-side pagination doesn't duplicate or skip rows on test_time ties.
- TestResult.list_metric_monitor_events — separate, simpler query path
for Metric (no run-by-type CROSS JOIN, no synthesized pending rows).
The dashboard's per-type events transform stays in monitors_dashboard.py
because its shape is bespoke to the chart payload; centralizing just the
SQL would still require a non-trivial adapter on the dashboard side.
monitor_id joins the Followable IDs table as an alias for the underlying
test_definition.id UUID — the abstraction stays stable if monitors move
to a dedicated table later.
Status helpers (_summary_status, _format_monitor_cell, _format_schema_cell,
_event_status) return Title Case ("Error", "Pending", "Training",
"Anomaly", "Ok"), matching the rest of the MCP layer. parse_monitor_type
accepts either case so values round-trip.
_parse_kv_pairs splits input_parameters on ";" (matches the writer side
at execute_tests_query.py:321 and the dashboard's dict_from_kv).
Closes TG-1092
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent e473ec1 commit 78d1c29
10 files changed
Lines changed: 1785 additions & 56 deletions
File tree
- testgen
- common/models
- mcp
- tools
- ui/views
- tests/unit/mcp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
273 | 364 | | |
274 | 365 | | |
275 | 366 | | |
| |||
557 | 648 | | |
558 | 649 | | |
559 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
560 | 740 | | |
561 | 741 | | |
562 | 742 | | |
| |||
0 commit comments