@@ -33,12 +33,21 @@ use crate::{
33
33
handlers:: http:: { cluster:: fetch_daily_stats, logstream:: error:: StreamError } ,
34
34
parseable:: PARSEABLE ,
35
35
rbac:: { map:: SessionKey , role:: Action , Users } ,
36
+ stats:: Stats ,
36
37
storage:: { ObjectStorageError , ObjectStoreFormat , StreamType , STREAM_ROOT_DIRECTORY } ,
37
38
users:: { dashboards:: DASHBOARDS , filters:: FILTERS } ,
38
39
} ;
39
40
40
41
type StreamMetadataResponse = Result < ( String , Vec < ObjectStoreFormat > , DataSetType ) , PrismHomeError > ;
41
42
43
+ #[ derive( Debug , Serialize , Default ) ]
44
+ pub struct DatasetStats {
45
+ dataset_name : String ,
46
+ events : u64 ,
47
+ ingestion_size : u64 ,
48
+ storage_size : u64 ,
49
+ }
50
+
42
51
#[ derive( Debug , Serialize , Default ) ]
43
52
pub struct DatedStats {
44
53
date : String ,
@@ -65,6 +74,7 @@ pub struct HomeResponse {
65
74
pub alerts_info : AlertsInfo ,
66
75
pub stats_details : Vec < DatedStats > ,
67
76
pub datasets : Vec < DataSet > ,
77
+ pub top_five_ingestion : Vec < ( String , Stats ) > ,
68
78
}
69
79
70
80
#[ derive( Debug , Serialize ) ]
@@ -117,7 +127,7 @@ pub async fn generate_home_response(
117
127
let stream_metadata_results: Vec < StreamMetadataResponse > =
118
128
futures:: future:: join_all ( stream_metadata_futures) . await ;
119
129
120
- let mut stream_wise_stream_json = HashMap :: new ( ) ;
130
+ let mut stream_wise_stream_json: HashMap < String , Vec < ObjectStoreFormat > > = HashMap :: new ( ) ;
121
131
let mut datasets = Vec :: new ( ) ;
122
132
123
133
for result in stream_metadata_results {
@@ -144,6 +154,8 @@ pub async fn generate_home_response(
144
154
}
145
155
}
146
156
157
+ let top_five_ingestion = get_top_5_streams_by_ingestion ( & stream_wise_stream_json) ;
158
+
147
159
// Process stats for all dates concurrently
148
160
let stats_futures = dates
149
161
. iter ( )
@@ -169,8 +181,39 @@ pub async fn generate_home_response(
169
181
stats_details : stream_details,
170
182
datasets,
171
183
alerts_info,
184
+ top_five_ingestion,
172
185
} )
173
186
}
187
+
188
+ fn get_top_5_streams_by_ingestion (
189
+ stream_wise_stream_json : & HashMap < String , Vec < ObjectStoreFormat > > ,
190
+ ) -> Vec < ( String , Stats ) > {
191
+ let mut result: Vec < _ > = stream_wise_stream_json
192
+ . iter ( )
193
+ . map ( |( stream_name, formats) | {
194
+ let total_stats = formats. iter ( ) . fold (
195
+ Stats {
196
+ events : 0 ,
197
+ ingestion : 0 ,
198
+ storage : 0 ,
199
+ } ,
200
+ |mut acc, osf| {
201
+ let current = & osf. stats . current_stats ;
202
+ acc. events += current. events ;
203
+ acc. ingestion += current. ingestion ;
204
+ acc. storage += current. storage ;
205
+ acc
206
+ } ,
207
+ ) ;
208
+ ( stream_name. clone ( ) , total_stats)
209
+ } )
210
+ . collect ( ) ;
211
+
212
+ result. sort_by_key ( |( _, stats) | std:: cmp:: Reverse ( stats. ingestion ) ) ;
213
+ result. truncate ( 5 ) ;
214
+ result
215
+ }
216
+
174
217
async fn get_stream_metadata (
175
218
stream : String ,
176
219
) -> Result < ( String , Vec < ObjectStoreFormat > , DataSetType ) , PrismHomeError > {
0 commit comments