Repository: risingwavelabs/risingwave
File: grafana/dashboard/dev/streaming_relations.py (Python)

Code before:
                    "Top Relations by CPU Rate",
                    "Top 10 relations with the highest peak CPU rate (%).",
                    [
                        panels.table_target(
                            _relation_cpu_peak_topk_expr(
                                poll_duration_rate_expr, actor_count_expr
                            )
                        )
                    ],
                    ["id", "name", "Value", "type"],
                    dict.fromkeys(["Time"], True),
                    {"Value": "rate"},
                    {"rate": "percent"},
                ),
                panels.subheader("CPU Usage By Relation"),
                panels.timeseries_percentage(
                    "CPU Usage Per Streaming Job",
                    "The figure shows the CPU usage of each streaming job",
                    [
                        panels.target(
                            f"label_replace("
                            f"({_sum_fragment_metric_by_mv(poll_duration_expr)}"
                            f"/ 1000000000), "
                            f"'id', '$1', 'materialized_view_id', '(.*)'"
                            f") * on(id) group_left(name, type) {metric('relation_info')}",
                            "relation {{name}} (id={{id}} type={{type}})",
                        )
                    ],
                ),
                panels.subheader("Busy Rate By Relation"),
                panels.timeseries_percentage(
                    "Relation Busy Rate",
                    "The rate that a relation is busy, i.e. the busy rate of its busiest actor.",
                    [
                        _relation_busy_rate_target(panels, "$__rate_interval"),
                    ],
                ),
                panels.timeseries_percentage(
                    "Relation Busy Rate (10m)",
                    "The rate that a relation is busy, i.e. the busy rate of its busiest actor, over the last 10 minutes.",
                    [
                        _relation_busy_rate_target(panels, "10m"),
                    ],
                ),
                panels.timeseries_percentage(
                    "Relation Busy Rate (5m)",
                    "The rate that a relation is busy, i.e. the busy rate of its busiest actor, over the last 5 minutes.",
                    [
                        _relation_busy_rate_target(panels, "5m"),
                    ],
                ),

Review comment (suggestion):
The legend format has been changed from the original `{{type}} {{name}} id {{id}}` to `relation {{name}} (id={{id}} type={{type}})`. This appears to be an unrelated formatting change that should not be included in this PR focused on adding fragment-level metrics.
```suggestion
                            "{{type}} {{name}} id {{id}}",
```

Code after:
                panels.subheader("Overview"),
                panels.table_info(
                    "Top Relations by Busy Rate",
                    "Top 10 relations with the highest peak busy rate (%).",
                    [
                        panels.table_target(
                            _relation_busy_peak_topk_expr("$__rate_interval")
                        )
                    ],
                    ["id", "name", "Value", "type"],
                    dict.fromkeys(["Time"], True),
                    {"Value": "rate"},
                    {"rate": "percent"},
                ),
                panels.table_info(
                    "Top Relations by CPU Rate",
                    "Top 10 relations with the highest peak CPU rate (%).",
                    [
                        panels.table_target(
                            _relation_cpu_peak_topk_expr(
                                poll_duration_rate_expr, actor_count_expr
                            )
                        )
                    ],
                    ["id", "name", "Value", "type"],
                    dict.fromkeys(["Time"], True),
                    {"Value": "rate"},
                    {"rate": "percent"},
                ),
                panels.subheader("CPU Usage By Relation"),
                panels.timeseries_percentage(
                    "CPU Usage Per Streaming Job",
                    "The figure shows the CPU usage of each streaming job",
                    [
                        panels.target(
                            f"label_replace("
                            f"({_sum_fragment_metric_by_mv(poll_duration_expr)}"
                            f"/ 1000000000), "
                            f"'id', '$1', 'materialized_view_id', '(.*)'"
                            f") * on(id) group_left(name, type) {metric('relation_info')}",
                            "{{type}} {{name}} id {{id}}",
                        )
                    ],
                ),
                panels.subheader("Busy Rate By Relation"),
                panels.timeseries_percentage(
                    "Relation Busy Rate",
                    "The rate that a relation is busy, i.e. the busy rate of its busiest actor.",
                    [
                        _relation_busy_rate_target(panels, "$__rate_interval"),
                    ],