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

Code before:
                        f"{metric('state_store_meta_cache_usage_ratio')} >= bool 1.1",
                        "Abnormal Meta Cache Memory",
                    ),
                    panels.target(
                        f"{metric('state_store_block_cache_usage_ratio')} >= bool 1.1",
                        "Abnormal Block Cache Memory",
                    ),
                    panels.target(
                        f"{metric('state_store_uploading_memory_usage_ratio')} >= bool 0.7",
                        "Abnormal Uploading Memory Usage",
                    ),
                    panels.target(
                        f"{metric('storage_write_stop_compaction_groups')} > bool 0",
                        "Write Stall",
                    ),
                    panels.target(
                        f"{metric('storage_version_size')} >= bool 314572800",
                        "Abnormal Version Size",
                    ),
                    panels.target(
                        f"{metric('storage_delta_log_count')} >= bool 5000",
                        "Abnormal Delta Log Number",
                    ),
                    panels.target(
                        f"{metric('state_store_event_handler_pending_event')} >= bool 10000000",
                        "Abnormal Pending Event Number",
                    ),
                    panels.target(
                        f"{metric('object_store_failure_count')} >= bool 50",
                        "Abnormal Object Storage Failure",
                    ),
                ],
                ["last"],
            ),
            panels.timeseries_count(
                "Errors",
                "Errors in the system group by type",
                [
                    panels.target(
                        f"sum({metric('user_compute_error')}) by (error_type, executor_name, fragment_id)",
                        "{{error_type}} @ {{executor_name}} (fragment_id={{fragment_id}})",
                    ),
                    panels.target(
                        f"sum({metric('user_source_error')}) by (error_type, source_id, source_name, fragment_id)",
                        "{{error_type}} @ {{source_name}} (source_id={{source_id}} fragment_id={{fragment_id}})",
                    ),
                    panels.target(
                        f"sum({metric('user_sink_error')}) by (error_type, sink_id, sink_name, fragment_id)",
                        "{{error_type}} @ {{sink_name}} (sink_id={{sink_id}} fragment_id={{fragment_id}})",
                    ),
                    panels.target(

Review comment (suggestion):
The query string is split across multiple lines using backslash continuation, but the whitespace handling is inconsistent and may lead to unexpected spacing in the final query. Consider using parentheses for multi-line strings or f-string implicit concatenation to avoid potential whitespace issues. For example: `f\"(sum(rate(...)) / ignoring(...) / 1000000000)\"`
```suggestion
                        (
                            f"sum(rate({metric('stream_actor_input_buffer_blocking_duration_ns')}[$__rate_interval])) by (fragment_id, upstream_fragment_id)"
                            f" / ignoring (upstream_fragment_id) group_left sum({metric('stream_actor_count')}) by (fragment_id)"
                            f" / 1000000000"
                        ),
```

Code after:
                "Actor Output Blocking Rate (Downstream Backpressure)",
                "The rate that an actor is blocked by its downstream.",
                [
                    # The metrics might be pre-aggregated locally on each compute node when `actor_id` is masked due to metrics level settings.
                    # Thus to calculate the average, we need to manually divide the actor count.
                    #
                    # Note: actor_count is equal to the number of dispatchers for a given downstream fragment,
                    # this holds true as long as we don't support multiple edges between two fragments.
                    panels.target(
                        f"sum(rate({metric('stream_actor_output_buffer_blocking_duration_ns')}[$__rate_interval])) by (fragment_id, downstream_fragment_id) \
                            / ignoring (downstream_fragment_id) group_left sum({metric('stream_actor_count')}) by (fragment_id) \
                            / 1000000000",
                        "fragment {{fragment_id}}->{{downstream_fragment_id}}",
                    ),
                ],
            ),
            panels.timeseries_percentage(
                "Actor Input Blocking Rate (Upstream Backpressure)",
                "The rate that an actor is blocked by its upstream.",
                [
                    # The metrics might be pre-aggregated locally on each compute node when `actor_id` is masked due to metrics level settings.
                    # Thus to calculate the average, we need to manually divide the actor count.
                    panels.target(
                        f"sum(rate({metric('stream_actor_input_buffer_blocking_duration_ns')}[$__rate_interval])) by (fragment_id, upstream_fragment_id) \
                            / ignoring (upstream_fragment_id) group_left sum({metric('stream_actor_count')}) by (fragment_id) \
                            / 1000000000",
                        "fragment {{fragment_id}}<-{{upstream_fragment_id}}",
                    ),
                ],
            ),
            panels.subheader("Busy Rate"),
            panels.timeseries_percentage(
                "Actor Busy Rate",
                "The rate that an actor is busy, i.e. the rate that an actor is not blocked by its downstream or upstream.",
                [
                    _actor_busy_rate_alt_target(panels, "$__rate_interval"),
                ],
            ),
            panels.timeseries_percentage(
                "Actor Busy Rate (10m)",
                "The rate that an actor is busy, i.e. the rate that an actor is not blocked by its downstream or upstream, over the last 10 minutes.",
                [
                    _actor_busy_rate_alt_target(panels, "10m"),
                ],
            ),
            panels.timeseries_percentage(
                "Actor Busy Rate (5m)",
                "The rate that an actor is busy, i.e. the rate that an actor is not blocked by its downstream or upstream, over the last 5 minutes.",
                [
                    _actor_busy_rate_alt_target(panels, "5m"),
                ],