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

Fixes #26059: Create a new ‘About’ page for easy access to technical information #6102

48 changes: 48 additions & 0 deletions webapp/sources/rudder/rudder-web/src/main/elm/sources/About.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
port module About exposing (update)

import Browser
import Result
import Json.Decode exposing (Value)

import About.DataTypes exposing (..)
import About.Init exposing (init, subscriptions) -- fakeData
import About.View exposing (view)

--
-- Port for interacting with external JS
--

port errorNotification : String -> Cmd msg
port copy : String -> Cmd msg
port copyJson : Value -> Cmd msg

main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GetAboutInfo res ->
let
ui = model.ui
newModel = {model | ui = {ui | loading = False}}
in
case res of
Ok info ->
({newModel | info = Just info}, Cmd.none)
Err _ ->
(newModel, (errorNotification "Error while fetching information"))
-- ({ newModel | info = Just fakeData}, (errorNotification "Error while fetching information"))
Copy s ->
( model, copy s )

CopyJson value ->
(model, copyJson value)

UpdateUI newUI ->
({model | ui = newUI}, Cmd.none)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module About.ApiCalls exposing (..)

import Http exposing (emptyBody, expectJson, header, request)

import About.DataTypes exposing (..)
import About.JsonDecoder exposing (decodeGetAboutInfo)


getUrl: Model -> String -> String
getUrl m url =
m.contextPath ++ "/secure/api" ++ url

getAboutInfo : Model -> Cmd Msg
getAboutInfo model =
request
{ method = "GET"
, headers = [header "X-Requested-With" "XMLHttpRequest"]
, url = getUrl model "/plugins/about"
, body = emptyBody
, expect = expectJson GetAboutInfo decodeGetAboutInfo
, timeout = Nothing
, tracker = Nothing
}
--}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module About.DataTypes exposing (..)

import Http exposing (Error)
import Json.Encode exposing (Value)

type alias RudderInfo =
{ version : String
, build : String
, instanceId : String
, relays : List Relay
}

type alias Relay =
{ uuid : String
, hostname : String
, managedNodes : Int
}

type alias SystemInfo =
{ os : OperatingSystem
, jvm : JvmInfo
}

type alias OperatingSystem =
{ name : String
, version : String
}

type alias JvmInfo =
{ version : String
, cmd : String
}

type alias NodesInfo =
{ total : Int
, audit : Int
, enforce : Int
, enabled : Int
, disabled : Int
}

type alias PluginInfo =
{ id : String
, name : String
, version : String
, abiVersion : String
, license : LicenseInfo
}

type alias LicenseInfo =
{ licensee : String
, startDate : String
, endDate : String
, allowedNodesNumber : Int
, supportedVersions : String
}


type alias AboutInfo =
{ rudderInfo : RudderInfo
, system : SystemInfo
, nodes : NodesInfo
, plugins : List PluginInfo
}

type alias Model =
{ contextPath : String
, info : Maybe AboutInfo
, ui : UI
}

type alias UI =
{ loading : Bool
, showRelays : Bool
, showPlugins : Bool
}

type Msg
= GetAboutInfo (Result Error AboutInfo)
| Copy String
| CopyJson Value
| UpdateUI UI
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module About.Init exposing (..)

import About.DataTypes exposing (..)
import About.ApiCalls exposing (getAboutInfo)


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none

init : { contextPath : String } -> ( Model, Cmd Msg )
init flags =
let
initModel = Model flags.contextPath Nothing (UI True True True)
in
( initModel
, getAboutInfo initModel
)
{--
fakeData : AboutInfo
fakeData =
let
relaysList =
[ (Relay "0123-4567-8901-2345" "relay1" 96)
, (Relay "4567-8901-2345-6789" "relay2" 202)
, (Relay "8901-2345-6789-0123" "relay3" 29)
]

rudderInfo = RudderInfo "8.3.0" "build-1" "d40076ff-6a7d-4887-b1a9-6c99c4b25e29" relaysList

os = OperatingSystem "Ubuntu" "24.04"
jvm = JvmInfo "9.0" "lauchOptions -X -R --param1 --param2 --param3 --param4 --param5"
system = SystemInfo os jvm

nodes = NodesInfo 1000 600 400 900 100

license = LicenseInfo "Demo Normation" "01-01-2024" "01-01-2025" 9999 "8.3.0"
plugins =
[ PluginInfo "branding" "Branding" "2.0.0" "8.3.0" license
]
in
AboutInfo rudderInfo system nodes plugins
--}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module About.JsonDecoder exposing (..)

import Json.Decode as D exposing (Decoder, string, int, list, at)
import Json.Decode.Pipeline exposing (required)

import About.DataTypes exposing (..)


