@@ -31,6 +31,7 @@ use tower_http::add_extension::AddExtensionLayer;
31
31
use tower_http:: compression:: CompressionLayer ;
32
32
use tower_http:: cors:: { self , CorsLayer } ;
33
33
34
+ use crate :: hummock:: HummockManagerRef ;
34
35
use crate :: manager:: MetadataManager ;
35
36
use crate :: manager:: diagnose:: DiagnoseCommandRef ;
36
37
@@ -41,6 +42,7 @@ pub struct DashboardService {
41
42
pub prometheus_client : Option < prometheus_http_query:: Client > ,
42
43
pub prometheus_selector : String ,
43
44
pub metadata_manager : MetadataManager ,
45
+ pub hummock_manager : HummockManagerRef ,
44
46
pub compute_clients : ComputeClientPool ,
45
47
pub diagnose_command : DiagnoseCommandRef ,
46
48
pub trace_state : otlp_embedded:: StateRef ,
@@ -65,6 +67,7 @@ pub(super) mod handlers {
65
67
Index , PbDatabase , PbSchema , Sink , Source , Subscription , Table , View ,
66
68
} ;
67
69
use risingwave_pb:: common:: { WorkerNode , WorkerType } ;
70
+ use risingwave_pb:: hummock:: TableStats ;
68
71
use risingwave_pb:: meta:: list_object_dependencies_response:: PbObjectDependencies ;
69
72
use risingwave_pb:: meta:: {
70
73
ActorIds , FragmentIdToActorIdMap , FragmentToRelationMap , PbTableFragments , RelationIdInfos ,
@@ -76,14 +79,48 @@ pub(super) mod handlers {
76
79
} ;
77
80
use risingwave_pb:: stream_plan:: FragmentTypeFlag ;
78
81
use risingwave_pb:: user:: PbUserInfo ;
79
- use serde:: Deserialize ;
82
+ use serde:: { Deserialize , Serialize } ;
80
83
use serde_json:: json;
81
84
use thiserror_ext:: AsReport ;
82
85
83
86
use super :: * ;
84
87
use crate :: controller:: fragment:: StreamingJobInfo ;
85
88
use crate :: rpc:: await_tree:: { dump_cluster_await_tree, dump_worker_node_await_tree} ;
86
89
90
+ #[ derive( Serialize ) ]
91
+ pub struct TableWithStats {
92
+ #[ serde( flatten) ]
93
+ pub table : Table ,
94
+ pub total_size_bytes : i64 ,
95
+ pub total_key_count : i64 ,
96
+ pub total_key_size : i64 ,
97
+ pub total_value_size : i64 ,
98
+ pub compressed_size : u64 ,
99
+ }
100
+
101
+ impl TableWithStats {
102
+ pub fn from_table_and_stats ( table : Table , stats : Option < & TableStats > ) -> Self {
103
+ match stats {
104
+ Some ( stats) => Self {
105
+ total_size_bytes : stats. total_key_size + stats. total_value_size ,
106
+ total_key_count : stats. total_key_count ,
107
+ total_key_size : stats. total_key_size ,
108
+ total_value_size : stats. total_value_size ,
109
+ compressed_size : stats. total_compressed_size ,
110
+ table,
111
+ } ,
112
+ None => Self {
113
+ total_size_bytes : 0 ,
114
+ total_key_count : 0 ,
115
+ total_key_size : 0 ,
116
+ total_value_size : 0 ,
117
+ compressed_size : 0 ,
118
+ table,
119
+ } ,
120
+ }
121
+ }
122
+ }
123
+
87
124
pub struct DashboardError ( anyhow:: Error ) ;
88
125
pub type Result < T > = std:: result:: Result < T , DashboardError > ;
89
126
@@ -126,29 +163,60 @@ pub(super) mod handlers {
126
163
127
164
async fn list_table_catalogs_inner (
128
165
metadata_manager : & MetadataManager ,
166
+ hummock_manager : & HummockManagerRef ,
129
167
table_type : TableType ,
130
- ) -> Result < Json < Vec < Table > > > {
168
+ ) -> Result < Json < Vec < TableWithStats > > > {
131
169
let tables = metadata_manager
132
170
. catalog_controller
133
171
. list_tables_by_type ( table_type. into ( ) )
134
172
. await
135
173
. map_err ( err) ?;
136
174
137
- Ok ( Json ( tables) )
175
+ // Get table statistics from hummock manager
176
+ let version_stats = hummock_manager. get_version_stats ( ) . await ;
177
+
178
+ let tables_with_stats = tables
179
+ . into_iter ( )
180
+ . map ( |table| {
181
+ let stats = version_stats. table_stats . get ( & table. id ) ;
182
+ TableWithStats :: from_table_and_stats ( table, stats)
183
+ } )
184
+ . collect ( ) ;
185
+
186
+ Ok ( Json ( tables_with_stats) )
138
187
}
139
188
140
189
pub async fn list_materialized_views (
141
190
Extension ( srv) : Extension < Service > ,
142
- ) -> Result < Json < Vec < Table > > > {
143
- list_table_catalogs_inner ( & srv. metadata_manager , TableType :: MaterializedView ) . await
191
+ ) -> Result < Json < Vec < TableWithStats > > > {
192
+ list_table_catalogs_inner (
193
+ & srv. metadata_manager ,
194
+ & srv. hummock_manager ,
195
+ TableType :: MaterializedView ,
196
+ )
197
+ . await
144
198
}
145
199
146
- pub async fn list_tables ( Extension ( srv) : Extension < Service > ) -> Result < Json < Vec < Table > > > {
147
- list_table_catalogs_inner ( & srv. metadata_manager , TableType :: Table ) . await
200
+ pub async fn list_tables (
201
+ Extension ( srv) : Extension < Service > ,
202
+ ) -> Result < Json < Vec < TableWithStats > > > {
203
+ list_table_catalogs_inner (
204
+ & srv. metadata_manager ,
205
+ & srv. hummock_manager ,
206
+ TableType :: Table ,
207
+ )
208
+ . await
148
209
}
149
210
150
- pub async fn list_index_tables ( Extension ( srv) : Extension < Service > ) -> Result < Json < Vec < Table > > > {
151
- list_table_catalogs_inner ( & srv. metadata_manager , TableType :: Index ) . await
211
+ pub async fn list_index_tables (
212
+ Extension ( srv) : Extension < Service > ,
213
+ ) -> Result < Json < Vec < TableWithStats > > > {
214
+ list_table_catalogs_inner (
215
+ & srv. metadata_manager ,
216
+ & srv. hummock_manager ,
217
+ TableType :: Index ,
218
+ )
219
+ . await
152
220
}
153
221
154
222
pub async fn list_indexes ( Extension ( srv) : Extension < Service > ) -> Result < Json < Vec < Index > > > {
@@ -177,8 +245,13 @@ pub(super) mod handlers {
177
245
178
246
pub async fn list_internal_tables (
179
247
Extension ( srv) : Extension < Service > ,
180
- ) -> Result < Json < Vec < Table > > > {
181
- list_table_catalogs_inner ( & srv. metadata_manager , TableType :: Internal ) . await
248
+ ) -> Result < Json < Vec < TableWithStats > > > {
249
+ list_table_catalogs_inner (
250
+ & srv. metadata_manager ,
251
+ & srv. hummock_manager ,
252
+ TableType :: Internal ,
253
+ )
254
+ . await
182
255
}
183
256
184
257
pub async fn list_sources ( Extension ( srv) : Extension < Service > ) -> Result < Json < Vec < Source > > > {
0 commit comments