refactor!: unify the API of getting total cpu and memory (#7049)

* refactor: add `get_total_cpu_millicores()` / `get_total_cpu_cores()` / `get_total_memory_bytes()` / `get_total_memory_readable()` in common-stat

Signed-off-by: zyy17 <zyylsxm@gmail.com>

* tests: update sqlness test cases

Signed-off-by: zyy17 <zyylsxm@gmail.com>

---------

Signed-off-by: zyy17 <zyylsxm@gmail.com>
This commit is contained in:
zyy17
2025-10-16 20:41:34 +08:00
committed by GitHub
parent 2e6ea1167f
commit cf1b8392af
21 changed files with 192 additions and 157 deletions

View File

@@ -4,22 +4,22 @@ Affected Rows: 0
DESC TABLE CLUSTER_INFO;
+---------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------------+----------------------+-----+------+---------+---------------+
| peer_id | Int64 | | NO | | FIELD |
| peer_type | String | | NO | | FIELD |
| peer_addr | String | | YES | | FIELD |
| peer_hostname | String | | YES | | FIELD |
| cpus | UInt32 | | NO | | FIELD |
| memory_bytes | UInt64 | | NO | | FIELD |
| version | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| start_time | TimestampMillisecond | | YES | | FIELD |
| uptime | String | | YES | | FIELD |
| active_time | String | | YES | | FIELD |
| node_status | String | | YES | | FIELD |
+---------------+----------------------+-----+------+---------+---------------+
+----------------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+----------------------+----------------------+-----+------+---------+---------------+
| peer_id | Int64 | | NO | | FIELD |
| peer_type | String | | NO | | FIELD |
| peer_addr | String | | YES | | FIELD |
| peer_hostname | String | | YES | | FIELD |
| total_cpu_millicores | UInt32 | | NO | | FIELD |
| total_memory_bytes | UInt64 | | NO | | FIELD |
| version | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| start_time | TimestampMillisecond | | YES | | FIELD |
| uptime | String | | YES | | FIELD |
| active_time | String | | YES | | FIELD |
| node_status | String | | YES | | FIELD |
+----------------------+----------------------+-----+------+---------+---------------+
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d+\.\d+(?:\.\d+)+\s) Version
@@ -87,18 +87,18 @@ SELECT peer_id, node_status FROM CLUSTER_INFO WHERE PEER_TYPE = 'DATANODE' ORDER
| 2 | {"workloads"PLACEHOLDER,"leader_regions"PLACEHOLDER,"follower_regions"PLACEHOLDER} |
+---------+------------------------------------------------------------------+
SELECT peer_type, cpus!=0, memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
SELECT peer_type, total_cpu_millicores!=0, total_memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
+-----------+-------------------------------+---------------------------------------+
| peer_type | cluster_info.cpus != Int64(0) | cluster_info.memory_bytes != Int64(0) |
+-----------+-------------------------------+---------------------------------------+
| DATANODE | true | true |
| DATANODE | true | true |
| DATANODE | true | true |
| FLOWNODE | true | true |
| FRONTEND | true | true |
| METASRV | true | true |
+-----------+-------------------------------+---------------------------------------+
+-----------+-----------------------------------------------+---------------------------------------------+
| peer_type | cluster_info.total_cpu_millicores != Int64(0) | cluster_info.total_memory_bytes != Int64(0) |
+-----------+-----------------------------------------------+---------------------------------------------+
| DATANODE | true | true |
| DATANODE | true | true |
| DATANODE | true | true |
| FLOWNODE | true | true |
| FRONTEND | true | true |
| METASRV | true | true |
+-----------+-----------------------------------------------+---------------------------------------------+
USE PUBLIC;

View File

