Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show alert annotations #833

Merged
merged 3 commits into from
May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions examples/ha/send_alerts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,44 @@ alerts1='[
"alertname": "DiskRunningFull",
"dev": "sda1",
"instance": "example1"
}
},
"annotations": {
"info": "The disk sda1 is running full",
"summary": "please check the instance example1"
}
},
{
"labels": {
"alertname": "DiskRunningFull",
"dev": "sda2",
"instance": "example1"
}
},
"annotations": {
"info": "The disk sda2 is running full",
"summary": "please check the instance example1"
}
},
{
"labels": {
"alertname": "DiskRunningFull",
"dev": "sda1",
"instance": "example2"
}
},
"annotations": {
"info": "The disk sda1 is running full",
"summary": "please check the instance example2"
}
},
{
"labels": {
"alertname": "DiskRunningFull",
"dev": "sdb2",
"instance": "example2"
}
},
"annotations": {
"info": "The disk sdb2 is running full",
"summary": "please check the instance example2"
}
},
{
"labels": {
Expand Down
2 changes: 1 addition & 1 deletion ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM node:latest

RUN npm install -g elm elm-format elm-test
RUN npm install -g elm@0.18.0 elm-format@0.6.1-alpha elm-test@0.18.3
48 changes: 12 additions & 36 deletions ui/app/src/Alerts/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,23 @@ fetchAlerts filter =
Utils.Api.send (Utils.Api.get url alertsDecoder)



-- Decoders
-- Once the API returns the newly created silence, this can go away and we
-- re-use the silence decoder.


alertsDecoder : Json.Decoder (List Alert)
alertsDecoder =
Json.at [ "data" ] (Json.list alertDecoder)


unwrapWithDefault : a -> Maybe a -> Json.Decoder a
unwrapWithDefault default val =
case val of
Just a ->
Json.succeed a
Json.list alertDecoder
-- populate alerts with ids:
|> Json.map (List.indexedMap (toString >> (|>)))
|> field "data"

Nothing ->
Json.succeed default


alertDecoder : Json.Decoder Alert
{-| TODO: decode alert id when provided
-}
alertDecoder : Json.Decoder (String -> Alert)
alertDecoder =
Json.map6 Alert
(Json.maybe (field "annotations" (Json.keyValuePairs Json.string)) |> andThen (unwrapWithDefault []))
Json.map5 Alert
(Json.maybe (field "annotations" (Json.keyValuePairs Json.string))
|> andThen (Maybe.withDefault [] >> Json.succeed)
)
(field "labels" (Json.keyValuePairs Json.string))
(Json.maybe (field "silenced" Json.string))
(decodeSilenced)
(Json.maybe (Json.at [ "status", "silencedBy", "0" ] Json.string))
(field "startsAt" iso8601Time)
(field "generatorURL" Json.string)


decodeSilenced : Decoder Bool
decodeSilenced =
Json.maybe (field "silenced" Json.string)
|> andThen
(\val ->
case val of
Just _ ->
Json.succeed True

Nothing ->
Json.succeed False
)
2 changes: 1 addition & 1 deletion ui/app/src/Alerts/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type alias Alert =
{ annotations : Labels
, labels : Labels
, silenceId : Maybe String
, silenced : Bool
, startsAt : Time
, generatorUrl : String
, id : String
}


Expand Down
41 changes: 37 additions & 4 deletions ui/app/src/Views/AlertList/AlertView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import Html.Events exposing (onClick)
import Types exposing (Msg(CreateSilenceFromAlert, Noop, MsgForAlertList))
import Utils.Date
import Views.FilterBar.Types as FilterBarTypes
import Views.AlertList.Types exposing (AlertListMsg(MsgForFilterBar))
import Views.AlertList.Types exposing (AlertListMsg(MsgForFilterBar, SetActive))
import Utils.Filter
import Time exposing (Time)


view : List ( String, String ) -> Alert -> Html Msg
view labels alert =
view : List ( String, String ) -> Maybe String -> Alert -> Html Msg
view labels maybeActiveId alert =
let
-- remove the grouping labels, and bring the alertname to front
ungroupedLabels =
Expand All @@ -25,11 +25,20 @@ view labels alert =
li
[ class "align-items-start list-group-item border-0 alert-list-item p-0 mb-4"
]
[ div [ class "w-100 mb-2 d-flex align-items-start" ]
[ div
[ class "w-100 mb-2 d-flex align-items-start" ]
[ dateView alert.startsAt
, if List.length alert.annotations > 0 then
annotationsButton maybeActiveId alert
else
text ""
, generatorUrlButton alert.generatorUrl
, silenceButton alert
]
, if maybeActiveId == Just alert.id then
table [ class "table w-100 mb-1" ] (List.map annotation alert.annotations)
else
text ""
, div [] (List.map labelButton ungroupedLabels)
]

Expand All @@ -43,6 +52,30 @@ dateView time =
]


annotationsButton : Maybe String -> Alert -> Html Msg
annotationsButton maybeActiveId alert =
if maybeActiveId == Just alert.id then
button
[ onClick (SetActive Nothing |> MsgForAlertList)
, class "btn btn-outline-info border-0 active"
]
[ i [ class "fa fa-minus mr-2" ] [], text "Info" ]
else
button
[ onClick (SetActive (Just alert.id) |> MsgForAlertList)
, class "btn btn-outline-info border-0"
]
[ i [ class "fa fa-plus mr-2" ] [], text "Info" ]


annotation : ( String, String ) -> Html Msg
annotation ( key, value ) =
tr []
[ th [ class "text-nowrap" ] [ text (key ++ ":") ]
, td [ class "w-100" ] [ text value ]
]


labelButton : ( String, String ) -> Html Msg
labelButton ( key, value ) =
button
Expand Down
3 changes: 3 additions & 0 deletions ui/app/src/Views/AlertList/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type AlertListMsg
| MsgForFilterBar FilterBar.Msg
| MsgForGroupBar GroupBar.Msg
| ToggleSilenced Bool
| SetActive (Maybe String)
| SetTab Tab


Expand All @@ -25,6 +26,7 @@ type alias Model =
, groupBar : GroupBar.Model
, filterBar : FilterBar.Model
, tab : Tab
, activeId : Maybe String
}


Expand All @@ -34,4 +36,5 @@ initAlertList =
, groupBar = GroupBar.initGroupBar
, filterBar = FilterBar.initFilterBar
, tab = FilterTab
, activeId = Nothing
}
5 changes: 4 additions & 1 deletion ui/app/src/Views/AlertList/Updates.elm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ update msg ({ groupBar, filterBar } as model) filter =
newFilterBar =
FilterBar.setMatchers filter filterBar
in
( { model | alerts = Loading, filterBar = newFilterBar, groupBar = newGroupBar }
( { model | alerts = Loading, filterBar = newFilterBar, groupBar = newGroupBar, activeId = Nothing }
, Api.fetchAlerts filter |> Cmd.map (AlertsFetched >> MsgForAlertList)
)

Expand All @@ -67,3 +67,6 @@ update msg ({ groupBar, filterBar } as model) filter =
GroupBar.update "/#/alerts" filter msg groupBar
in
( { model | groupBar = newGroupBar }, Cmd.map (MsgForGroupBar >> MsgForAlertList) cmd )

SetActive maybeId ->
( { model | activeId = maybeId }, Cmd.none )
16 changes: 8 additions & 8 deletions ui/app/src/Views/AlertList/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ renderSilenced maybeShowSilenced =


view : Model -> Filter -> Html Msg
view { alerts, groupBar, filterBar, tab } filter =
view { alerts, groupBar, filterBar, tab, activeId } filter =
div []
[ div
[ class "card mb-5" ]
Expand All @@ -58,7 +58,7 @@ view { alerts, groupBar, filterBar, tab } filter =
]
, case alerts of
Success alerts ->
alertGroups filter groupBar alerts
alertGroups activeId filter groupBar alerts

Loading ->
Utils.Views.loading
Expand All @@ -71,8 +71,8 @@ view { alerts, groupBar, filterBar, tab } filter =
]


alertGroups : Filter -> GroupBar.Model -> List Alert -> Html Msg
alertGroups filter groupBar alerts =
alertGroups : Maybe String -> Filter -> GroupBar.Model -> List Alert -> Html Msg
alertGroups activeId filter groupBar alerts =
let
grouped =
alerts
Expand All @@ -86,14 +86,14 @@ alertGroups filter groupBar alerts =
|> List.filterMap
(\labels ->
Maybe.map
(alertList labels filter)
(alertList activeId labels filter)
(Dict.get labels grouped)
)
|> div []


alertList : Labels -> Filter -> List Alert -> Html Msg
alertList labels filter alerts =
alertList : Maybe String -> Labels -> Filter -> List Alert -> Html Msg
alertList activeId labels filter alerts =
div []
[ div []
(case labels of
Expand All @@ -111,5 +111,5 @@ alertList labels filter alerts =
, if List.isEmpty alerts then
div [] [ text "no alerts found" ]
else
ul [ class "list-group mb-4" ] (List.map (AlertView.view labels) alerts)
ul [ class "list-group mb-4" ] (List.map (AlertView.view labels activeId) alerts)
]
4 changes: 2 additions & 2 deletions ui/bindata.go

Large diffs are not rendered by default.