decodeGetAboutInfo : Decoder AboutInfo
decodeGetAboutInfo =
at [ "data" ] decodeAboutInfo

decodeAboutInfo : Decoder AboutInfo
decodeAboutInfo =
D.succeed AboutInfo
|> required "rudder" decodeRudderInfo
|> required "system" decodeSystemInfo
|> required "nodes" decodeNodesInfo
|> required "plugins" (list decodePluginInfo)

decodeRudderInfo : Decoder RudderInfo
decodeRudderInfo =
D.succeed RudderInfo
|> required "version" string
|> required "build" string
|> required "instanceId" string
|> required "relays" (list decodeRelay)

decodeRelay : Decoder Relay
decodeRelay =
D.succeed Relay
|> required "uuid" string
|> required "hostname" string
|> required "managedNodes" int

decodeSystemInfo : Decoder SystemInfo
decodeSystemInfo =
D.succeed SystemInfo
|> required "os" decodeOperatingSystem
|> required "jvm" decodeJvm

decodeOperatingSystem : Decoder OperatingSystem
decodeOperatingSystem =
D.succeed OperatingSystem
|> required "name" string
|> required "version" string

decodeJvm : Decoder JvmInfo
decodeJvm =
D.succeed JvmInfo
|> required "version" string
|> required "cmd" string

decodeNodesInfo : Decoder NodesInfo
decodeNodesInfo =
D.succeed NodesInfo
|> required "total" int
|> required "audit" int
|> required "enforce" int
|> required "enabled" int
|> required "disabled" int

decodePluginInfo : Decoder PluginInfo
decodePluginInfo =
D.succeed PluginInfo
|> required "id" string
|> required "name" string
|> required "version" string
|> required "abiVersion" string
|> required "license" decodeLicenseInfo

decodeLicenseInfo : Decoder LicenseInfo
decodeLicenseInfo =
D.succeed LicenseInfo
|> required "licensee" string
|> required "startDate" string
|> required "endDate" string
|> required "allowedNodesNumber" int
|> required "supportedVersions" string
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module About.JsonEncoder exposing (..)

import About.DataTypes exposing (..)
import Json.Encode exposing (..)

encodeRudderInfo : RudderInfo -> Value
encodeRudderInfo rudderInfo =
object
[ ( "version", string rudderInfo.version )
, ( "build", string rudderInfo.build )
, ( "instanceId", string rudderInfo.instanceId )
, ( "relays", (list encodeRelay) rudderInfo.relays )
]

encodeRelay : Relay -> Value
encodeRelay relay =
object
[ ( "uuid", string relay.uuid )
, ( "hostname", string relay.hostname )
, ( "managedNodes", int relay.managedNodes )
]

encodeSystemInfo : SystemInfo -> Value
encodeSystemInfo systemInfo =
object
[ ( "os", encodeOs systemInfo.os )
, ( "jvm", encodeJvm systemInfo.jvm )
]

encodeOs : OperatingSystem -> Value
encodeOs os =
object
[ ( "name", string os.name )
, ( "version", string os.version )
]
encodeJvm : JvmInfo -> Value
encodeJvm jvm =
object
[ ( "version", string jvm.version )
, ( "cmd", string jvm.cmd )
]

encodeNodesInfo : NodesInfo -> Value
encodeNodesInfo nodesInfo =
object
[ ( "total", int nodesInfo.total )
, ( "audit", int nodesInfo.audit )
, ( "enforce", int nodesInfo.enforce )
, ( "enabled", int nodesInfo.enabled )
, ( "disabled", int nodesInfo.disabled )
]

encodePluginInfo : PluginInfo -> Value
encodePluginInfo pluginInfo =
object
[ ( "id", string pluginInfo.id )
, ( "name", string pluginInfo.name )
, ( "version", string pluginInfo.version )
, ( "abiVersion", string pluginInfo.abiVersion )
, ( "license", encodeLicenseInfo pluginInfo.license )
]

encodeLicenseInfo : LicenseInfo -> Value
encodeLicenseInfo licenseInfo =
object
[ ( "licensee", string licenseInfo.licensee )
, ( "startDate", string licenseInfo.startDate )
, ( "endDate", string licenseInfo.endDate )
, ( "allowedNodesNumber", int licenseInfo.allowedNodesNumber )
, ( "supportedVersions", string licenseInfo.supportedVersions )
]

encodeAboutInfo : AboutInfo -> Value
encodeAboutInfo aboutInfo =
object
[ ( "rudder", encodeRudderInfo aboutInfo.rudderInfo )
, ( "system", encodeSystemInfo aboutInfo.system )
, ( "nodes", encodeNodesInfo aboutInfo.nodes )
, ( "plugins", (list encodePluginInfo) aboutInfo.plugins )
]
Loading