diff --git a/cmd/zdravko/main.go b/cmd/zdravko/main.go index e29491d..9bd8ee0 100644 --- a/cmd/zdravko/main.go +++ b/cmd/zdravko/main.go @@ -2,7 +2,7 @@ package main import ( "flag" - "log" + "log/slog" "os" "os/signal" "sync" @@ -20,7 +20,19 @@ type StartableAndStoppable interface { Stop() error } +func setupLogger() { + opts := &slog.HandlerOptions{ + Level: slog.LevelDebug, + } + + logger := slog.New(slog.NewTextHandler(os.Stdout, opts)) + + slog.SetDefault(logger) +} + func main() { + setupLogger() + var startServer bool var startWorker bool var startTemporal bool @@ -28,47 +40,47 @@ func main() { flag.BoolVar(&startServer, "server", false, "Start the server") flag.BoolVar(&startWorker, "worker", false, "Start the worker") flag.BoolVar(&startTemporal, "temporal", false, "Start the temporal") - flag.Parse() - println("Starting zdravko...") - println("Server: ", startServer) - println("Worker: ", startWorker) - println("Temporal: ", startTemporal) + slog.Info("Starting zdravko...", "server", startServer, "worker", startWorker, "temporal", startTemporal) if !startServer && !startWorker && !startTemporal { - log.Fatal("At least one of the following must be set: --server, --worker, --temporal") + slog.Error("At least one of the following must be set: --server, --worker, --temporal") + os.Exit(1) } var servers [3]StartableAndStoppable var wg sync.WaitGroup if startTemporal { - log.Println("Setting up Temporal") + slog.Info("Setting up Temporal") cfg := config.NewTemporalConfig() temporal, err := temporal.NewTemporal(cfg) if err != nil { - log.Fatalf("Unable to create temporal: %v", err) + slog.Error("Unable to create temporal", "error", err) + os.Exit(1) } servers[0] = temporal } if startServer { - log.Println("Setting up Server") + slog.Info("Setting up Server") cfg := config.NewServerConfig() server, err := server.NewServer(cfg) if err != nil { - log.Fatalf("Unable to create server: %v", err) + slog.Error("Unable to create server", "error", err) + os.Exit(1) } servers[1] = server } if startWorker { - log.Println("Setting up Worker") + slog.Info("Setting up Worker") cfg := config.NewWorkerConfig() worker, err := worker.NewWorker(cfg) if err != nil { - log.Fatalf("Unable to create worker: %v", err) + slog.Error("Unable to create worker", "error", err) + os.Exit(1) } servers[2] = worker } @@ -79,13 +91,14 @@ func main() { continue } - println("Starting", srv.Name()) + slog.Info("Starting", "name", srv.Name()) wg.Add(1) go func() { defer wg.Done() err := srv.Start() if err != nil { - log.Fatalf("Unable to start %s: %v", srv.Name(), err) + slog.Error("Unable to start", "name", srv.Name(), "error", err) + os.Exit(1) } }() } @@ -94,16 +107,16 @@ func main() { signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) go func() { for sig := range c { - log.Printf("Received signal: %v", sig) + slog.Info("Received signal", "signal", sig) for _, srv := range servers { if srv == nil { continue } - println("Stopping", srv.Name()) + slog.Info("Stopping", "name", srv.Name()) err := srv.Stop() if err != nil { - log.Printf("Unable to stop server %s: %v", srv.Name(), err) + slog.Error("Unable to stop server", "name", srv.Name(), "error", err) } } } diff --git a/pkg/server/server.go b/pkg/server/server.go index 2753483..b516de7 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -25,7 +25,7 @@ func NewServer(cfg *config.ServerConfig) (*Server, error) { return &Server{ cfg: cfg, echo: echo.New(), - logger: slog.Default().WithGroup("server"), + logger: slog.Default(), }, nil } @@ -51,7 +51,12 @@ func (s *Server) Start() error { s.worker = NewWorker(temporalClient, s.cfg, s.logger, sqliteDb, kvStore) - s.echo.Renderer = templates.NewTemplates() + templates, err := templates.NewTemplates(s.logger) + if err != nil { + return errors.Wrap(err, "failed to create templates") + } + s.echo.Renderer = templates + s.echo.Use(middleware.Logger()) s.echo.Use(middleware.Recover()) s.echo.Use(middleware.Secure()) diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index fc669bb..7fd9332 100644 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -66,7 +66,7 @@ type Worker struct { func NewWorker(cfg *config.WorkerConfig) (*Worker, error) { return &Worker{ cfg: cfg, - logger: slog.Default().WithGroup("worker"), + logger: slog.Default(), }, nil } diff --git a/web/static/css/main.css b/web/static/css/main.css index 55cc37e..cc0fdd2 100644 --- a/web/static/css/main.css +++ b/web/static/css/main.css @@ -82,18 +82,18 @@ code { background: repeating-linear-gradient( 0deg, var(--color-orange-300), - var(--color-orange-300) 10%, - var(--color-orange-400) 10%, - var(--color-orange-400) 20% + var(--color-orange-300) 33%, + var(--color-orange-400) 33%, + var(--color-orange-400) 66% ); } #page-index .history.degraded:hover > .bar { background: repeating-linear-gradient( 0deg, var(--color-orange-400), - var(--color-orange-400) 10%, - var(--color-orange-500) 10%, - var(--color-orange-500) 20% + var(--color-orange-400) 33%, + var(--color-orange-500) 33%, + var(--color-orange-500) 66% ); } diff --git a/web/static/css/tailwind.css b/web/static/css/tailwind.css index d73695c..f39f94b 100644 --- a/web/static/css/tailwind.css +++ b/web/static/css/tailwind.css @@ -1020,10 +1020,6 @@ video { height: min-content; } -.w-12 { - width: 3rem; -} - .w-20 { width: 5rem; } @@ -1386,16 +1382,16 @@ video { line-height: 1.5rem; } -.text-lg { - font-size: 1.125rem; - line-height: 1.75rem; -} - .text-sm { font-size: 0.875rem; line-height: 1.25rem; } +.text-xl { + font-size: 1.25rem; + line-height: 1.75rem; +} + .text-xs { font-size: 0.75rem; line-height: 1rem; @@ -1514,6 +1510,11 @@ video { color: rgb(107 33 168 / var(--tw-text-opacity)); } +.text-red-500 { + --tw-text-opacity: 1; + color: rgb(239 68 68 / var(--tw-text-opacity)); +} + .text-red-600 { --tw-text-opacity: 1; color: rgb(220 38 38 / var(--tw-text-opacity)); @@ -1743,9 +1744,9 @@ code { background: repeating-linear-gradient( 0deg, var(--color-orange-300), - var(--color-orange-300) 10%, - var(--color-orange-400) 10%, - var(--color-orange-400) 20% + var(--color-orange-300) 33%, + var(--color-orange-400) 33%, + var(--color-orange-400) 66% ); } @@ -1753,9 +1754,9 @@ code { background: repeating-linear-gradient( 0deg, var(--color-orange-400), - var(--color-orange-400) 10%, - var(--color-orange-500) 10%, - var(--color-orange-500) 20% + var(--color-orange-400) 33%, + var(--color-orange-500) 33%, + var(--color-orange-500) 66% ); } @@ -2133,8 +2134,8 @@ code { justify-content: center; } - .sm\:justify-evenly { - justify-content: space-evenly; + .sm\:justify-between { + justify-content: space-between; } .sm\:px-8 { diff --git a/web/templates/components/base.tmpl b/web/templates/components/base.tmpl index 89e888d..8671ad0 100644 --- a/web/templates/components/base.tmpl +++ b/web/templates/components/base.tmpl @@ -17,8 +17,12 @@ -
- zdravko.mnts.dev +
+ zdravko.mnts.dev - Profile Image
{{ template "main" . }}
diff --git a/web/templates/components/footer.tmpl b/web/templates/components/footer.tmpl new file mode 100644 index 0000000..e69de29 diff --git a/web/templates/components/head.tmpl b/web/templates/components/head.tmpl new file mode 100644 index 0000000..e69de29 diff --git a/web/templates/pages/index.tmpl b/web/templates/pages/index.tmpl index ee12d10..e28c086 100644 --- a/web/templates/pages/index.tmpl +++ b/web/templates/pages/index.tmpl @@ -1,4 +1,22 @@ {{ define "main" }} + {{ $outcomeText := "All services are online." }} + {{ $outcomeIcon := "check" }} + {{ $outcomeColor := "bg-green-300" }} + {{ if eq .Outcome "DOWN" }} + {{ $outcomeText = "Some services are down." }} + {{ $outcomeIcon = "alert-circle" }} + {{ $outcomeColor = "bg-red-300" }} + {{ else if eq .Outcome "DEGRADED" }} + {{ $outcomeText = "Some services are degraded." }} + {{ $outcomeIcon = "alert-triangle" }} + {{ $outcomeColor = "bg-orange-300" }} + {{ else }} + {{ $outcomeText = "We are unable to determine current status." }} + {{ $outcomeIcon = "help-circle" }} + {{ $outcomeColor = "bg-gray-300" }} + {{ end }} + +
{{ else }} - {{ if eq .Outcome "HEALTHY" }} -
- - - -

All services are online

-

- Last updated on - {{ Now.UTC.Format "Jan 02 at 15:04 MST" }} -

-
- {{ else if eq .Outcome "UNKNOWN" }} -
- - - -

- We are unable to determine current status -

-

- Last updated on - {{ Now.UTC.Format "Jan 02 at 15:04 MST" }} -

-
- {{ else if eq .Outcome "DOWN" }} -
- - - -

Some services are down

-

- Last updated on - {{ Now.UTC.Format "Jan 02 at 15:04 MST" }} -

-
- {{ else if eq .Outcome "DEGRADED" }} -
- - - -

Degraded services

-

- Last updated on - {{ Now.UTC.Format "Jan 02 at 15:04 MST" }} -

-
- {{ end }} +
+ + + +

+ {{ $outcomeText }} +

+

+ Last updated on + {{ Now.UTC.Format "Jan 02 at 15:04 MST" }} +

+
+