diff --git a/documentation/adrs/0016-use-slack-to-inform-user-about-important-system-events.md b/documentation/adrs/0016-use-slack-to-inform-user-about-important-system-events.md new file mode 100644 index 0000000..83022dc --- /dev/null +++ b/documentation/adrs/0016-use-slack-to-inform-user-about-important-system-events.md @@ -0,0 +1,22 @@ +# 16. use Slack to inform user about important system events + +Date: 2024-02-02 + +## Status + +Accepted + +## Context + +Requirement F-004 requires the owners of the system to be informed about important system events. + +## Decision + +Such important events are "system startup" and "acquisition of usage and repository data". +These shall be sent to a Slack channel to notify the owners. + +## Consequences + +- Slack app to be created +- [Slack API](https://pkg.go.dev/github.com/slack-go/slack@v0.12.3#section-readme) to be used +- Slack OAuth Token to be set at fly.io \ No newline at end of file diff --git a/documentation/arc42/chapters/01_introduction_and_goals.adoc b/documentation/arc42/chapters/01_introduction_and_goals.adoc index 8c42f7f..1aefea5 100644 --- a/documentation/arc42/chapters/01_introduction_and_goals.adoc +++ b/documentation/arc42/chapters/01_introduction_and_goals.adoc @@ -17,11 +17,22 @@ ifndef::imagesdir[:imagesdir: ../../images] === Requirements Overview +[glossary] +F-001:: publish current usage statistics of arc42 websites +F-002:: publish current repository statistics (like issues, bugs) of arc42 websites + +F-003:: store important results and events persistently for future reference + +F-004:: inform owners of important system events === Quality Goals -* Environmental friendly: Reduce computing resources used as much as possible. +[glossary] + +Q-001:: Environmental friendly: Reduce computing resources used as much as possible. + +Q-002:: Available: statics are available via the website 24x7. Short periods (hours) of downtime can be allowed, in such cases cached or dated results shall be displayed. === Stakeholders diff --git a/documentation/images/06-system-startup.puml b/documentation/images/06-system-startup.puml index 96ada4e..e10ba4e 100644 --- a/documentation/images/06-system-startup.puml +++ b/documentation/images/06-system-startup.puml @@ -2,36 +2,29 @@ 'https://plantuml.com/activity-diagram-beta start -:ClickServlet.handleRequest(); -:new page; -if (Page.onSecurityCheck) then (true) - :Page.onInit(); - if (isForward?) then (no) - :Process controls; - if (continue processing?) then (no) - stop - endif - - if (isPost?) then (yes) - :Page.onPost(); - else (no) - :Page.onGet(); - endif - :Page.onRender(); - endif -else (false) -endif -if (do redirect?) then (yes) - :redirect process; -else - if (do forward?) then (yes) - :Forward request; - else (no) - :Render page template; - endif -endif +:init logger, db, cache; + +:siteStats = loadStats(); + +:cache siteStats, expiry 10min; + +:repoStats = loadRepoStats(); +:cache repoStats, expiry 1min; -stop +group API Server Process +:apiGateway.StartAPIServer(); + +detach + +:wait for http request; + +if (External Event occurs) then (yes) + :execute method B; +else (no) + :skip method B; +endif +end group +:finalize process; @enduml diff --git a/documentation/images/slack-app/slack-status-gopher-logo.pptx b/documentation/images/slack-app/slack-status-gopher-logo.pptx new file mode 100644 index 0000000..d8a3c9d Binary files /dev/null and b/documentation/images/slack-app/slack-status-gopher-logo.pptx differ diff --git a/documentation/images/slack-app/slack-status-gopher.png b/documentation/images/slack-app/slack-status-gopher.png new file mode 100644 index 0000000..189eb1d Binary files /dev/null and b/documentation/images/slack-app/slack-status-gopher.png differ diff --git a/go-app/internal/api/apiGateway.go b/go-app/internal/api/apiGateway.go index b5182b9..5339508 100644 --- a/go-app/internal/api/apiGateway.go +++ b/go-app/internal/api/apiGateway.go @@ -70,13 +70,12 @@ func statsHTMLTableHandler(w http.ResponseWriter, r *http.Request) { domain.ArcStats.FlyRegion, domain.ArcStats.WhereDoesItRun = fly.RegionAndLocation() // 4. store request params in database - // TODO: make this async // TODO: include real IP address - database.SaveInvocationParams(r.Host, r.RequestURI) + go database.SaveInvocationParams(r.Host, r.RequestURI) - // 4b: inform owner via Slack + // 4b: inform the owner via Slack msg := fmt.Sprintf("Loaded arc42 statistics in %sms on %s", domain.ArcStats.HowLongDidItTake, time.Now().Format("02 Jan 15:04")) - slack.SendSlackMessage(msg) + go slack.SendSlackMessage(msg) // 5. finally, render the template executeTemplate(w, filepath.Join(TemplatesDir, HtmlTableTmpl), domain.ArcStats) diff --git a/go-app/main.go b/go-app/main.go index a95cefb..c9e6ae4 100644 --- a/go-app/main.go +++ b/go-app/main.go @@ -13,7 +13,7 @@ import ( "time" ) -const appVersion = "0.5.6" +const appVersion = "0.5.7" // version history // 0.5.x rate limit: limit amount of queries to external APIs @@ -22,6 +22,7 @@ const appVersion = "0.5.6" // 0.5.4: start with empty table on homepage // 0.5.5: caching with zcache // 0.5.6: send slack message for important system events, starting with data acquisition +// 0.5.7: performance optimization, initial database insert and Slack message now async // 0.4.7 replace most inline styles by css // 0.4.6 sortable table (a: initial, b...e: fix layout issues), f: fix #94 // 0.4.5 fix missing separators in large numbers