@@ -57,6 +57,7 @@ interface AlertDetails {
5757 alertName : string ;
5858 severity : string ;
5959 value : number ;
60+ description : string ;
6061}
6162
6263function usePrometheusWebSocket ( ) {
@@ -318,14 +319,16 @@ export function PrometheusQueryBox({
318319 } , [ executeQuery , hardcodedQuery , sessionName ] ) ;
319320
320321 const getAlertDetails = useCallback ( ( ) => {
321- if ( queryResults . length === 0 ) return null ;
322+ if ( queryResults . length === 0 ) return [ ] ;
322323 const result = queryResults [ 0 ] ;
323- if ( result . data . result . length === 0 ) return null ;
324-
325- const alertInfo = result . data . result [ 0 ] . metric ;
326- console . log ( "alertName: " , alertInfo . name ) ;
327- const alertName = alertInfo . name ;
328- return alertName ;
324+ if ( result . data . result . length === 0 ) return [ ] ;
325+
326+ // Get all alert names from the ALERTS query results
327+ const alertNames = result . data . result . map (
328+ ( alertResult ) => alertResult . metric . name
329+ ) ;
330+ console . log ( "Alert names from ALERTS query: " , alertNames ) ;
331+ return alertNames ;
329332 } , [ queryResults ] ) ;
330333
331334 const handleCloseButton = useCallback ( ( ) => {
@@ -346,12 +349,17 @@ export function PrometheusQueryBox({
346349 } , [ getAllQueryResults ] ) ;
347350
348351 useEffect ( ( ) => {
349- let alertDetails = getAlertDetails ( ) ;
350- console . log ( "🚨 Alert details:" , alertDetails ) ;
351- getAllAlertDetails ( alertDetails ) ;
352- } , [ queryResults ] ) ;
352+ const alertNames = getAlertDetails ( ) ;
353+ console . log ( "🚨 Alert names:" , alertNames ) ;
354+ getAllAlertDetails ( alertNames ) ;
355+ } , [ queryResults , getAlertDetails ] ) ;
356+
357+ async function getAllAlertDetails ( alertNames : string [ ] ) {
358+ if ( ! alertNames || alertNames . length === 0 ) {
359+ setAlerts ( [ ] ) ;
360+ return ;
361+ }
353362
354- async function getAllAlertDetails ( alertName : string ) {
355363 const detailsQuery = {
356364 label : "Alerts for this session" ,
357365 path : `http://prometheus-server.monitoring.svc.cluster.local/api/v1/alerts` ,
@@ -362,24 +370,31 @@ export function PrometheusQueryBox({
362370 } ;
363371
364372 const result = await executeQuery ( detailsQuery ) ;
365- console . log ( "📊 Alert details query result:" , result ?. data . alerts [ 0 ] . value ) ;
373+ console . log ( "📊 Alert details query result:" , result ?. data . alerts ) ;
374+
366375 if ( result ?. data ?. alerts ?. length && result . data . alerts . length > 0 ) {
367- const alert = result . data . alerts . find ( ( a ) => a . labels . name === alertName ) ;
368- if ( alert ) {
376+ // Filter alerts to only include those from the ALERTS query
377+ const relevantAlerts = result . data . alerts . filter ( ( alert ) =>
378+ alertNames . includes ( alert . labels . name )
379+ ) ;
380+
381+ const alertDetails : AlertDetails [ ] = relevantAlerts . map ( ( alert ) => {
369382 const severity = alert . labels . severity || "unknown" ;
370383 const value = parseFloat ( alert . value ) || 0 ;
371384 console . log (
372385 `🚨 Alert found - Name: ${ alert . labels . alertname } , Severity: ${ severity } , Value: ${ value } `
373386 ) ;
374- const newAlert : AlertDetails = {
387+ return {
375388 alertName : alert . labels . alertname ,
376389 severity,
377390 value,
391+ description : alert . annotations ?. description || "" ,
378392 } ;
379- setAlerts ( [ newAlert ] ) ;
380- } else {
381- console . log ( `ℹ️ No alert found with name: ${ alertName } ` ) ;
382- }
393+ } ) ;
394+ setAlerts ( alertDetails ) ;
395+ } else {
396+ console . log ( `ℹ️ No alerts found` ) ;
397+ setAlerts ( [ ] ) ;
383398 }
384399 }
385400
@@ -408,15 +423,16 @@ export function PrometheusQueryBox({
408423
409424 { alerts . map ( ( alert , idx ) => (
410425 < div key = { idx } className = "mb-2" >
411- < div className = "fw-bold" > { alert . alertName } </ div >
412- < div className = "mb-1" >
413- < div
414- className = {
415- "text-warning"
416- }
417- >
418- Severity: { alert . severity } , Value: { alert . value }
419- </ div >
426+ < div className = "fw-normal text-dark medium" >
427+ { alert . description || alert . alertName }
428+ </ div >
429+ < div
430+ className = { cx (
431+ "medium" ,
432+ alert . severity === "warning" ? "text-warning" : "text-danger"
433+ ) }
434+ >
435+ { alert . value }
420436 </ div >
421437 </ div >
422438 ) ) }
0 commit comments