@@ -50,6 +50,6 @@ SELECT peer_id, peer_type, peer_addr, version, git_commit, start_time, uptime, a
-- SQLNESS REPLACE (:\s*(\".*?\"|\[.*?\]|\{.*?\}|[0-9]+|true|false|null)) PLACEHOLDER
SELECT peer_id, node_status FROM CLUSTER_INFO WHERE PEER_TYPE = 'DATANODE' ORDER BY peer_id;
SELECT peer_type, cpus!=0, memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
SELECT peer_type, total_cpu_millicores!=0, total_memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
USE PUBLIC;

View File

@@ -72,15 +72,15 @@ select * from information_schema.columns order by table_schema, table_name, colu
| greptime | information_schema | check_constraints | constraint_name | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | check_constraints | constraint_schema | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | cluster_info | active_time | 11 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | cluster_info | cpus | 5 | | | 10 | 0 | | | | | | select,insert | | UInt32 | int unsigned | FIELD | | No | int unsigned | | |
| greptime | information_schema | cluster_info | git_commit | 8 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | cluster_info | memory_bytes | 6 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | No | bigint unsigned | | |
| greptime | information_schema | cluster_info | node_status | 12 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | cluster_info | peer_addr | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | cluster_info | peer_hostname | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | cluster_info | peer_id | 1 | | | 19 | 0 | | | | | | select,insert | | Int64 | bigint | FIELD | | No | bigint | | |
| greptime | information_schema | cluster_info | peer_type | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | cluster_info | start_time | 9 | | | | | 3 | | | | | select,insert | | TimestampMillisecond | timestamp(3) | FIELD | | Yes | timestamp(3) | | |
| greptime | information_schema | cluster_info | total_cpu_millicores | 5 | | | 10 | 0 | | | | | | select,insert | | UInt32 | int unsigned | FIELD | | No | int unsigned | | |
| greptime | information_schema | cluster_info | total_memory_bytes | 6 | | | 20 | 0 | | | | | | select,insert | | UInt64 | bigint unsigned | FIELD | | No | bigint unsigned | | |
| greptime | information_schema | cluster_info | uptime | 10 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | |
| greptime | information_schema | cluster_info | version | 7 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | collation_character_set_applicability | character_set_name | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |

View File

@@ -4,22 +4,22 @@ Affected Rows: 0
DESC TABLE CLUSTER_INFO;
+---------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+---------------+----------------------+-----+------+---------+---------------+
| peer_id | Int64 | | NO | | FIELD |
| peer_type | String | | NO | | FIELD |
| peer_addr | String | | YES | | FIELD |
| peer_hostname | String | | YES | | FIELD |
| cpus | UInt32 | | NO | | FIELD |
| memory_bytes | UInt64 | | NO | | FIELD |
| version | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| start_time | TimestampMillisecond | | YES | | FIELD |
| uptime | String | | YES | | FIELD |
| active_time | String | | YES | | FIELD |
| node_status | String | | YES | | FIELD |
+---------------+----------------------+-----+------+---------+---------------+
+----------------------+----------------------+-----+------+---------+---------------+
| Column | Type | Key | Null | Default | Semantic Type |
+----------------------+----------------------+-----+------+---------+---------------+
| peer_id | Int64 | | NO | | FIELD |
| peer_type | String | | NO | | FIELD |
| peer_addr | String | | YES | | FIELD |
| peer_hostname | String | | YES | | FIELD |
| total_cpu_millicores | UInt32 | | NO | | FIELD |
| total_memory_bytes | UInt64 | | NO | | FIELD |
| version | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| start_time | TimestampMillisecond | | YES | | FIELD |
| uptime | String | | YES | | FIELD |
| active_time | String | | YES | | FIELD |
| node_status | String | | YES | | FIELD |
+----------------------+----------------------+-----+------+---------+---------------+
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d+\.\d+(?:\.\d+)+) Version
@@ -61,13 +61,13 @@ SELECT peer_id, peer_type, peer_addr, version, git_commit, start_time, uptime, a
++
++
SELECT peer_type, cpus!=0, memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
SELECT peer_type, total_cpu_millicores!=0, total_memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
+------------+-------------------------------+---------------------------------------+
| peer_type | cluster_info.cpus != Int64(0) | cluster_info.memory_bytes != Int64(0) |
+------------+-------------------------------+---------------------------------------+
| STANDALONE | true | true |
+------------+-------------------------------+---------------------------------------+
+------------+-----------------------------------------------+---------------------------------------------+
| peer_type | cluster_info.total_cpu_millicores != Int64(0) | cluster_info.total_memory_bytes != Int64(0) |
+------------+-----------------------------------------------+---------------------------------------------+
| STANDALONE | true | true |
+------------+-----------------------------------------------+---------------------------------------------+
USE PUBLIC;

View File

@@ -30,6 +30,6 @@ SELECT peer_id, peer_type, peer_addr, version, git_commit, start_time, uptime, a
SELECT peer_id, peer_type, peer_addr, version, git_commit, start_time, uptime, active_time FROM CLUSTER_INFO WHERE PEER_ID > 0;
SELECT peer_type, cpus!=0, memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
SELECT peer_type, total_cpu_millicores!=0, total_memory_bytes!=0 FROM CLUSTER_INFO ORDER BY peer_type;
USE PUBLIC;