Skip to content

metric sinks: run, rehydrate, and track dataflow progress (SQL-571) - #38018

Draft
mtabebe wants to merge 2 commits into
MaterializeInc:mainfrom
mtabebe:ma/prom-metrics/sql-571-runtime
Draft

metric sinks: run, rehydrate, and track dataflow progress (SQL-571)#38018
mtabebe wants to merge 2 commits into
MaterializeInc:mainfrom
mtabebe:ma/prom-metrics/sql-571-runtime

Conversation

@mtabebe

@mtabebe mtabebe commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Problem:

CREATE METRIC SINK only wrote a catalog item. It never
optimized or shipped a dataflow, so nothing actually ran. On top of that
a metric sink export had neither a trace nor a sink_write_frontier, so
every frontier report logged collection without write frontier, the
controller never saw progress, and the since of the sink's input stayed
pinned.

Solution:

CREATE METRIC SINK now optimizes and ships a dataflow, DROP
tears it down, and bootstrap re-renders every metric sink so one survives
a restart. The assembly optimizer starts from the GlobalId of the
collection to export, like CREATE INDEX, pushes the row-wise shaping
into MIR, and exports a single MetricSink sink. Sequencing is staged so
optimization runs off the coordinator thread. Bootstrap reuses the global
expression cache, like materialized views do. A cached plan embeds a
transient id for the shaped view, and reusing that id across a boot is
safe because build ids are dataflow-local on the worker and never
registered in the controller's instance-global collections.

For progress, the operator already folds the combined ok+err input
frontier, so we hand that to the ComputeState. Every worker reports it,
not just the one that owns the registry collector. The controller meets
the per-worker frontiers, so a worker stuck at the minimum would
otherwise hold the input back.

Rendering create-item notices and shipping a dataflow under a read hold
move into the shared render_create_item_notices and ship_new_dataflow
helpers, with CREATE INDEX moved onto both.

Testing:

testdrive drives a sink's series into the replica's Prometheus
registry and back out through mz_cluster_prometheus_metrics, then
checks that DROP METRIC SINK and DROP VIEW ... CASCADE retract them.

The restart platform check now probes for the re-rendered dataflow, not
just the re-parsed catalog item. Introspection is per-replica and the
checks default to two replicas, so it targets one.

An optimizer unit test pins the assembled dataflow to exactly one
MetricSink export over the shaped view.

Co-Authored-By: Moritz Hoffmann antiguru@gmail.com

mtabebe and others added 2 commits July 29, 2026 20:10
Problem:

To maintain cluster metrics we defined the MetricSink compute operator.
However, there is no way to ask for one. We need a SQL surface that
names a metric sink and a durable catalog representation that survives
a restart.

Solution:

Add `CREATE METRIC SINK <name> IN CLUSTER <c> FROM <rel>` and `DROP
METRIC SINK`, gated behind `enable_metric_sink`. Creating a sink writes a
catalog item and nothing else: no dataflow is optimized or shipped, so a
sink created today publishes no metrics.

Planning checks that the `FROM` relation exposes the five columns the
operator reads (`metric_name`, `metric_type`, `labels`, `value`, `help`).
Note: order is not enforced and extra columns are fine. Nullability is not
checked.

Metric sinks need no new durable record. They persist as ordinary `Item`s
and `item_type` works the type out from `create_sql`.

However, the changes to audit and serialization does bump the catalog
version.

There are some gaps in:
- `mz_comments` has no `MetricSink` branch, but `CommentObjectType`
has no variant either, so `COMMENT ON METRIC SINK` does not parse
and no such record can exist
- `MZ_DEFAULT_PRIVILEGES` has no CASE arm, but `ON METRIC SINKS`
is rejected during planning

Note: `enable_metric_sink` is off by default

Testing:

- New `test/sqllogictest/metric_sink.slt`: the column contract and each
 way of violating it, `FROM` targets with no rows to read, `IF NOT
EXISTS`, the flag-off refusal, and the seven views above answering with
 a metric sink present.

Co-Authored-By: Moritz Hoffmann <mh@materialize.com>
Problem:

`CREATE METRIC SINK` only wrote a catalog item. It never
optimized or shipped a dataflow, so nothing actually ran. On top of that
a metric sink export had neither a trace nor a `sink_write_frontier`, so
every frontier report logged `collection without write frontier`, the
controller never saw progress, and the since of the sink's input stayed
pinned.

Solution:

`CREATE METRIC SINK` now optimizes and ships a dataflow, `DROP`
tears it down, and bootstrap re-renders every metric sink so one survives
a restart. The assembly optimizer starts from the `GlobalId` of the
collection to export, like `CREATE INDEX`, pushes the row-wise shaping
into MIR, and exports a single `MetricSink` sink. Sequencing is staged so
optimization runs off the coordinator thread. Bootstrap reuses the global
expression cache, like materialized views do. A cached plan embeds a
transient id for the shaped view, and reusing that id across a boot is
safe because build ids are dataflow-local on the worker and never
registered in the controller's instance-global collections.

For progress, the operator already folds the combined ok+err input
frontier, so we hand that to the `ComputeState`. Every worker reports it,
not just the one that owns the registry collector. The controller meets
the per-worker frontiers, so a worker stuck at the minimum would
otherwise hold the input back.

Rendering create-item notices and shipping a dataflow under a read hold
move into the shared `render_create_item_notices` and `ship_new_dataflow`
helpers, with `CREATE INDEX` moved onto both.

Testing:

testdrive drives a sink's series into the replica's Prometheus
registry and back out through `mz_cluster_prometheus_metrics`, then
checks that `DROP METRIC SINK` and `DROP VIEW ... CASCADE` retract them.

The restart platform check now probes for the re-rendered dataflow, not
just the re-parsed catalog item. Introspection is per-replica and the
checks default to two replicas, so it targets one.

An optimizer unit test pins the assembled dataflow to exactly one
`MetricSink` export over the shaped view.

Co-Authored-By: Moritz Hoffmann <antiguru@gmail.com>
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