From 05a235455a055ffc3089604ecbeb4818c2219128 Mon Sep 17 00:00:00 2001 From: gengjun-git Date: Fri, 25 Aug 2023 10:21:01 +0800 Subject: [PATCH] [Enhancement] Add agent task metrics (#29707) Signed-off-by: gengjun-git --- .../java/com/starrocks/metric/MetricRepo.java | 11 ++ test/sql/test_metrics/R/test_memory_metrics | 130 +++++++++--------- test/sql/test_metrics/T/test_memory_metrics | 3 + 3 files changed, 82 insertions(+), 62 deletions(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/metric/MetricRepo.java b/fe/fe-core/src/main/java/com/starrocks/metric/MetricRepo.java index 3c7ef1b27f4a54..246493d2c9b34e 100644 --- a/fe/fe-core/src/main/java/com/starrocks/metric/MetricRepo.java +++ b/fe/fe-core/src/main/java/com/starrocks/metric/MetricRepo.java @@ -74,6 +74,7 @@ import com.starrocks.service.ExecuteEnv; import com.starrocks.system.Backend; import com.starrocks.system.SystemInfoService; +import com.starrocks.task.AgentTaskQueue; import com.starrocks.transaction.TransactionState; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -727,6 +728,16 @@ public Long getValue() { }; queryCoordinatorCount.addLabel(new MetricLabel("type", "query_coordinator_count")); STARROCKS_METRIC_REGISTER.addMetric(queryCoordinatorCount); + + GaugeMetric agentTaskCount = new GaugeMetric("memory", MetricUnit.NOUNIT, + "The count of agent task") { + @Override + public Long getValue() { + return (long) AgentTaskQueue.getTaskNum(); + } + }; + agentTaskCount.addLabel(new MetricLabel("type", "agent_task_count")); + STARROCKS_METRIC_REGISTER.addMetric(agentTaskCount); } // to generate the metrics related to tablets of each backends diff --git a/test/sql/test_metrics/R/test_memory_metrics b/test/sql/test_metrics/R/test_memory_metrics index 0f27837de0baea..fbcecbf0bf7ca2 100644 --- a/test/sql/test_metrics/R/test_memory_metrics +++ b/test/sql/test_metrics/R/test_memory_metrics @@ -1,10 +1,10 @@ --- name: test_memory_metrics_txn_callback_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_callback_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_load_profile_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"load_profile_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_delete_job_info_count +-- name: test_memory_metrics_txn_bytes CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -18,23 +18,20 @@ PROPERTIES ( insert into t1 values (1); -- result: -- !result -delete from t1 where a = 1; --- result: --- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"delete_job_info_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_bytes\" | awk '{if ($NF >= 832) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_compaction_stats_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"compaction_stats_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_agent_task_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"agent_task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_tablet_count +-- name: test_memory_metrics_tablet_bytes CREATE TABLE `t1` ( - a int + a int ) ENGINE=OLAP DUPLICATE KEY(`a`) DISTRIBUTED BY HASH(`a`) BUCKETS 10 @@ -43,12 +40,12 @@ PROPERTIES ( ); -- result: -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"tablet_count\" | awk '{if ($NF >= 10) print "true"; else print "false";}' +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"tablet_bytes\" | awk '{if ($NF >= 1360) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_query_profile_count +-- name: test_memory_metrics_tablet_count CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -59,27 +56,26 @@ PROPERTIES ( ); -- result: -- !result -set enable_profile=true; --- result: --- !result -select count(*) from t1; +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"tablet_count\" | awk '{if ($NF >= 10) print "true"; else print "false";}' -- result: 0 +true -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_profile_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' +-- name: test_memory_metrics_running_task_run_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"running_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_pending_task_run_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"pending_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_delete_job_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"delete_job_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_replica_bytes +-- name: test_memory_metrics_query_profile_count CREATE TABLE `t1` ( - a int + a int ) ENGINE=OLAP DUPLICATE KEY(`a`) DISTRIBUTED BY HASH(`a`) BUCKETS 10 @@ -88,24 +84,19 @@ PROPERTIES ( ); -- result: -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"replica_bytes\" | awk '{if ($NF >= 1440) print "true"; else print "false";}' +set enable_profile=true; -- result: -0 -true -- !result --- name: test_memory_metrics_delete_job_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"delete_job_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +select count(*) from t1; -- result: 0 -true -- !result --- name: test_memory_metrics_task_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_profile_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_txn_count +-- name: test_memory_metrics_replica_count CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -116,27 +107,40 @@ PROPERTIES ( ); -- result: -- !result -insert into t1 values (1); +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"replica_count\" | awk '{if ($NF >= 10) print "true"; else print "false";}' -- result: +0 +true -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' +-- name: test_memory_metrics_query_detail_count +admin set frontend config ("enable_collect_query_detail_info" = "true"); +-- result: +-- !result +[UC]show frontends; +-- result: +172.26.92.139_9312_1692690164465 172.26.92.139 9312 8332 9332 9322 LEADER 1640562713 true true 2292 2023-08-22 17:44:15 true 2023-08-22 17:42:09 add_agent_task_metrics-ba5647e +-- !result +admin set frontend config ("enable_collect_query_detail_info" = "false"); +-- result: +-- !result +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_detail_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_catalogs_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"catalogs_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_history_task_run_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"history_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_stream_load_task_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"stream_load_task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_compaction_stats_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"compaction_stats_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_txn_bytes +-- name: test_memory_metrics_delete_job_info_count CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -150,12 +154,21 @@ PROPERTIES ( insert into t1 values (1); -- result: -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_bytes\" | awk '{if ($NF >= 832) print "true"; else print "false";}' +delete from t1 where a = 1; +-- result: +-- !result +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"delete_job_info_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_tablet_bytes +-- name: test_memory_metrics_pending_task_run_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"pending_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- result: +0 +true +-- !result +-- name: test_memory_metrics_replica_bytes CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -166,40 +179,36 @@ PROPERTIES ( ); -- result: -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"tablet_bytes\" | awk '{if ($NF >= 1360) print "true"; else print "false";}' +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"replica_bytes\" | awk '{if ($NF >= 1440) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_running_task_run_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"running_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_catalogs_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"catalogs_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_load_profile_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"load_profile_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_stream_load_task_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"stream_load_task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_query_detail_count -admin set frontend config ("enable_collect_query_detail_info" = "true"); --- result: --- !result -[UC]show frontends; --- result: -172.26.92.139_9312_1690292126093 172.26.92.139 9312 8332 9332 9322 LEADER 2056272365 true true 232533 2023-08-03 19:36:20 true 2023-08-03 16:04:39 add_memory_metrics-40b18af --- !result -admin set frontend config ("enable_collect_query_detail_info" = "false"); +-- name: test_memory_metrics_txn_callback_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_callback_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: +0 +true -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_detail_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' +-- name: test_memory_metrics_task_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' -- result: 0 true -- !result --- name: test_memory_metrics_replica_count +-- name: test_memory_metrics_txn_count CREATE TABLE `t1` ( a int ) ENGINE=OLAP @@ -210,13 +219,10 @@ PROPERTIES ( ); -- result: -- !result -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"replica_count\" | awk '{if ($NF >= 10) print "true"; else print "false";}' +insert into t1 values (1); -- result: -0 -true -- !result --- name: test_memory_metrics_history_task_run_count -shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"history_task_run_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"txn_count\" | awk '{if ($NF >= 1) print "true"; else print "false";}' -- result: 0 true @@ -232,4 +238,4 @@ shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_coordinat -- result: 0 true --- !result \ No newline at end of file +-- !result diff --git a/test/sql/test_metrics/T/test_memory_metrics b/test/sql/test_metrics/T/test_memory_metrics index de7ab344ace736..f8a72e3c6d8692 100644 --- a/test/sql/test_metrics/T/test_memory_metrics +++ b/test/sql/test_metrics/T/test_memory_metrics @@ -134,3 +134,6 @@ shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"load_profile_co -- name: test_memory_metrics_query_coordinator_count shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"query_coordinator_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +-- name: test_memory_metrics_agent_task_count +shell: curl '${url}/metrics' | grep starrocks_fe_memory | grep \"agent_task_count\" | awk '{if ($NF >= 0) print "true"; else print "false";}' +