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

Code before:
    actor_busy_rate_expr = _actor_busy_rate_expr(rate_interval)
    return panels.target(
        f"({actor_busy_rate_expr})",
        "fragment {{fragment_id}}",
    )

def _relation_busy_rate_expr(rate_interval: str):
    actor_busy_rate_expr = _actor_busy_rate_expr(rate_interval)
    relation_busy_rate_expr = (
        f"topk (1,"
        f"  ({actor_busy_rate_expr}) * on (fragment_id) group_right {metric('table_info')}"
        f") by (materialized_view_id)"
    )
    relation_busy_rate_with_metadata_expr = (
        f"label_replace(({relation_busy_rate_expr}), 'id', '$1', 'materialized_view_id', '(.*)')"
        f"* on (id) group_left (name, type) {metric('relation_info')}"
    )
    return relation_busy_rate_with_metadata_expr

def _relation_busy_rate_target(panels: Panels, rate_interval: str):
    return panels.target(
        _relation_busy_rate_expr(rate_interval),
        "name {{name}} id {{id}} type {{type}} fragment {{fragment_id}}",
    )

@section
def _(outer_panels: Panels):
    panels = outer_panels
    return [
        outer_panels.row("Cluster Essential Information"),
        *[
            panels.subheader("Node Status"),
            panels.timeseries_count(
                "Node Count",
                "The number of each type of RisingWave components alive.",
                [
                    panels.target(
                        f"sum({metric('worker_num')}) by (worker_type)",
                        "{{worker_type}}",
                    )
                ],
                ["last"],
            ),
            panels.timeseries_memory(
                "Node Memory",
                "The memory usage of each RisingWave component.",
                [
                    panels.target(
                        f"avg({metric('process_resident_memory_bytes')}) by ({COMPONENT_LABEL}, {NODE_LABEL})",
                        "{{%s}} @ {{%s}}" % (COMPONENT_LABEL, NODE_LABEL),
                    )

Review comment (suggestion):
The functions `_relation_busy_rate_expr` and `_relation_busy_rate_target` lack documentation comments explaining their purpose and logic. Consider adding comments similar to those for `_actor_busy_rate_expr` (lines 77-82) to explain:
- What relation busy rate represents
- How it aggregates actor busy rates by materialized view
- Why `topk(1, ...)` is used to select the busiest fragment per relation
- How the metric joins work to enrich with relation metadata

Code after:

def _actor_busy_rate_target(panels: Panels, rate_interval: str):
    actor_busy_rate_expr = _actor_busy_rate_expr(rate_interval)
    return panels.target(
        f"({actor_busy_rate_expr})",
        "fragment {{fragment_id}}",
    )

def _relation_busy_rate_expr(rate_interval: str):
    actor_busy_rate_expr = _actor_busy_rate_expr(rate_interval)
    relation_busy_rate_expr = (
        f"topk(1,"
        f"  ({actor_busy_rate_expr}) * on (fragment_id) group_right {metric('table_info')}"
        f") by (materialized_view_id)"
    )
    relation_busy_rate_with_metadata_expr = (
        f"label_replace(({relation_busy_rate_expr}), 'id', '$1', 'materialized_view_id', '(.*)')"
        f"* on (id) group_left (name, type) {metric('relation_info')}"
    )
    return relation_busy_rate_with_metadata_expr

def _relation_busy_rate_target(panels: Panels, rate_interval: str):
    return panels.target(
        _relation_busy_rate_expr(rate_interval),
        "name {{name}} id {{id}} type {{type}} fragment {{fragment_id}}",
    )

@section
def _(outer_panels: Panels):
    panels = outer_panels
    return [
        outer_panels.row("Cluster Essential Information"),
        *[
            panels.subheader("Node Status"),
            panels.timeseries_count(
                "Node Count",
                "The number of each type of RisingWave components alive.",
                [
                    panels.target(
                        f"sum({metric('worker_num')}) by (worker_type)",
                        "{{worker_type}}",
                    )
                ],
                ["last"],
            ),
            panels.timeseries_memory(
                "Node Memory",
                "The memory usage of each RisingWave component.",
                [
                    panels.target(
                        f"avg({metric('process_resident_memory_bytes')}) by ({COMPONENT_LABEL}, {NODE_LABEL})",