mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-26 16:12:20 +00:00
Parse alert list into alert groups when received from API
We can simplify the view flow by parsing the list of alerts for custom grouping as soon as they are returned to the update function. Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
This commit is contained in:
parent
b4fb8a28ef
commit
759bf7b6b6
@ -2,10 +2,12 @@ module Views.AlertList.Updates exposing (update)
|
||||
|
||||
import Alerts.Api as Api
|
||||
import Browser.Navigation as Navigation
|
||||
import Data.AlertGroup exposing (AlertGroup)
|
||||
import Dict
|
||||
import Set
|
||||
import Types exposing (Msg(..))
|
||||
import Utils.Filter exposing (Filter, generateQueryString, parseFilter)
|
||||
import Utils.List
|
||||
import Utils.Types exposing (ApiData(..))
|
||||
import Views.AlertList.Types exposing (AlertListMsg(..), Model, Tab(..))
|
||||
import Views.FilterBar.Updates as FilterBar
|
||||
@ -26,20 +28,44 @@ update msg ({ groupBar, alerts, filterBar, receiverBar, alertGroups } as model)
|
||||
)
|
||||
|
||||
AlertsFetched listOfAlerts ->
|
||||
( { model
|
||||
| alerts = listOfAlerts
|
||||
, groupBar =
|
||||
let
|
||||
( groups_, groupBar_ ) =
|
||||
case listOfAlerts of
|
||||
Success ungroupedAlerts ->
|
||||
let
|
||||
groups =
|
||||
ungroupedAlerts
|
||||
|> Utils.List.groupBy
|
||||
(.labels >> Dict.toList >> List.filter (\( key, _ ) -> List.member key groupBar.fields))
|
||||
|> Dict.toList
|
||||
|> List.map
|
||||
(\( labels, alerts_ ) ->
|
||||
AlertGroup (Dict.fromList labels) { name = "unknown" } alerts_
|
||||
)
|
||||
|
||||
newGroupBar =
|
||||
{ groupBar
|
||||
| list =
|
||||
List.concatMap (.labels >> Dict.toList) ungroupedAlerts
|
||||
|> List.map Tuple.first
|
||||
|> Set.fromList
|
||||
}
|
||||
in
|
||||
( Success groups, newGroupBar )
|
||||
|
||||
_ ->
|
||||
groupBar
|
||||
Initial ->
|
||||
( Initial, groupBar )
|
||||
|
||||
Loading ->
|
||||
( Loading, groupBar )
|
||||
|
||||
Failure e ->
|
||||
( Failure e, groupBar )
|
||||
in
|
||||
( { model
|
||||
| alerts = listOfAlerts
|
||||
, alertGroups = groups_
|
||||
, groupBar = groupBar_
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
@ -70,35 +70,10 @@ view { alerts, alertGroups, groupBar, filterBar, receiverBar, tab, activeId, act
|
||||
Html.map (MsgForGroupBar >> MsgForAlertList) (GroupBar.view groupBar filter.customGrouping)
|
||||
]
|
||||
]
|
||||
, if filter.customGrouping then
|
||||
Utils.Views.apiData (customAlertGroups activeId activeLabels groupBar) alerts
|
||||
|
||||
else
|
||||
Utils.Views.apiData (defaultAlertGroups activeId activeLabels) alertGroups
|
||||
, Utils.Views.apiData (defaultAlertGroups activeId activeLabels) alertGroups
|
||||
]
|
||||
|
||||
|
||||
customAlertGroups : Maybe String -> Maybe Labels -> GroupBar.Model -> List GettableAlert -> Html Msg
|
||||
customAlertGroups activeId activeLabels { fields } ungroupedAlerts =
|
||||
ungroupedAlerts
|
||||
|> Utils.List.groupBy
|
||||
(.labels >> Dict.toList >> List.filter (\( key, _ ) -> List.member key fields))
|
||||
|> (\groupsDict ->
|
||||
case Dict.toList groupsDict of
|
||||
[] ->
|
||||
Utils.Views.error "No alerts found"
|
||||
|
||||
groups ->
|
||||
div []
|
||||
(List.map
|
||||
(\( labels, alerts ) ->
|
||||
alertGroup activeId activeLabels labels alerts
|
||||
)
|
||||
groups
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
defaultAlertGroups : Maybe String -> Maybe Labels -> List AlertGroup -> Html Msg
|
||||
defaultAlertGroups activeId activeLabels groups =
|
||||
case groups of
|
||||
|
Loading…
Reference in New Issue
Block a user