Skip to content

Commit

Permalink
Stn/status page ohne mesh (prometheus#920)
Browse files Browse the repository at this point in the history
* Render status page without mesh connection (prometheus#918)

A mesh connection was assumed, even though the
value that was being passed into the helper
function was a possibly-nil pointer. Add a check
for this, and return a nil value in that case. The
frontend finds this when decoding the json
payload, and displays the "not configured"
message.

* Update bindata
  • Loading branch information
stuartnelson3 authored and Corentin Chary committed Sep 14, 2017
1 parent dd290d5 commit 04715e1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
10 changes: 7 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) {
ConfigJSON *config.Config `json:"configJSON"`
VersionInfo map[string]string `json:"versionInfo"`
Uptime time.Time `json:"uptime"`
MeshStatus meshStatus `json:"meshStatus"`
MeshStatus *meshStatus `json:"meshStatus"`
}{
ConfigYAML: api.config.String(),
ConfigJSON: api.config,
Expand Down Expand Up @@ -214,9 +214,13 @@ type peerStatus struct {
UID uint64 `json:"uid"` // e.g. "14015114173033265000"
}

func getMeshStatus(api *API) meshStatus {
func getMeshStatus(api *API) *meshStatus {
if api.mrouter == nil {
return nil
}

status := mesh.NewStatus(api.mrouter)
strippedStatus := meshStatus{
strippedStatus := &meshStatus{
Name: status.Name,
NickName: status.NickName,
Peers: make([]peerStatus, len(status.Peers)),
Expand Down
4 changes: 2 additions & 2 deletions ui/app/src/Status/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Status.Api exposing (getStatus)
import Utils.Api exposing (send, get)
import Utils.Types exposing (ApiData)
import Status.Types exposing (StatusResponse, VersionInfo, MeshStatus, MeshPeer)
import Json.Decode exposing (Decoder, map2, string, field, at, list, int)
import Json.Decode exposing (Decoder, map2, string, field, at, list, int, maybe)


getStatus : String -> (ApiData StatusResponse -> msg) -> Cmd msg
Expand All @@ -29,7 +29,7 @@ decodeData =
(field "configYAML" string)
(field "uptime" string)
(field "versionInfo" decodeVersionInfo)
(field "meshStatus" decodeMeshStatus)
(field "meshStatus" (maybe decodeMeshStatus))


decodeVersionInfo : Decoder VersionInfo
Expand Down
2 changes: 1 addition & 1 deletion ui/app/src/Status/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type alias StatusResponse =
{ config : String
, uptime : String
, versionInfo : VersionInfo
, meshStatus : MeshStatus
, meshStatus : Maybe MeshStatus
}


Expand Down
44 changes: 27 additions & 17 deletions ui/app/src/Views/Status/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,34 @@ viewConfig config =
]


viewMeshStatus : MeshStatus -> Html Types.Msg
viewMeshStatus : Maybe MeshStatus -> Html Types.Msg
viewMeshStatus meshStatus =
span []
[ h2 [] [ text "Mesh Status" ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.name ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Nick Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.nickName ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Peers:" ]
, ul [ class "col-sm-10" ] <|
List.map viewMeshPeer meshStatus.peers
]
]
case meshStatus of
Just meshStatus ->
span []
[ h2 [] [ text "Mesh Status" ]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.name ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Nick Name:" ]
, div [ class "col-sm-10" ] [ text meshStatus.nickName ]
]
, div [ class "form-group row" ]
[ b [ class "col-sm-2" ] [ text "Peers:" ]
, ul [ class "col-sm-10" ] <|
List.map viewMeshPeer meshStatus.peers
]
]

Nothing ->
span []
[ h2 [] [ text "Mesh Status" ]
, div [ class "form-group row" ]
[ div [ class "col-sm-10" ] [ text "Mesh not configured" ]
]
]


viewMeshPeer : MeshPeer -> Html Types.Msg
Expand Down
4 changes: 2 additions & 2 deletions ui/bindata.go

Large diffs are not rendered by default.

0 comments on commit 04715e1

Please sign in to comment.