mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-19 12:40:49 +00:00
Move to using ISO8601 date
Useability for the form is horrible, and will be fixed after silences are being created.
This commit is contained in:
parent
764dbb229e
commit
00897e85c7
@ -12,7 +12,8 @@
|
||||
"elm-lang/html": "2.0.0 <= v < 3.0.0",
|
||||
"elm-lang/http": "1.0.0 <= v < 2.0.0",
|
||||
"elm-lang/navigation": "2.0.1 <= v < 3.0.0",
|
||||
"evancz/url-parser": "2.0.1 <= v < 3.0.0"
|
||||
"evancz/url-parser": "2.0.1 <= v < 3.0.0",
|
||||
"jweir/elm-iso8601": "3.0.2 <= v < 4.0.0"
|
||||
},
|
||||
"elm-version": "0.18.0 <= v < 0.19.0"
|
||||
}
|
||||
|
15
src/Api.elm
15
src/Api.elm
@ -7,6 +7,7 @@ import Json.Decode as Json exposing (..)
|
||||
import Task
|
||||
import String
|
||||
import Date exposing (..)
|
||||
import ISO8601
|
||||
|
||||
|
||||
-- Internal Imports
|
||||
@ -102,7 +103,7 @@ alertDecoder =
|
||||
(field "inhibited" Json.bool)
|
||||
(Json.maybe (field "silenced" Json.int))
|
||||
(decodeSilenced)
|
||||
(field "startsAt" stringToDate)
|
||||
(field "startsAt" stringtoISO8601)
|
||||
(field "generatorURL" Json.string)
|
||||
|
||||
|
||||
@ -120,12 +121,12 @@ decodeSilenced =
|
||||
)
|
||||
|
||||
|
||||
stringToDate : Decoder Date.Date
|
||||
stringToDate =
|
||||
stringtoISO8601 : Decoder ISO8601.Time
|
||||
stringtoISO8601 =
|
||||
Json.string
|
||||
|> andThen
|
||||
(\val ->
|
||||
case Date.fromString val of
|
||||
case ISO8601.fromString val of
|
||||
Err err ->
|
||||
Json.fail err
|
||||
|
||||
@ -150,9 +151,9 @@ silenceDecoder =
|
||||
(field "id" Json.int)
|
||||
(field "createdBy" Json.string)
|
||||
(field "comment" Json.string)
|
||||
(field "startsAt" Json.string)
|
||||
(field "endsAt" Json.string)
|
||||
(field "createdAt" Json.string)
|
||||
(field "startsAt" stringtoISO8601)
|
||||
(field "endsAt" stringtoISO8601)
|
||||
(field "createdAt" stringtoISO8601)
|
||||
(field "matchers" (Json.list matcherDecoder))
|
||||
|
||||
|
||||
|
54
src/Main.elm
54
src/Main.elm
@ -1,9 +1,12 @@
|
||||
-- External Imports
|
||||
|
||||
|
||||
module Main exposing (..)
|
||||
|
||||
-- External Imports
|
||||
|
||||
import Date
|
||||
import Navigation
|
||||
import Task
|
||||
import Time
|
||||
import ISO8601
|
||||
|
||||
|
||||
-- Internal Imports
|
||||
@ -13,6 +16,7 @@ import Views
|
||||
import Api
|
||||
import Types exposing (..)
|
||||
import Utils.List
|
||||
import Utils.Date
|
||||
|
||||
|
||||
main =
|
||||
@ -35,7 +39,7 @@ init location =
|
||||
|
||||
nullSilence : Silence
|
||||
nullSilence =
|
||||
Silence 0 "" "" "" "" "" [ nullMatcher ]
|
||||
Silence 0 "" "" Utils.Date.unixEpochStart Utils.Date.unixEpochStart Utils.Date.unixEpochStart [ nullMatcher ]
|
||||
|
||||
|
||||
nullMatcher : Matcher
|
||||
@ -69,7 +73,7 @@ update msg model =
|
||||
( { model | route = EditSilenceRoute id }, Api.getSilence id )
|
||||
|
||||
NewSilence ->
|
||||
( { model | silence = nullSilence, route = NewSilenceRoute }, Cmd.none )
|
||||
( { model | route = NewSilenceRoute }, Cmd.none )
|
||||
|
||||
FetchAlertGroups ->
|
||||
( { model | route = AlertGroupsRoute }, Api.getAlertGroups )
|
||||
@ -87,20 +91,25 @@ update msg model =
|
||||
RedirectAlerts ->
|
||||
( { model | route = AlertGroupsRoute }, Navigation.newUrl "/#/alerts" )
|
||||
|
||||
UpdateStartsAt date ->
|
||||
-- TODO: Will have to parse the date into a string probably.
|
||||
UpdateStartsAt time ->
|
||||
let
|
||||
sil =
|
||||
model.silence
|
||||
in
|
||||
( { model | silence = { sil | startsAt = date } }, Cmd.none )
|
||||
|
||||
UpdateEndsAt date ->
|
||||
startsAt =
|
||||
Utils.Date.parseWithDefault sil.startsAt time
|
||||
in
|
||||
( { model | silence = { sil | startsAt = startsAt } }, Cmd.none )
|
||||
|
||||
UpdateEndsAt time ->
|
||||
let
|
||||
sil =
|
||||
model.silence
|
||||
|
||||
endsAt =
|
||||
Utils.Date.parseWithDefault sil.endsAt time
|
||||
in
|
||||
( { model | silence = { sil | endsAt = date } }, Cmd.none )
|
||||
( { model | silence = { sil | endsAt = endsAt } }, Cmd.none )
|
||||
|
||||
UpdateCreatedBy by ->
|
||||
let
|
||||
@ -168,6 +177,29 @@ update msg model =
|
||||
in
|
||||
( { model | silence = { s | matchers = matchers } }, Cmd.none )
|
||||
|
||||
SilenceFromAlert matchers ->
|
||||
let
|
||||
s =
|
||||
{ nullSilence | matchers = List.sortBy .name matchers }
|
||||
in
|
||||
( { model | silence = s }, (Task.perform NewDefaultTimeRange Time.now) )
|
||||
|
||||
NewDefaultTimeRange time ->
|
||||
let
|
||||
endsAt =
|
||||
Utils.Date.addTime time (2 * Time.hour)
|
||||
|
||||
startsAt =
|
||||
Utils.Date.toISO8601 time
|
||||
|
||||
s =
|
||||
model.silence
|
||||
in
|
||||
( { model | silence = { s | startsAt = startsAt, endsAt = endsAt } }, Cmd.none )
|
||||
|
||||
Noop _ ->
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
urlUpdate : Navigation.Location -> Msg
|
||||
urlUpdate location =
|
||||
|
@ -5,6 +5,7 @@ module Silences.Views exposing (..)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import ISO8601
|
||||
|
||||
|
||||
-- Internal Imports
|
||||
@ -31,7 +32,7 @@ silenceView silence =
|
||||
[ class "f6 link br2 ba ph3 pv2 mr2 dib dark-blue"
|
||||
, href ("#/silences/" ++ (toString silence.id) ++ "/edit")
|
||||
]
|
||||
[ text "Create" ]
|
||||
[ text "Update" ]
|
||||
]
|
||||
|
||||
|
||||
@ -69,8 +70,8 @@ silenceFormView kind silence =
|
||||
div [ class "pa4 black-80" ]
|
||||
[ fieldset [ class "ba b--transparent ph0 mh0" ]
|
||||
[ legend [ class "ph0 mh0 fw6" ] [ text <| kind ++ " Silence" ]
|
||||
, formField "Start" silence.startsAt UpdateStartsAt
|
||||
, formField "End" silence.endsAt UpdateEndsAt
|
||||
, formField "Start" (ISO8601.toString silence.startsAt) UpdateStartsAt
|
||||
, formField "End" (ISO8601.toString silence.endsAt) UpdateEndsAt
|
||||
, div [ class "mt3" ]
|
||||
[ label [ class "f6 b db mb2" ]
|
||||
[ text "Matchers "
|
||||
|
@ -3,7 +3,8 @@ module Types exposing (..)
|
||||
-- External Imports
|
||||
|
||||
import Http exposing (Error)
|
||||
import Date exposing (Date)
|
||||
import Time
|
||||
import ISO8601
|
||||
|
||||
|
||||
-- Internal Imports
|
||||
@ -22,9 +23,9 @@ type alias Silence =
|
||||
{ id : Int
|
||||
, createdBy : String
|
||||
, comment : String
|
||||
, startsAt : String
|
||||
, endsAt : String
|
||||
, createdAt : String
|
||||
, startsAt : ISO8601.Time
|
||||
, endsAt : ISO8601.Time
|
||||
, createdAt : ISO8601.Time
|
||||
, matchers : List Matcher
|
||||
}
|
||||
|
||||
@ -41,7 +42,7 @@ type alias Alert =
|
||||
, inhibited : Bool
|
||||
, silenceId : Maybe Int
|
||||
, silenced : Bool
|
||||
, startsAt : Date
|
||||
, startsAt : ISO8601.Time
|
||||
, generatorUrl : String
|
||||
}
|
||||
|
||||
@ -82,6 +83,9 @@ type Msg
|
||||
| UpdateStartsAt String
|
||||
| UpdateCreatedBy String
|
||||
| UpdateComment String
|
||||
| SilenceFromAlert (List Matcher)
|
||||
| Noop (List Matcher)
|
||||
| NewDefaultTimeRange Time.Time
|
||||
|
||||
|
||||
type Route
|
||||
|
@ -1,55 +1,37 @@
|
||||
module Utils.Date exposing (..)
|
||||
|
||||
import Date exposing (Month(..))
|
||||
import Date exposing (Date, Month(..))
|
||||
import Time
|
||||
import ISO8601
|
||||
|
||||
|
||||
dateFormat : Date.Date -> String
|
||||
dateFormat date =
|
||||
dateFormat : ISO8601.Time -> String
|
||||
dateFormat t =
|
||||
String.join "/" <| List.map toString [ ISO8601.month t, ISO8601.day t, ISO8601.year t ]
|
||||
|
||||
|
||||
unixEpochStart : ISO8601.Time
|
||||
unixEpochStart =
|
||||
ISO8601.fromTime 0
|
||||
|
||||
|
||||
addTime : Time.Time -> Time.Time -> ISO8601.Time
|
||||
addTime isoTime add =
|
||||
let
|
||||
time =
|
||||
String.join ":" <| List.map toString [ Date.hour date, Date.minute date, Date.second date ]
|
||||
ms =
|
||||
(Time.inMilliseconds isoTime) + (Time.inMilliseconds add)
|
||||
|
||||
d =
|
||||
String.join "/" <| List.map toString [ dateToInt <| Date.month date, Date.day date, Date.year date ]
|
||||
t =
|
||||
round ms
|
||||
in
|
||||
d
|
||||
ISO8601.fromTime t
|
||||
|
||||
|
||||
dateToInt : Date.Month -> Int
|
||||
dateToInt month =
|
||||
case month of
|
||||
Jan ->
|
||||
1
|
||||
parseWithDefault : ISO8601.Time -> String -> ISO8601.Time
|
||||
parseWithDefault default toParse =
|
||||
Result.withDefault default (ISO8601.fromString toParse)
|
||||
|
||||
Feb ->
|
||||
2
|
||||
|
||||
Mar ->
|
||||
3
|
||||
|
||||
Apr ->
|
||||
4
|
||||
|
||||
May ->
|
||||
5
|
||||
|
||||
Jun ->
|
||||
6
|
||||
|
||||
Jul ->
|
||||
7
|
||||
|
||||
Aug ->
|
||||
8
|
||||
|
||||
Sep ->
|
||||
9
|
||||
|
||||
Oct ->
|
||||
10
|
||||
|
||||
Nov ->
|
||||
11
|
||||
|
||||
Dec ->
|
||||
12
|
||||
toISO8601 : Time.Time -> ISO8601.Time
|
||||
toISO8601 time =
|
||||
ISO8601.fromTime <| round (Time.inMilliseconds time)
|
||||
|
@ -54,14 +54,14 @@ alertGroupsView alertGroup =
|
||||
]
|
||||
|
||||
|
||||
blockView : Block -> Html msg
|
||||
blockView : Block -> Html Msg
|
||||
blockView block =
|
||||
-- Block level
|
||||
div []
|
||||
(List.map alertView block.alerts)
|
||||
|
||||
|
||||
alertView : Alert -> Html msg
|
||||
alertView : Alert -> Html Msg
|
||||
alertView alert =
|
||||
let
|
||||
id =
|
||||
@ -74,23 +74,24 @@ alertView alert =
|
||||
|
||||
b =
|
||||
if alert.silenced then
|
||||
buttonLink "fa-deaf" ("#/silences/" ++ toString id) "dark-blue"
|
||||
buttonLink "fa-deaf" ("#/silences/" ++ toString id) "dark-blue" (Noop [])
|
||||
else
|
||||
buttonLink "fa-exclamation-triangle" "#/silences/new" "dark-red"
|
||||
buttonLink "fa-exclamation-triangle" "#/silences/new" "dark-red" <|
|
||||
(SilenceFromAlert (List.map (\( k, v ) -> Matcher k v False) alert.labels))
|
||||
in
|
||||
div [ class "f6 mb3" ]
|
||||
[ div [ class "mb1" ]
|
||||
[ b
|
||||
, buttonLink "fa-bar-chart" alert.generatorUrl "black"
|
||||
, buttonLink "fa-bar-chart" alert.generatorUrl "black" (Noop [])
|
||||
, p [ class "dib mr2" ] [ text <| Utils.Date.dateFormat alert.startsAt ]
|
||||
]
|
||||
, div [ class "mb2 w-80-l w-100-m" ] (List.map labelButton <| List.filter (\( k, v ) -> k /= "alertname") alert.labels)
|
||||
]
|
||||
|
||||
|
||||
buttonLink : String -> String -> String -> Html msg
|
||||
buttonLink icon link color =
|
||||
a [ class <| "f6 link br1 ba mr1 ph3 pv2 mb2 dib " ++ color, href link ]
|
||||
buttonLink : String -> String -> String -> msg -> Html msg
|
||||
buttonLink icon link color msg =
|
||||
a [ class <| "f6 link br1 ba mr1 ph3 pv2 mb2 dib " ++ color, href link, onClick msg ]
|
||||
[ i [ class <| "fa fa-3 " ++ icon ] []
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user