From 6f794a1623e8edd5aabd2a235e1f9269e7f60252 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 26 Jun 2023 19:46:33 +0200 Subject: [PATCH 1/7] feat(details): join with container_status Signed-off-by: vringar --- Explorer/src/components/container_detail_page.tsx | 6 +++--- Explorer/src/lib/db.ts | 6 +++--- Explorer/src/lib/types/Container.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Explorer/src/components/container_detail_page.tsx b/Explorer/src/components/container_detail_page.tsx index ecb04c7..16f84d5 100644 --- a/Explorer/src/components/container_detail_page.tsx +++ b/Explorer/src/components/container_detail_page.tsx @@ -3,12 +3,12 @@ import { Table } from "flowbite-react"; import { H1 } from "@/components/style_elements"; import { HealthIndicatorBadge } from "@/components/health_indicators"; -import { Container } from "@/lib/types/Container"; +import { ContainerDetails } from "@/lib/types/Container"; export default function ContainerDetailPage({ container_details, }: { - container_details: Container; + container_details: ContainerDetails; }): JSX.Element { return (
@@ -140,7 +140,7 @@ function _ContainerChangelogWidget({ function ContainerDetailsWidget({ container_data, }: { - container_data: Container; + container_data: ContainerDetails; }): JSX.Element { return (
diff --git a/Explorer/src/lib/db.ts b/Explorer/src/lib/db.ts index 9ec444e..719e0ff 100644 --- a/Explorer/src/lib/db.ts +++ b/Explorer/src/lib/db.ts @@ -1,5 +1,5 @@ import "server-only"; -import { Container, ContainerList } from "./types/Container"; +import { ContainerDetails, ContainerList } from "./types/Container"; import { Pool } from "pg"; const pool = new Pool({ @@ -12,10 +12,10 @@ const pool = new Pool({ export async function getContainerDetails( container_id: string -): Promise { +): Promise { return ( await pool.query( - "SELECT * FROM containers c WHERE container_id = $1 order by timestamp DESC limit 1", + "SELECT * FROM containers c LEFT JOIN container_states cs ON cs.id = c.state_id WHERE c.container_id = $1 order by timestamp DESC limit 1", [container_id] ) ).rows[0]; diff --git a/Explorer/src/lib/types/Container.ts b/Explorer/src/lib/types/Container.ts index 4044bf1..4855026 100644 --- a/Explorer/src/lib/types/Container.ts +++ b/Explorer/src/lib/types/Container.ts @@ -1,4 +1,14 @@ import { Status } from "./Status"; +type ContainerStates = + | { kind: "running"; started_at: Date } + | { + kind: "terminated"; + container_id: number; + exit_code: number; + finished_at: Date; + signal: number; + } + | { kind: "waiting"; message: string; reason: string }; export type Container = { id: number; @@ -16,4 +26,5 @@ export type Container = { state_id: number; last_state_id: number; }; +export type ContainerDetails = Container & ContainerStates; export type ContainerList = Container[]; From 981c1d73a85945592c3bff03cdc0882126448051 Mon Sep 17 00:00:00 2001 From: vringar Date: Sun, 9 Jul 2023 17:21:09 +0200 Subject: [PATCH 2/7] WIP --- .../src/components/container_detail_page.tsx | 14 ++++++---- Explorer/src/lib/db.ts | 28 +++++++++++++++++-- Explorer/src/lib/types/Container.ts | 8 +++--- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Explorer/src/components/container_detail_page.tsx b/Explorer/src/components/container_detail_page.tsx index 16f84d5..9a66efc 100644 --- a/Explorer/src/components/container_detail_page.tsx +++ b/Explorer/src/components/container_detail_page.tsx @@ -3,22 +3,24 @@ import { Table } from "flowbite-react"; import { H1 } from "@/components/style_elements"; import { HealthIndicatorBadge } from "@/components/health_indicators"; -import { ContainerDetails } from "@/lib/types/Container"; +import { Container, ContainerDetails } from "@/lib/types/Container"; +import { ReactNode } from "react"; export default function ContainerDetailPage({ container_details, }: { container_details: ContainerDetails; }): JSX.Element { + const container = container_details.container; return (
-

- +

+

- +
{/*
@@ -140,7 +142,7 @@ function _ContainerChangelogWidget({ function ContainerDetailsWidget({ container_data, }: { - container_data: ContainerDetails; + container_data: Container; }): JSX.Element { return (
@@ -158,7 +160,7 @@ function ContainerDetailsWidget({ {Object.entries(container_data).map(([name, value], index) => { if (value instanceof Date) { value = value.toUTCString(); - } else if (typeof value === "boolean") { + } else if (value instanceof Boolean) { value = value ? "true" : "false"; } return ( diff --git a/Explorer/src/lib/db.ts b/Explorer/src/lib/db.ts index 719e0ff..d07e879 100644 --- a/Explorer/src/lib/db.ts +++ b/Explorer/src/lib/db.ts @@ -1,5 +1,5 @@ import "server-only"; -import { ContainerDetails, ContainerList } from "./types/Container"; +import { ContainerDetails, Container, ContainerList } from "./types/Container"; import { Pool } from "pg"; const pool = new Pool({ @@ -13,12 +13,34 @@ const pool = new Pool({ export async function getContainerDetails( container_id: string ): Promise { - return ( + const res1 = ( await pool.query( - "SELECT * FROM containers c LEFT JOIN container_states cs ON cs.id = c.state_id WHERE c.container_id = $1 order by timestamp DESC limit 1", + "SELECT * FROM containers c WHERE c.container_id = $1 order by timestamp DESC limit 1", [container_id] ) ).rows[0]; + if (!res1) { + // No container found + return undefined; + } + const container: Container = { + id: res1.id, + timestamp: res1.timestamp, + container_id: res1.container_id, + pod_id: res1.container_id, + name: res1.name, + image: res1.image, + status: res1.status, + // ports: 0, + image_id: res1.image_id, + ready: res1.ready, + restart_count: res1.restart_count, + started: res1.started, + // state_id: 0, + // last_state_id: 0, + }; + + return { container, status: {} }; } export async function getContainerList(): Promise { diff --git a/Explorer/src/lib/types/Container.ts b/Explorer/src/lib/types/Container.ts index 4855026..cdfc161 100644 --- a/Explorer/src/lib/types/Container.ts +++ b/Explorer/src/lib/types/Container.ts @@ -18,13 +18,13 @@ export type Container = { name: string; image: string; status: Status; - ports: number; image_id: string; ready: boolean; restart_count: number; started: boolean; - state_id: number; - last_state_id: number; }; -export type ContainerDetails = Container & ContainerStates; +export type ContainerDetails = { + container: Container; + status: ContainerStates; +}; export type ContainerList = Container[]; From ed11f80583990bdf26fc09bfdedc9042cfa162f0 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 17 Jul 2023 19:22:32 +0200 Subject: [PATCH 3/7] fix(darkmode): make headings work in darkmode Signed-off-by: vringar --- Explorer/src/components/container_detail_page.tsx | 6 +++--- Explorer/src/components/pod_detail_page.tsx | 6 +++--- Explorer/src/components/style_elements.tsx | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Explorer/src/components/container_detail_page.tsx b/Explorer/src/components/container_detail_page.tsx index 49a1906..8854e2f 100644 --- a/Explorer/src/components/container_detail_page.tsx +++ b/Explorer/src/components/container_detail_page.tsx @@ -1,7 +1,7 @@ "use client"; import { Table } from "flowbite-react"; -import { H1 } from "@/components/style_elements"; +import { H1, H2 } from "@/components/style_elements"; import { HealthIndicatorBadge } from "@/components/health_indicators"; import { Container } from "@/lib/types/Container"; import Link from "next/link"; @@ -88,7 +88,7 @@ function _ContainerChangelogWidget({
-

Changelog

+

@@ -145,7 +145,7 @@ function ContainerDetailsWidget({ }): JSX.Element { return (
-

Details

+

diff --git a/Explorer/src/components/pod_detail_page.tsx b/Explorer/src/components/pod_detail_page.tsx index 47cc44e..0cff16a 100644 --- a/Explorer/src/components/pod_detail_page.tsx +++ b/Explorer/src/components/pod_detail_page.tsx @@ -1,7 +1,7 @@ "use client"; import Link from "next/link"; import { Table } from "flowbite-react"; -import { H1 } from "@/components/style_elements"; +import { H1, H2 } from "@/components/style_elements"; import { HealthIndicatorBadge } from "@/components/health_indicators"; import { Pod } from "@/lib/types/Pod"; import { Container, ContainerList } from "@/lib/types/Container"; @@ -36,7 +36,7 @@ export default function PodDetailPage({ function PodDetailsWidget({ pod_data }: { pod_data: Pod }): JSX.Element { return (
-

Details

+

@@ -80,7 +80,7 @@ function ChildContainerWidget({ }): JSX.Element { return (
-

Child Containers

+

+

{content} -

+ ); } From 3e309720be1d97c87425c8b8276029a97d23b082 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 17 Jul 2023 21:24:37 +0200 Subject: [PATCH 4/7] feat(container): show container state Signed-off-by: vringar --- DB/kubernetes-schema.sql | 4 ++-- Explorer/src/components/container_detail_page.tsx | 4 ++++ Explorer/src/lib/db.ts | 8 +++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DB/kubernetes-schema.sql b/DB/kubernetes-schema.sql index 9091a7e..2869052 100644 --- a/DB/kubernetes-schema.sql +++ b/DB/kubernetes-schema.sql @@ -85,10 +85,10 @@ CREATE TABLE nodes( CREATE TABLE "container_states"( "id" int GENERATED ALWAYS AS IDENTITY PRIMARY KEY, "kind" text, - "started_at" time, + "started_at" timestamp, "container_id" text, "exit_code" int, - "finished_at" time, + "finished_at" timestamp, "message" text, "reason" text, "signal" int diff --git a/Explorer/src/components/container_detail_page.tsx b/Explorer/src/components/container_detail_page.tsx index 0127d7e..eb5aec8 100644 --- a/Explorer/src/components/container_detail_page.tsx +++ b/Explorer/src/components/container_detail_page.tsx @@ -205,6 +205,9 @@ function computeValue( ); } + case "ready": + case "started": + return container_data[key] ? "true" : "false"; default: return container_data[key]; } @@ -218,6 +221,7 @@ function ContainerStatesWidget({ if (state === undefined) { return
; } + console.log(state); let elem: JSX.Element; switch (state.kind) { case "running": diff --git a/Explorer/src/lib/db.ts b/Explorer/src/lib/db.ts index 7b77752..eb40c4e 100644 --- a/Explorer/src/lib/db.ts +++ b/Explorer/src/lib/db.ts @@ -29,12 +29,12 @@ export async function getContainerDetails( return undefined; } const last_fail_state = await getContainerState(container_row.last_state_id); - + console.log(container_row); const container: Container = { id: container_row.id, timestamp: container_row.timestamp, container_id: container_row.container_id, - pod_id: container_row.container_id, + pod_id: container_row.pod_id, name: container_row.name, image: container_row.image, status: container_row.status, @@ -55,13 +55,15 @@ async function getContainerState( state_id: number ): Promise { const row = ( - await pool.query("SELECT * FROM container_states cs WHERE c.id = $1", [ + await pool.query("SELECT * FROM container_states cs WHERE cs.id = $1", [ state_id, ]) ).rows[0]; if (!row) { return undefined; } + console.log(row); + switch (row.kind) { case "Waiting": return { kind: "waiting", message: row.message, reason: row.reason }; From 648a4bdc443c598146dfc5c1736b6cc835c27216 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 17 Jul 2023 21:29:33 +0200 Subject: [PATCH 5/7] fix(model): change model to timestamp as well Signed-off-by: vringar --- Proxy/internal/database/model/model.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Proxy/internal/database/model/model.go b/Proxy/internal/database/model/model.go index 6bc7613..ee749cd 100644 --- a/Proxy/internal/database/model/model.go +++ b/Proxy/internal/database/model/model.go @@ -103,10 +103,10 @@ type Container struct { type ContainerState struct { ID int `bun:"id,autoincrement,pk"` Kind string `bun:"kind,type:text"` - StartedAt time.Time `bun:"started_at,type:time"` + StartedAt time.Time `bun:"started_at,type:timestamp"` ContainerID string `bun:"container_id,type:text"` ExitCode int `bun:"exit_code,type:int"` - FinishedAt time.Time `bun:"finished_at,type:time"` + FinishedAt time.Time `bun:"finished_at,type:timestamp"` Message string `bun:"message,type:text"` Reason string `bun:"reason,type:text"` Signal int `bun:"signal,type:int"` From d7257acf3715bac0d526f68ea083b33bbf0ec018 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 17 Jul 2023 21:35:18 +0200 Subject: [PATCH 6/7] fix(tests): update jest test Signed-off-by: vringar --- Explorer/src/app/containers/[id]/page.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Explorer/src/app/containers/[id]/page.test.js b/Explorer/src/app/containers/[id]/page.test.js index 1725cec..be7911a 100644 --- a/Explorer/src/app/containers/[id]/page.test.js +++ b/Explorer/src/app/containers/[id]/page.test.js @@ -11,7 +11,7 @@ jest.mock("../../../lib/db", () => ({ return Promise.resolve({ container_event_id: 1, container_id: 1, - timestamp: "2021-08-01 00:00:00", + timestamp: new Date("2021-08-01 00:00:00"), pod_id: 1, name: "Container 1", image: "Image 1", From 0aae1efc7e3c00a7b6a22a757d5a4e1e252ed6c9 Mon Sep 17 00:00:00 2001 From: vringar Date: Mon, 17 Jul 2023 21:38:00 +0200 Subject: [PATCH 7/7] fix(Explorer): remove console.log Signed-off-by: vringar --- Explorer/src/components/container_detail_page.tsx | 1 - Explorer/src/lib/db.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/Explorer/src/components/container_detail_page.tsx b/Explorer/src/components/container_detail_page.tsx index eb5aec8..fac62a7 100644 --- a/Explorer/src/components/container_detail_page.tsx +++ b/Explorer/src/components/container_detail_page.tsx @@ -221,7 +221,6 @@ function ContainerStatesWidget({ if (state === undefined) { return
; } - console.log(state); let elem: JSX.Element; switch (state.kind) { case "running": diff --git a/Explorer/src/lib/db.ts b/Explorer/src/lib/db.ts index eb40c4e..7da1bbb 100644 --- a/Explorer/src/lib/db.ts +++ b/Explorer/src/lib/db.ts @@ -29,7 +29,6 @@ export async function getContainerDetails( return undefined; } const last_fail_state = await getContainerState(container_row.last_state_id); - console.log(container_row); const container: Container = { id: container_row.id, timestamp: container_row.timestamp, @@ -62,7 +61,6 @@ async function getContainerState( if (!row) { return undefined; } - console.log(row); switch (row.kind) { case "Waiting":