Skip to content

Commit

Permalink
fix: added operational banner
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywhitaker3 committed Apr 19, 2024
1 parent e687cf6 commit 2451808
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 22 deletions.
2 changes: 0 additions & 2 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ configuration:
ui:
# The title of the page
title: Status Page
# The header text to display
header: Status Page

imagePullSecrets: []
nameOverride: ""
Expand Down
6 changes: 1 addition & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type Service struct {
}

type UI struct {
PageTitle string `yaml:"title"`
HeaderText string `yaml:"header"`
PageTitle string `yaml:"title"`
}

type Config struct {
Expand Down Expand Up @@ -84,9 +83,6 @@ func setDefaults(conf *Config) {
if conf.UI.PageTitle == "" {
conf.UI.PageTitle = "PromPage"
}
if conf.UI.HeaderText == "" {
conf.UI.HeaderText = "Status Page"
}
}

func (c *Config) Validate() error {
Expand Down
54 changes: 48 additions & 6 deletions internal/http/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,32 @@ import (
"github.com/labstack/echo/v4"
)

var (
OutageNone = "None"
OutagePartial = "Partial"
OutageFull = "Full"
)

func NewStatusPageHandler(app *app.App, cache *ResultCache) echo.HandlerFunc {
tmpl := template.Must(template.ParseFS(views.Views, "index.html"))

return func(c echo.Context) error {
res, t := cache.Get()
age := time.Since(t)
op := operational(res)

data := struct {
Config config.Config
Results []collector.Result
Age time.Duration
Config config.Config
Results []collector.Result
Age time.Duration
Outage string
BannerClasses string
}{
Config: *app.Config,
Results: res,
Age: age.Round(time.Second),
Config: *app.Config,
Results: res,
Age: age.Round(time.Second),
Outage: op,
BannerClasses: bannerClasses(op),
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
Expand All @@ -39,3 +50,34 @@ func NewStatusPageHandler(app *app.App, cache *ResultCache) echo.HandlerFunc {
return c.HTML(http.StatusOK, buf.String())
}
}

func operational(res []collector.Result) string {
passing := 0
for _, r := range res {
if r.Status {
passing++
}
}

switch passing {
case 0:
return OutageFull
case len(res):
return OutageNone
default:
return OutagePartial
}
}

func bannerClasses(outage string) string {
switch outage {
case OutageNone:
return "bg-lime-600 text-white"
case OutageFull:
return "bg-red-500 text-white"
case OutagePartial:
fallthrough
default:
return "bg-orange-400"
}
}
23 changes: 15 additions & 8 deletions internal/resources/static/up.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion internal/resources/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<body class="mx-auto min-h-dvh w-full md:w-3/4 p-12 md:p-8 lg:p-6 lg:w-1/2 flex flex-col justify-between bg-neutral-50">
{{/* Main content */}}
<div class="mb-6">
<h1 class="text-center text-2xl text-avocado-600 mb-6">{{ .Config.UI.HeaderText }}</h1>
<div class="flex flex-col justify-center items-center py-6 mb-6 w-full rounded-md shadow-md text-xl {{ .BannerClasses }}">
{{- if eq .Outage "None" }}
All Systems Operational
{{- else }}
{{ .Outage }} Systems Outage
{{- end }}
</div>

<div class="flex flex-col items-center justify-center rounded-md shadow-md border">
{{- range .Results }}
Expand Down
6 changes: 6 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["internal/resources/views/*.html"],
safelist: [
'bg-lime-600',
'bg-red-500',
'bg-orange-400',
'text-white'
],
theme: {
extend: {
colors: {
Expand Down

0 comments on commit 2451808

Please sign in to comment.