Skip to content

catalog: builtin metric sinks types, catalog item, and lowering (SQL-554)#37841

Open
mtabebe wants to merge 1 commit into
MaterializeInc:mainfrom
mtabebe:ma/prom-metrics/sql-554
Open

catalog: builtin metric sinks types, catalog item, and lowering (SQL-554)#37841
mtabebe wants to merge 1 commit into
MaterializeInc:mainfrom
mtabebe:ma/prom-metrics/sql-554

Conversation

@mtabebe

@mtabebe mtabebe commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Problem:

The Prometheus cluster metrics feature needs the authoring type, catalog representation, and lowering for builtin metric sinks.

Nothing gets installed and there's no runtime behavior change yet.

The abstraction is the generic, backend-agnostic MetricSink, not a Prometheus-specific one.

Solution:

  • Add the BuiltinMetricSink authoring type, along with BuiltinMetricSinkValue, MetricSinkKind, a Builtin::MetricSink variant.
  • builtin_metric_sink_view_sql projects a sink's query into the canonical MetricSink row shape (metric_name, metric_type, labels, value, help), UNION ALL-ed across the value columns.
  • Each sink materializes a companion BuiltinView (the canonical shape, built at enumeration time) plus a thin CatalogItem::MetricSink that points at it.
  • Add CatalogItemType::MetricSink (rendered metric-sink) and the CatalogItem::MetricSink, MetricSink, and MetricSinkValue structs, then wire them through every exhaustive match
  • Boot construction builds the item directly (create_sql: None)
  • For discoverability, the mz_metric_sinks_raw backing table (populated in builtin_table_updates) feeds the mz_internal.mz_metric_sinks view and mz_catalog.mz_objects (as type = 'metric-sink'). Note: It's registered before mz_objects in the builtin list, since a builtin view can only depend on lower-id builtins.
  • Register the first concrete sink, mz_metric_dataflow_errors, with companion view mz_metric_dataflow_errors_shaped. No dataflow is installed here.

Testing:

  • Unit tests for the lowering
  • catalog-protos snapshot consistency tests

Note to reviewers:

The most important things to review are:

  • src/catalog/src/builtin.rs — the BuiltinMetricSink types + the concrete mz_metric_dataflow_errors sink
  • src/catalog/src/builtin/builtin.rs — the lowering + make_mz_metric_sinks
  • src/catalog/src/memory/objects.rs — the CatalogItem::MetricSink modeling
  • src/adapter/src/catalog/apply.rs — boot construction
  • src/catalog/src/builtin/mz_internal.rs — the mz_metric_sinks_raw table
  • src/adapter/src/catalog/builtin_table_updates.rs — pack_metric_sink_update
  • src/adapter/src/optimize/metric_sink.rs — lowering tests

There are some mechanical changes (exhaustive-match arms for the new CatalogItem::MetricSink variant across sql/ and adapter/coord/, plus new OIDs) or generated changes (objects_v91.rs, the encoding snapshot, and the regenerated SLT/testdrive golden files)

@mtabebe
mtabebe force-pushed the ma/prom-metrics/sql-554 branch 2 times, most recently from 1a21275 to 548d41a Compare July 23, 2026 21:09
@mtabebe mtabebe changed the title catalog: builtin metric sinks types, catalog item, and lowering (SQL-554( catalog: builtin metric sinks types, catalog item, and lowering (SQL-554) Jul 23, 2026
@mtabebe
mtabebe force-pushed the ma/prom-metrics/sql-554 branch from 548d41a to 68d2b95 Compare July 24, 2026 13:19
…554)

Problem:

The Prometheus cluster metrics feature needs the authoring type,
catalog representation, and lowering for builtin metric sinks.

Nothing gets installed and there's no runtime behavior change yet.

The abstraction is the generic, backend-agnostic MetricSink, not a
Prometheus-specific one.

Solution:

- Add the `BuiltinMetricSink` authoring type, along with `BuiltinMetricSinkValue`,
  `MetricSinkKind`, a `Builtin::MetricSink` variant.
- `builtin_metric_sink_view_sql` projects a sink's query into the canonical
  MetricSink row shape (`metric_name`, `metric_type`, `labels`, `value`, `help`),
  `UNION ALL`-ed across the value columns.
- Each sink materializes a companion `BuiltinView` (the canonical shape, built at
  enumeration time) plus a thin `CatalogItem::MetricSink` that points at it.
- Add `CatalogItemType::MetricSink` (rendered `metric-sink`) and the
  `CatalogItem::MetricSink`, `MetricSink`, and `MetricSinkValue` structs, then
  wire them through every exhaustive match
- Boot construction builds the item directly (`create_sql: None`)
- For discoverability, the `mz_metric_sinks_raw` backing table (populated in
  `builtin_table_updates`) feeds the `mz_internal.mz_metric_sinks` view and
  `mz_catalog.mz_objects` (as `type = 'metric-sink'`). Note: It's registered before
  `mz_objects` in the builtin list, since a builtin view can only depend on
  lower-id builtins.
- Register the first concrete sink, `mz_metric_dataflow_errors`, with companion
  view `mz_metric_dataflow_errors_shaped`. No dataflow is installed here.

Testing:

- Unit tests for the lowering
- catalog-protos snapshot consistency tests

Co-Authored-By: Moritz Hoffmann <mh@materialize.com>
@mtabebe
mtabebe force-pushed the ma/prom-metrics/sql-554 branch from 68d2b95 to 59294b3 Compare July 24, 2026 17:28
@mtabebe
mtabebe requested review from SangJunBak and antiguru July 24, 2026 18:16
@mtabebe
mtabebe marked this pull request as ready for review July 24, 2026 18:16
@mtabebe
mtabebe requested review from a team and sjwiesman as code owners July 24, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant