metric sinks: SHOW, catalog visibility, and RBAC (SQL-572) - #38149
Draft
mtabebe wants to merge 4 commits into
Draft
metric sinks: SHOW, catalog visibility, and RBAC (SQL-572)#38149mtabebe wants to merge 4 commits into
mtabebe wants to merge 4 commits into
Conversation
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>
Make CreateMetricSinkStatement.name non-nullable, collapse the redundant item_type reject match into the relation_desc None branch, and add a TODO(SQL-572) on the platform-check survival probe. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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>
mtabebe
force-pushed
the
ma/prom-metrics/sql-572-show-rbac
branch
from
August 11, 2026 13:59
58c8c11 to
2599599
Compare
Problem: A metric sink was invisible, `mz_objects` did not carry it, and there was no way to read back the SQL that created it. Creating one required ownership of the `FROM` relation, stricter than any other sink. Solution: `SHOW METRIC SINKS [FROM <schema>] [IN CLUSTER <c>] [LIKE ...]` lists name, `from`, and cluster. `SHOW [REDACTED] CREATE METRIC SINK` replays `create_sql`. Both require `enable_metric_sink`. `mz_internal.mz_metric_sinks` exposes what the catalog knows about a sink, shaped like `mz_catalog.mz_sinks`, and joins into `mz_objects` as type `metric-sink`. It is a materialized view derived from `mz_catalog_raw`. Create now needs `CREATE` on the schema, `CREATE` on the cluster, and read on the `FROM` relation, the same shape as `CREATE SINK`. You need read on it, not ownership. The relation carries only the columns something reads. `create_sql` and `redacted_create_sql` have no reader, and `SHOW CREATE` is how you get the SQL back. Testing: - `metric_sink.slt` covers discovery and access control: the `mz_metric_sinks` row resolving to its `FROM` relation, cluster, schema, and owner, `mz_objects` and `mz_show_all_objects` membership, the three `SHOW METRIC SINKS` filters, the `SHOW CREATE` round-trip, the audit rows, and privileges. - The restart platform check reads `SHOW METRIC SINKS` instead of probing with a `CREATE` expected to fail.
mtabebe
force-pushed
the
ma/prom-metrics/sql-572-show-rbac
branch
from
August 11, 2026 14:35
2599599 to
5eeeece
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
A metric sink was invisible,
mz_objectsdid not carry it, and therewas no way to read back the SQL that created it. Creating one required
ownership of the
FROMrelation, stricter than any other sink.Solution:
SHOW METRIC SINKS [FROM <schema>] [IN CLUSTER <c>] [LIKE ...]listsname,
from, and cluster.SHOW [REDACTED] CREATE METRIC SINKreplayscreate_sql. Both requireenable_metric_sink.mz_internal.mz_metric_sinksexposes what the catalog knows about asink, shaped like
mz_catalog.mz_sinks, and joins intomz_objectsastype
metric-sink. It is a materialized view derived frommz_catalog_raw.Create now needs
CREATEon the schema,CREATEon the cluster, andread on the
FROMrelation, the same shape asCREATE SINK. You needread on it, not ownership.
The relation carries only the columns something reads.
create_sqlandredacted_create_sqlhave no reader, andSHOW CREATEis how you getthe SQL back.
Testing:
metric_sink.sltcovers discovery and access control: themz_metric_sinksrow resolving to itsFROMrelation, cluster, schema,and owner,
mz_objectsandmz_show_all_objectsmembership, the threeSHOW METRIC SINKSfilters, theSHOW CREATEround-trip, the auditrows, and privileges.
The restart platform check reads
SHOW METRIC SINKSinstead ofprobing with a
CREATEexpected to fail.