Skip to content

Commit

Permalink
Refactor to use kotlin actors for back end
Browse files Browse the repository at this point in the history
- main purpose is the make the back end more responsive which was affecting the front end
- responsiveness was improved in 0.4.0 and 0.5.0 but reaping wasn't reliable after running for a long time
- remove some unused frontend code
- upgrade kotlin version to 1.3.61 (seems to get rid of issue where running in Intellij would fail every second time)
- use "experimental" kotlin coroutine actors, disable compiler warnings
- refactor all k8s operations into one class so it's easier to test and pass around to actors
- use "Manager" as main actor, all others are created and managed by it
- configure the "Namespace" actor  (one instance for each namespace) to ensure each namespace is updated every 5s
- remove some values from Status and NamespaceStatus that were not used in the UI and not required in the backend
- split unit tests into time related and k8s related
  • Loading branch information
sgdan committed Jan 12, 2020
1 parent e35dac3 commit dafe441
Show file tree
Hide file tree
Showing 17 changed files with 757 additions and 497 deletions.
11 changes: 8 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.50"
id "org.jetbrains.kotlin.kapt" version "1.3.50"
id "org.jetbrains.kotlin.plugin.allopen" version "1.3.50"
id "org.jetbrains.kotlin.jvm" version "1.3.61"
id "org.jetbrains.kotlin.kapt" version "1.3.61"
id "org.jetbrains.kotlin.plugin.allopen" version "1.3.61"
id "com.github.johnrengelman.shadow" version "5.1.0"
id "application"
}
Expand Down Expand Up @@ -36,6 +36,8 @@ dependencies {
runtimeOnly "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8"
runtimeOnly "ch.qos.logback:logback-classic:1.2.3"

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'

compile "io.github.microutils:kotlin-logging:1.7.6"
compile "io.fabric8:kubernetes-client:4.2.2"
testCompile "io.fabric8:kubernetes-server-mock:4.6.0"
Expand All @@ -60,6 +62,9 @@ compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
javaParameters = true
freeCompilerArgs += [
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi"]
}
}

Expand Down
99 changes: 42 additions & 57 deletions frontend/src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
module Main exposing (..)
module Main exposing (main)

import Browser
import Element exposing (..)
import Element
exposing
( Attr
, Attribute
, Color
, Element
, alignRight
, column
, el
, fill
, fillPortion
, height
, layout
, maximum
, none
, padding
, rgb255
, row
, shrink
, spacing
, table
, text
, width
)
import Element.Background as Background
import Element.Border as Border
import Element.Events as Events
import Element.Font as Font
import Element.Input as Input
import Html
import Http exposing (..)
import Http exposing (Error(..))
import Json.Decode as D
import Json.Encode as E
import Time exposing (..)
import Time



Expand Down Expand Up @@ -186,7 +209,7 @@ update msg model =
Err x ->
( { model | state = LoadFailed <| toString x }, Cmd.none )

GetUpdate newTime ->
GetUpdate _ ->
( model, loadState model.url )

Extend namespace ->
Expand All @@ -210,41 +233,31 @@ update msg model =


subscriptions : Model -> Sub Msg
subscriptions model =
subscriptions _ =
Time.every 5000 GetUpdate


nsRow : Namespace -> Element msg
nsRow ns =
row
[ spacing 20
, padding 20
]
[ text ns.name
, text "-"
, text "State"
, text (String.fromInt ns.memLimit)
, text (String.fromInt ns.memUsed)
, text "-"
]


blue : Color
blue =
rgb255 100 100 255


green : Color
green =
rgb255 75 255 75


red : Color
red =
rgb255 255 75 75


dark : Color
dark =
rgb255 20 20 20


grey : Color
grey =
rgb255 130 130 130

Expand All @@ -254,6 +267,7 @@ showNamespace ns =
el [ getColor ns, Font.alignLeft ] <| text ns.name


headerAttr : List (Attr decorative msg)
headerAttr =
[ Font.size 20, Font.color blue ]

Expand Down Expand Up @@ -295,7 +309,7 @@ nsTable status model =
}
, { header = none
, width = fillPortion 1
, view = \ns -> none
, view = \_ -> none
}
]
}
Expand Down Expand Up @@ -433,40 +447,6 @@ showLimit model ns =
text <| String.fromInt ns.memLimit


padAndMod : Int -> String
padAndMod val =
String.fromInt (modBy 60 val) |> String.padLeft 2 '0'


formatRemaining : Int -> String
formatRemaining millis =
let
m =
millis // 1000 // 60

h =
m // 60

hs =
if h > 0 then
String.fromInt h ++ "h "

else
""

ms =
if m > 0 && h > 0 then
padAndMod m ++ "m"

else if m > 0 then
String.fromInt m ++ "m"

else
""
in
hs ++ ms


getColor : Namespace -> Attribute msg
getColor ns =
if ns.hasDownQuota && ns.memUsed > 0 then
Expand Down Expand Up @@ -554,11 +534,16 @@ nsDecoder =
(D.maybe <| D.field "remaining" D.string)


decodeNamespaces : Maybe (List Namespace) -> D.Decoder (List Namespace)
decodeNamespaces ns =
D.succeed (Maybe.withDefault [] ns)


statusDecoder : D.Decoder Status
statusDecoder =
D.map2 Status
(D.field "clock" D.string)
(D.field "namespaces" (D.list nsDecoder))
(D.maybe (D.field "namespaces" <| D.list nsDecoder) |> D.andThen decodeNamespaces)


msgDecoder : String -> Result D.Error Status
Expand Down
78 changes: 0 additions & 78 deletions src/main/kotlin/org/sgdan/podreaper/Actions.kt

This file was deleted.

Loading

0 comments on commit dafe441

Please sign in to comment.