diff --git a/src/catalog/src/information_schema/cluster_info.rs b/src/catalog/src/information_schema/cluster_info.rs index 351b43f5ad78..0f01852bb541 100644 --- a/src/catalog/src/information_schema/cluster_info.rs +++ b/src/catalog/src/information_schema/cluster_info.rs @@ -51,6 +51,7 @@ const VERSION: &str = "version"; const GIT_COMMIT: &str = "git_commit"; const START_TIME: &str = "start_time"; const UPTIME: &str = "uptime"; +const ACTIVE_TIME: &str = "active_time"; const INIT_CAPACITY: usize = 42; @@ -63,6 +64,7 @@ const INIT_CAPACITY: usize = 42; /// - `git_commit`: the build git commit hash of the peer. /// - `start_time`: the starting time of the peer. /// - `uptime`: the uptime of the peer. +/// - `active_time`: the time since the last activity of the peer. /// pub(super) struct InformationSchemaClusterInfo { schema: SchemaRef, @@ -92,6 +94,7 @@ impl InformationSchemaClusterInfo { true, ), ColumnSchema::new(UPTIME, ConcreteDataType::string_datatype(), true), + ColumnSchema::new(ACTIVE_TIME, ConcreteDataType::string_datatype(), true), ])) } @@ -150,6 +153,7 @@ struct InformationSchemaClusterInfoBuilder { git_commits: StringVectorBuilder, start_times: TimestampMillisecondVectorBuilder, uptimes: StringVectorBuilder, + active_times: StringVectorBuilder, } impl InformationSchemaClusterInfoBuilder { @@ -168,6 +172,7 @@ impl InformationSchemaClusterInfoBuilder { git_commits: StringVectorBuilder::with_capacity(INIT_CAPACITY), start_times: TimestampMillisecondVectorBuilder::with_capacity(INIT_CAPACITY), uptimes: StringVectorBuilder::with_capacity(INIT_CAPACITY), + active_times: StringVectorBuilder::with_capacity(INIT_CAPACITY), start_time_ms, } } @@ -252,14 +257,27 @@ impl InformationSchemaClusterInfoBuilder { .push(Some(TimestampMillisecond(Timestamp::new_millisecond( node_info.start_time_ms as i64, )))); - let now = common_time::util::current_time_millis() as u64; - let duration_since_start = now - node_info.start_time_ms; - let format = humantime::format_duration(Duration::from_millis(duration_since_start)); - self.uptimes.push(Some(format.to_string().as_str())); + self.uptimes.push(Some( + Self::format_duration_since(node_info.start_time_ms).as_str(), + )); } else { self.start_times.push(None); self.uptimes.push(None); } + + if node_info.last_activity_ts > 0 { + self.active_times.push(Some( + Self::format_duration_since(node_info.last_activity_ts as u64).as_str(), + )); + } else { + self.active_times.push(None); + } + } + + fn format_duration_since(ts: u64) -> String { + let now = common_time::util::current_time_millis() as u64; + let duration_since = now - ts; + humantime::format_duration(Duration::from_millis(duration_since)).to_string() } fn finish(&mut self) -> Result { @@ -271,6 +289,7 @@ impl InformationSchemaClusterInfoBuilder { Arc::new(self.git_commits.finish()), Arc::new(self.start_times.finish()), Arc::new(self.uptimes.finish()), + Arc::new(self.active_times.finish()), ]; RecordBatch::new(self.schema.clone(), columns).context(CreateRecordBatchSnafu) } diff --git a/tests/cases/distributed/information_schema/cluster_info.result b/tests/cases/distributed/information_schema/cluster_info.result index e375a2160247..3d4158aaffef 100644 --- a/tests/cases/distributed/information_schema/cluster_info.result +++ b/tests/cases/distributed/information_schema/cluster_info.result @@ -4,72 +4,73 @@ 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 | -| version | String | | NO | | FIELD | -| git_commit | String | | NO | | FIELD | -| start_time | TimestampMillisecond | | YES | | FIELD | -| uptime | 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 | +| version | String | | NO | | FIELD | +| git_commit | String | | NO | | FIELD | +| start_time | TimestampMillisecond | | YES | | FIELD | +| uptime | String | | YES | | FIELD | +| active_time | String | | YES | | FIELD | ++-------------+----------------------+-----+------+---------+---------------+ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE unknown UNKNOWN -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO ORDER BY peer_type; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|1|DATANODE|127.0.0.1:4101|Version|Hash|Start_time|Uptime||2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Uptime||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Uptime||1|FRONTEND|127.0.0.1:4001|Version|Hash|Start_time|Uptime||0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN|||++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|1|DATANODE|127.0.0.1:4101|Version|Hash|Start_time|Duration|Duration||2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Duration|Duration||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Duration|Duration||1|FRONTEND|127.0.0.1:4001|Version|Hash|Start_time|Duration|Duration||0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN||||+++++++++ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE unknown UNKNOWN -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'METASRV' ORDER BY peer_type; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN|||++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN||||+++++++++ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE unknown UNKNOWN -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'FRONTEND' ORDER BY peer_type; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|1|FRONTEND|127.0.0.1:4001|Version|Hash|Start_time|Uptime|++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|1|FRONTEND|127.0.0.1:4001|Version|Hash|Start_time|Duration|Duration|+++++++++ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE unknown UNKNOWN -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'FRONTEND' ORDER BY peer_type; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|1|DATANODE|127.0.0.1:4101|Version|Hash|Start_time|Uptime||2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Uptime||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Uptime||0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN|||++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|1|DATANODE|127.0.0.1:4101|Version|Hash|Start_time|Duration|Duration||2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Duration|Duration||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Duration|Duration||0|METASRV|127.0.0.1:3002|UNKNOWN|UNKNOWN||||+++++++++ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE unknown UNKNOWN -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_ID > 1 ORDER BY peer_type; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Uptime||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Uptime|++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|2|DATANODE|127.0.0.1:4102|Version|Hash|Start_time|Duration|Duration||3|DATANODE|127.0.0.1:4103|Version|Hash|Start_time|Duration|Duration|+++++++++ USE PUBLIC; diff --git a/tests/cases/distributed/information_schema/cluster_info.sql b/tests/cases/distributed/information_schema/cluster_info.sql index 8fc6631ea5a2..2ac906d05dbc 100644 --- a/tests/cases/distributed/information_schema/cluster_info.sql +++ b/tests/cases/distributed/information_schema/cluster_info.sql @@ -7,7 +7,7 @@ DESC TABLE CLUSTER_INFO; -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO ORDER BY peer_type; @@ -16,7 +16,7 @@ SELECT * FROM CLUSTER_INFO ORDER BY peer_type; -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'METASRV' ORDER BY peer_type; @@ -25,7 +25,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'METASRV' ORDER BY peer_type; -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'FRONTEND' ORDER BY peer_type; @@ -34,7 +34,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'FRONTEND' ORDER BY peer_type; -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'FRONTEND' ORDER BY peer_type; @@ -43,7 +43,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'FRONTEND' ORDER BY peer_type; -- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_ID > 1 ORDER BY peer_type; diff --git a/tests/cases/standalone/common/system/information_schema.result b/tests/cases/standalone/common/system/information_schema.result index d195c617b36c..cbe6e2d39f18 100644 --- a/tests/cases/standalone/common/system/information_schema.result +++ b/tests/cases/standalone/common/system/information_schema.result @@ -62,6 +62,7 @@ select * from information_schema.columns order by table_schema, table_name, colu | greptime | information_schema | check_constraints | constraint_catalog | 1 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | | | 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 | 8 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | Yes | string | | | | greptime | information_schema | cluster_info | git_commit | 5 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | 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_id | 1 | | | 19 | 0 | | | | | | select,insert | | Int64 | bigint | FIELD | | No | bigint | | | diff --git a/tests/cases/standalone/information_schema/cluster_info.result b/tests/cases/standalone/information_schema/cluster_info.result index 06a1b4b862df..853946c7fa00 100644 --- a/tests/cases/standalone/information_schema/cluster_info.result +++ b/tests/cases/standalone/information_schema/cluster_info.result @@ -4,37 +4,38 @@ 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 | -| version | String | | NO | | FIELD | -| git_commit | String | | NO | | FIELD | -| start_time | TimestampMillisecond | | YES | | FIELD | -| uptime | 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 | +| version | String | | NO | | FIELD | +| git_commit | String | | NO | | FIELD | +| start_time | TimestampMillisecond | | YES | | FIELD | +| uptime | String | | YES | | FIELD | +| active_time | String | | YES | | FIELD | ++-------------+----------------------+-----+------+---------+---------------+ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|0|STANDALONE||Version|Hash|Start_time|Uptime|++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|0|STANDALONE||Version|Hash|Start_time|Duration||+++++++++ -- SQLNESS REPLACE version node_version -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'STANDALONE'; -++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|++++++++|0|STANDALONE||Version|Hash|Start_time|Uptime|++++++++ ++++++++++|peer_id|peer_type|peer_addr|node_version|git_commit|start_time|uptime|active_time|+++++++++|0|STANDALONE||Version|Hash|Start_time|Duration||+++++++++ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'STANDALONE'; @@ -45,7 +46,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'STANDALONE'; -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_ID = 0; diff --git a/tests/cases/standalone/information_schema/cluster_info.sql b/tests/cases/standalone/information_schema/cluster_info.sql index f9b59edc1e45..58eca548a98a 100644 --- a/tests/cases/standalone/information_schema/cluster_info.sql +++ b/tests/cases/standalone/information_schema/cluster_info.sql @@ -6,7 +6,7 @@ DESC TABLE CLUSTER_INFO; -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO; @@ -14,7 +14,7 @@ SELECT * FROM CLUSTER_INFO; -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'STANDALONE'; @@ -24,7 +24,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'STANDALONE'; -- SQLNESS REPLACE (\d\.\d\.\d) Version -- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash -- SQLNESS REPLACE (\s[\-0-9T:\.]{23}) Start_time --- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Uptime +-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration -- SQLNESS REPLACE [\s\-]+ SELECT * FROM CLUSTER_INFO WHERE PEER_ID = 0;