@@ -44,7 +44,7 @@ use crate::{
44
44
type StreamMetadataResponse = Result < ( String , Vec < ObjectStoreFormat > , DataSetType ) , PrismHomeError > ;
45
45
46
46
#[ derive( Debug , Serialize , Default ) ]
47
- struct StreamInfo {
47
+ struct StreamStats {
48
48
// stream_count: u32,
49
49
// log_source_count: u32,
50
50
stats_summary : Stats ,
@@ -79,40 +79,25 @@ struct DataSet {
79
79
80
80
#[ derive( Debug , Serialize ) ]
81
81
pub struct HomeResponse {
82
- alert_titles : Vec < TitleAndId > ,
83
82
alerts_info : AlertsInfo ,
84
- correlation_titles : Vec < TitleAndId > ,
85
- stream_info : StreamInfo ,
86
83
stats_details : Vec < DatedStats > ,
87
- stream_titles : Vec < String > ,
88
84
datasets : Vec < DataSet > ,
89
- dashboard_titles : Vec < TitleAndId > ,
90
- filter_titles : Vec < TitleAndId > ,
85
+ }
86
+
87
+ #[ derive( Debug , Serialize ) ]
88
+ pub struct HomeSearchResponse {
89
+ alerts : Vec < TitleAndId > ,
90
+ correlations : Vec < TitleAndId > ,
91
+ dashboards : Vec < TitleAndId > ,
92
+ filters : Vec < TitleAndId > ,
91
93
}
92
94
93
95
pub async fn generate_home_response ( key : & SessionKey ) -> Result < HomeResponse , PrismHomeError > {
94
96
// Execute these operations concurrently
95
- let (
96
- stream_titles_result,
97
- alert_titles_result,
98
- correlation_titles_result,
99
- dashboards_result,
100
- filters_result,
101
- alerts_info_result,
102
- ) = tokio:: join!(
103
- get_stream_titles( key) ,
104
- get_alert_titles( key) ,
105
- get_correlation_titles( key) ,
106
- get_dashboard_titles( key) ,
107
- get_filter_titles( key) ,
108
- get_alerts_info( )
109
- ) ;
97
+ let ( stream_titles_result, alerts_info_result) =
98
+ tokio:: join!( get_stream_titles( key) , get_alerts_info( ) ) ;
110
99
111
100
let stream_titles = stream_titles_result?;
112
- let alert_titles = alert_titles_result?;
113
- let correlation_titles = correlation_titles_result?;
114
- let dashboard_titles = dashboards_result?;
115
- let filter_titles = filters_result?;
116
101
let alerts_info = alerts_info_result?;
117
102
118
103
// Generate dates for date-wise stats
@@ -161,7 +146,7 @@ pub async fn generate_home_response(key: &SessionKey) -> Result<HomeResponse, Pr
161
146
futures:: future:: join_all ( stats_futures) . await ;
162
147
163
148
let mut stream_details = Vec :: new ( ) ;
164
- let mut summary = StreamInfo :: default ( ) ;
149
+ let mut summary = StreamStats :: default ( ) ;
165
150
166
151
for result in stats_results {
167
152
match result {
@@ -179,104 +164,11 @@ pub async fn generate_home_response(key: &SessionKey) -> Result<HomeResponse, Pr
179
164
}
180
165
181
166
Ok ( HomeResponse {
182
- stream_info : summary,
183
167
stats_details : stream_details,
184
- stream_titles,
185
168
datasets,
186
- alert_titles,
187
- correlation_titles,
188
- dashboard_titles,
189
- filter_titles,
190
169
alerts_info,
191
170
} )
192
171
}
193
-
194
- // Helper functions to split the work
195
-
196
- async fn get_stream_titles ( key : & SessionKey ) -> Result < Vec < String > , PrismHomeError > {
197
- let stream_titles: Vec < String > = PARSEABLE
198
- . storage
199
- . get_object_store ( )
200
- . list_streams ( )
201
- . await
202
- . map_err ( |e| PrismHomeError :: Anyhow ( anyhow:: Error :: new ( e) ) ) ?
203
- . into_iter ( )
204
- . filter ( |logstream| {
205
- Users . authorize ( key. clone ( ) , Action :: ListStream , Some ( logstream) , None )
206
- == crate :: rbac:: Response :: Authorized
207
- } )
208
- . sorted ( )
209
- . collect_vec ( ) ;
210
-
211
- Ok ( stream_titles)
212
- }
213
-
214
- async fn get_alert_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
215
- let alert_titles = ALERTS
216
- . list_alerts_for_user ( key. clone ( ) )
217
- . await ?
218
- . iter ( )
219
- . map ( |alert| TitleAndId {
220
- title : alert. title . clone ( ) ,
221
- id : alert. id . to_string ( ) ,
222
- } )
223
- . collect_vec ( ) ;
224
-
225
- Ok ( alert_titles)
226
- }
227
-
228
- async fn get_correlation_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
229
- let correlation_titles = CORRELATIONS
230
- . list_correlations ( key)
231
- . await ?
232
- . iter ( )
233
- . map ( |corr| TitleAndId {
234
- title : corr. title . clone ( ) ,
235
- id : corr. id . clone ( ) ,
236
- } )
237
- . collect_vec ( ) ;
238
-
239
- Ok ( correlation_titles)
240
- }
241
-
242
- async fn get_dashboard_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
243
- let dashboard_titles = DASHBOARDS
244
- . list_dashboards ( key)
245
- . await
246
- . iter ( )
247
- . map ( |dashboard| TitleAndId {
248
- title : dashboard. name . clone ( ) ,
249
- id : dashboard
250
- . dashboard_id
251
- . as_ref ( )
252
- . ok_or_else ( || anyhow:: Error :: msg ( "Dashboard ID is null" ) )
253
- . unwrap ( )
254
- . clone ( ) ,
255
- } )
256
- . collect_vec ( ) ;
257
-
258
- Ok ( dashboard_titles)
259
- }
260
-
261
- async fn get_filter_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
262
- let filter_titles = FILTERS
263
- . list_filters ( key)
264
- . await
265
- . iter ( )
266
- . map ( |filter| TitleAndId {
267
- title : filter. filter_name . clone ( ) ,
268
- id : filter
269
- . filter_id
270
- . as_ref ( )
271
- . ok_or_else ( || anyhow:: Error :: msg ( "Filter ID is null" ) )
272
- . unwrap ( )
273
- . clone ( ) ,
274
- } )
275
- . collect_vec ( ) ;
276
-
277
- Ok ( filter_titles)
278
- }
279
-
280
172
async fn get_stream_metadata (
281
173
stream : String ,
282
174
) -> Result < ( String , Vec < ObjectStoreFormat > , DataSetType ) , PrismHomeError > {
@@ -374,6 +266,114 @@ async fn get_stream_stats_for_date(
374
266
) )
375
267
}
376
268
269
+ pub async fn generate_home_search_response (
270
+ key : & SessionKey ,
271
+ ) -> Result < HomeSearchResponse , PrismHomeError > {
272
+ let ( alert_titles, correlation_titles, dashboard_titles, filter_titles) = tokio:: join!(
273
+ get_alert_titles( key) ,
274
+ get_correlation_titles( key) ,
275
+ get_dashboard_titles( key) ,
276
+ get_filter_titles( key)
277
+ ) ;
278
+
279
+ let alerts = alert_titles?;
280
+ let correlations = correlation_titles?;
281
+ let dashboards = dashboard_titles?;
282
+ let filters = filter_titles?;
283
+
284
+ Ok ( HomeSearchResponse {
285
+ alerts,
286
+ correlations,
287
+ dashboards,
288
+ filters,
289
+ } )
290
+ }
291
+
292
+ // Helper functions to split the work
293
+ async fn get_stream_titles ( key : & SessionKey ) -> Result < Vec < String > , PrismHomeError > {
294
+ let stream_titles: Vec < String > = PARSEABLE
295
+ . storage
296
+ . get_object_store ( )
297
+ . list_streams ( )
298
+ . await
299
+ . map_err ( |e| PrismHomeError :: Anyhow ( anyhow:: Error :: new ( e) ) ) ?
300
+ . into_iter ( )
301
+ . filter ( |logstream| {
302
+ Users . authorize ( key. clone ( ) , Action :: ListStream , Some ( logstream) , None )
303
+ == crate :: rbac:: Response :: Authorized
304
+ } )
305
+ . sorted ( )
306
+ . collect_vec ( ) ;
307
+
308
+ Ok ( stream_titles)
309
+ }
310
+
311
+ async fn get_alert_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
312
+ let alert_titles = ALERTS
313
+ . list_alerts_for_user ( key. clone ( ) )
314
+ . await ?
315
+ . iter ( )
316
+ . map ( |alert| TitleAndId {
317
+ title : alert. title . clone ( ) ,
318
+ id : alert. id . to_string ( ) ,
319
+ } )
320
+ . collect_vec ( ) ;
321
+
322
+ Ok ( alert_titles)
323
+ }
324
+
325
+ async fn get_correlation_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
326
+ let correlation_titles = CORRELATIONS
327
+ . list_correlations ( key)
328
+ . await ?
329
+ . iter ( )
330
+ . map ( |corr| TitleAndId {
331
+ title : corr. title . clone ( ) ,
332
+ id : corr. id . clone ( ) ,
333
+ } )
334
+ . collect_vec ( ) ;
335
+
336
+ Ok ( correlation_titles)
337
+ }
338
+
339
+ async fn get_dashboard_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
340
+ let dashboard_titles = DASHBOARDS
341
+ . list_dashboards ( key)
342
+ . await
343
+ . iter ( )
344
+ . map ( |dashboard| TitleAndId {
345
+ title : dashboard. name . clone ( ) ,
346
+ id : dashboard
347
+ . dashboard_id
348
+ . as_ref ( )
349
+ . ok_or_else ( || anyhow:: Error :: msg ( "Dashboard ID is null" ) )
350
+ . unwrap ( )
351
+ . clone ( ) ,
352
+ } )
353
+ . collect_vec ( ) ;
354
+
355
+ Ok ( dashboard_titles)
356
+ }
357
+
358
+ async fn get_filter_titles ( key : & SessionKey ) -> Result < Vec < TitleAndId > , PrismHomeError > {
359
+ let filter_titles = FILTERS
360
+ . list_filters ( key)
361
+ . await
362
+ . iter ( )
363
+ . map ( |filter| TitleAndId {
364
+ title : filter. filter_name . clone ( ) ,
365
+ id : filter
366
+ . filter_id
367
+ . as_ref ( )
368
+ . ok_or_else ( || anyhow:: Error :: msg ( "Filter ID is null" ) )
369
+ . unwrap ( )
370
+ . clone ( ) ,
371
+ } )
372
+ . collect_vec ( ) ;
373
+
374
+ Ok ( filter_titles)
375
+ }
376
+
377
377
#[ derive( Debug , thiserror:: Error ) ]
378
378
pub enum PrismHomeError {
379
379
#[ error( "Error: {0}" ) ]
0 commit comments