import os import runpy import sys import attr sys.path.append(os.path.dirname(__file__)) from common import ( DATASOURCE, DATASOURCE_INPUT, OPTIONAL_QUANTILE, SERVERLESS_PROMQL_POLICY, PromQLPolicy, template, use_promql_policy, ) from grafanalib.core import HIDE_VARIABLE, SHOW, DataSourceInput, Templating VARIABLES_DATASOURCE_INPUT = DataSourceInput( name="DS_TEST-CLUSTER-VARIABLES", label="o11y-global-variables", pluginId="prometheus", pluginName="Prometheus", ) VARIABLES_DATASOURCE = f"${{{VARIABLES_DATASOURCE_INPUT.name}}}" def ServerlessTemplates() -> Templating: return Templating( list=[ template( name="control_plane_info", label="Region", type="query", query='label_values({application_id="devtier-infra"}, control_plane_info)', refresh=1, data_source=VARIABLES_DATASOURCE, hide=SHOW, ), template( name="db", type="query", query="label_values(tikv_engine_size_bytes, db)", data_source=DATASOURCE, hide=SHOW, multi=True, include_all=True, ), template( name="command", type="query", query="query_result(tikv_storage_command_total!=0)", data_source=DATASOURCE, hide=SHOW, regex='/\\btype="([^"]+)"/', multi=True, include_all=True, ), template( name="instance", type="query", query="label_values(tikv_engine_size_bytes, instance)", data_source=DATASOURCE, hide=SHOW, multi=True, include_all=True, all_value=".*", ), template( name="worker_instance", type="query", query="label_values(tikv_worker_cpu_cores_quota, instance)", data_source=DATASOURCE, hide=SHOW, multi=True, include_all=True, all_value=".*", ), template( name="titan_db", type="query", query="label_values(tikv_engine_titandb_num_live_blob_file, db)", data_source=DATASOURCE, hide=HIDE_VARIABLE, multi=True, include_all=True, ), template( name="additional_groupby", type="custom", query="none,instance", data_source=DATASOURCE, hide=SHOW, ), template( name=OPTIONAL_QUANTILE, type="custom", query="0.99,0.999,0.9999,0.99999,1", data_source=DATASOURCE, hide=SHOW, ), template( name="keyspace_id", type="query", query='label_values({__name__=~"tikv_cpu_token_wait_duration_seconds_count|tikv_yatp_pool_keyspace_task_slice_cpu_duration_seconds_count"}, keyspace_id)', data_source=DATASOURCE, hide=SHOW, multi=True, include_all=True, ), ] ) dashboard_path = os.path.join(os.path.dirname(__file__), "tikv_details.dashboard.py") with use_promql_policy(SERVERLESS_PROMQL_POLICY): details = runpy.run_path(dashboard_path) base_dashboard = details["dashboard"] cluster = details["Cluster"](resource_label_selector='container="tikv"') serverless_tikv_policy = attr.evolve( SERVERLESS_PROMQL_POLICY, default_label_selectors=( *SERVERLESS_PROMQL_POLICY.default_label_selectors, 'container="tikv"', ), ) with use_promql_policy(serverless_tikv_policy): ia = details["IA"]() cold_region = details["ColdRegion"]() worker_rows = { "Cloud Worker Service", "Cloud Worker - Native BR", "Cloud Worker - Schema Manager", } panels = [ cluster if panel.title == "Cluster" else ia if panel.title == "IA" else panel for panel in base_dashboard.panels if panel.title not in worker_rows ] resource_control_index = next( index for index, panel in enumerate(panels) if panel.title == "Resource Control (Serverless)" ) panels.insert(resource_control_index + 1, cold_region) dashboard = attr.evolve( base_dashboard, title="Starter-Essential-TiKV-Details-for-Clinic", uid="_eCx0ZDvz", inputs=[ attr.evolve(DATASOURCE_INPUT, label="o11y-global-data"), VARIABLES_DATASOURCE_INPUT, ], templating=ServerlessTemplates(), panels=panels, ).auto_panel_ids()