From 95b4143a85d60aadc30f0667b5ceb9c709b37140 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Tue, 1 Nov 2022 16:52:02 -0400 Subject: [PATCH] communicate time as epoch ms; better disable of durations in ui (#33) --- controller/overview.go | 10 ++++++---- controller/store/sql/postgresql/000_base.sql | 16 ++++++++-------- rest_model_zrok/environment.go | 4 ++-- rest_model_zrok/service.go | 4 ++-- rest_server_zrok/embedded_spec.go | 16 ++++++++-------- specs/zrok.yml | 8 ++++---- ui/package-lock.json | 11 +++++++++++ ui/package.json | 1 + ui/src/Environments.js | 8 ++++++-- ui/src/api/types.js | 8 ++++---- 10 files changed, 52 insertions(+), 34 deletions(-) diff --git a/controller/overview.go b/controller/overview.go index 93b46057..2dfa1cd2 100644 --- a/controller/overview.go +++ b/controller/overview.go @@ -8,6 +8,7 @@ import ( "github.com/openziti-test-kitchen/zrok/rest_model_zrok" "github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata" "github.com/sirupsen/logrus" + "time" ) func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Principal) middleware.Responder { @@ -29,13 +30,14 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ logrus.Errorf("error finding services for environment '%v': %v", env.ZId, err) return metadata.NewOverviewInternalServerError() } + logrus.Infof("updatedAt: %v", time.Since(env.UpdatedAt.UTC())) es := &rest_model_zrok.EnvironmentServices{ Environment: &rest_model_zrok.Environment{ Address: env.Address, - CreatedAt: env.CreatedAt.String(), + CreatedAt: env.CreatedAt.UnixMilli(), Description: env.Description, Host: env.Host, - UpdatedAt: env.UpdatedAt.String(), + UpdatedAt: env.UpdatedAt.UnixMilli(), ZID: env.ZId, }, } @@ -46,10 +48,10 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ } for _, svc := range svcs { es.Services = append(es.Services, &rest_model_zrok.Service{ - CreatedAt: svc.CreatedAt.String(), + CreatedAt: svc.CreatedAt.UnixMilli(), Frontend: svc.Frontend, Backend: svc.Backend, - UpdatedAt: svc.UpdatedAt.String(), + UpdatedAt: svc.UpdatedAt.UnixMilli(), ZID: svc.ZId, Name: svc.Name, Metrics: sparkData[svc.Name], diff --git a/controller/store/sql/postgresql/000_base.sql b/controller/store/sql/postgresql/000_base.sql index 39b3cfcd..db481ec5 100644 --- a/controller/store/sql/postgresql/000_base.sql +++ b/controller/store/sql/postgresql/000_base.sql @@ -8,8 +8,8 @@ create table accounts ( email varchar(1024) not null unique, password char(128) not null, token varchar(32) not null unique, - created_at timestamp not null default(current_timestamp), - updated_at timestamp not null default(current_timestamp), + created_at timestamptz not null default(current_timestamp), + updated_at timestamptz not null default(current_timestamp), constraint chk_email check (email <> ''), constraint chk_password check (password <> ''), @@ -24,8 +24,8 @@ create table account_requests ( token varchar(32) not null unique, email varchar(1024) not null unique, source_address varchar(64) not null, - created_at timestamp not null default(current_timestamp), - updated_at timestamp not null default(current_timestamp) + created_at timestamptz not null default(current_timestamp), + updated_at timestamptz not null default(current_timestamp) ); -- @@ -38,8 +38,8 @@ create table environments ( host varchar(256), address varchar(64), z_id varchar(32) not null unique, - created_at timestamp not null default(current_timestamp), - updated_at timestamp not null default(current_timestamp), + created_at timestamptz not null default(current_timestamp), + updated_at timestamptz not null default(current_timestamp), constraint chk_z_id check (z_id <> '') ); @@ -54,8 +54,8 @@ create table services ( name varchar(32) not null unique, frontend varchar(1024), backend varchar(1024), - created_at timestamp not null default(current_timestamp), - updated_at timestamp not null default(current_timestamp), + created_at timestamptz not null default(current_timestamp), + updated_at timestamptz not null default(current_timestamp), constraint chk_z_id check (z_id <> ''), constraint chk_name check (name <> '') diff --git a/rest_model_zrok/environment.go b/rest_model_zrok/environment.go index 9cbe608f..a6041314 100644 --- a/rest_model_zrok/environment.go +++ b/rest_model_zrok/environment.go @@ -24,7 +24,7 @@ type Environment struct { Address string `json:"address,omitempty"` // created at - CreatedAt string `json:"createdAt,omitempty"` + CreatedAt int64 `json:"createdAt,omitempty"` // description Description string `json:"description,omitempty"` @@ -33,7 +33,7 @@ type Environment struct { Host string `json:"host,omitempty"` // updated at - UpdatedAt string `json:"updatedAt,omitempty"` + UpdatedAt int64 `json:"updatedAt,omitempty"` // z Id ZID string `json:"zId,omitempty"` diff --git a/rest_model_zrok/service.go b/rest_model_zrok/service.go index b4f1de28..70e4fc7c 100644 --- a/rest_model_zrok/service.go +++ b/rest_model_zrok/service.go @@ -22,7 +22,7 @@ type Service struct { Backend string `json:"backend,omitempty"` // created at - CreatedAt string `json:"createdAt,omitempty"` + CreatedAt int64 `json:"createdAt,omitempty"` // frontend Frontend string `json:"frontend,omitempty"` @@ -34,7 +34,7 @@ type Service struct { Name string `json:"name,omitempty"` // updated at - UpdatedAt string `json:"updatedAt,omitempty"` + UpdatedAt int64 `json:"updatedAt,omitempty"` // z Id ZID string `json:"zId,omitempty"` diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index 403a9b4e..c69fc027 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -428,7 +428,7 @@ func init() { "type": "string" }, "createdAt": { - "type": "string" + "type": "integer" }, "description": { "type": "string" @@ -437,7 +437,7 @@ func init() { "type": "string" }, "updatedAt": { - "type": "string" + "type": "integer" }, "zId": { "type": "string" @@ -524,7 +524,7 @@ func init() { "type": "string" }, "createdAt": { - "type": "string" + "type": "integer" }, "frontend": { "type": "string" @@ -536,7 +536,7 @@ func init() { "type": "string" }, "updatedAt": { - "type": "string" + "type": "integer" }, "zId": { "type": "string" @@ -1036,7 +1036,7 @@ func init() { "type": "string" }, "createdAt": { - "type": "string" + "type": "integer" }, "description": { "type": "string" @@ -1045,7 +1045,7 @@ func init() { "type": "string" }, "updatedAt": { - "type": "string" + "type": "integer" }, "zId": { "type": "string" @@ -1132,7 +1132,7 @@ func init() { "type": "string" }, "createdAt": { - "type": "string" + "type": "integer" }, "frontend": { "type": "string" @@ -1144,7 +1144,7 @@ func init() { "type": "string" }, "updatedAt": { - "type": "string" + "type": "integer" }, "zId": { "type": "string" diff --git a/specs/zrok.yml b/specs/zrok.yml index f7309739..89f9c497 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -282,9 +282,9 @@ definitions: active: type: boolean createdAt: - type: string + type: integer updatedAt: - type: string + type: integer environmentServicesList: type: array @@ -352,9 +352,9 @@ definitions: metrics: $ref: "#/definitions/serviceMetrics" createdAt: - type: string + type: integer updatedAt: - type: string + type: integer serviceMetrics: type: array diff --git a/ui/package-lock.json b/ui/package-lock.json index bdccface..767194ca 100644 --- a/ui/package-lock.json +++ b/ui/package-lock.json @@ -15,6 +15,7 @@ "@mui/material": "^5.10.4", "dagre": "^0.8.5", "eslint-config-react-app": "^7.0.1", + "humanize-duration": "^3.27.3", "react": "^18.2.0", "react-data-table-component": "^7.5.2", "react-dom": "^18.2.0", @@ -8964,6 +8965,11 @@ "node": ">=10.17.0" } }, + "node_modules/humanize-duration": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.27.3.tgz", + "integrity": "sha512-iimHkHPfIAQ8zCDQLgn08pRqSVioyWvnGfaQ8gond2wf7Jq2jJ+24ykmnRyiz3fIldcn4oUuQXpjqKLhSVR7lw==" + }, "node_modules/iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", @@ -23475,6 +23481,11 @@ "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==" }, + "humanize-duration": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.27.3.tgz", + "integrity": "sha512-iimHkHPfIAQ8zCDQLgn08pRqSVioyWvnGfaQ8gond2wf7Jq2jJ+24ykmnRyiz3fIldcn4oUuQXpjqKLhSVR7lw==" + }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/ui/package.json b/ui/package.json index 283bafc7..aeb0a85e 100644 --- a/ui/package.json +++ b/ui/package.json @@ -10,6 +10,7 @@ "@mui/material": "^5.10.4", "dagre": "^0.8.5", "eslint-config-react-app": "^7.0.1", + "humanize-duration": "^3.27.3", "react": "^18.2.0", "react-data-table-component": "^7.5.2", "react-dom": "^18.2.0", diff --git a/ui/src/Environments.js b/ui/src/Environments.js index bc5013ff..64705e15 100644 --- a/ui/src/Environments.js +++ b/ui/src/Environments.js @@ -2,6 +2,8 @@ import DataTable from 'react-data-table-component'; import Services from './Services'; const Environments = (props) => { + const humanizeDuration = require("humanize-duration") + const columns = [ { name: 'Description', @@ -24,8 +26,8 @@ const Environments = (props) => { sortable: true, }, { - name: 'Updated', - selector: row => row.environment.updatedAt, + name: 'Uptime', + selector: row => humanizeDuration(new Date().getTime() - row.environment.updatedAt), sortable: true, }, ] @@ -33,6 +35,8 @@ const Environments = (props) => { const servicesComponent = ({ data }) => const servicesExpanded = row => row.services != null && row.services.length > 0 + console.log('now', Date.now()) + return (

Environments

diff --git a/ui/src/api/types.js b/ui/src/api/types.js index 03a62d54..3104ed5f 100644 --- a/ui/src/api/types.js +++ b/ui/src/api/types.js @@ -48,8 +48,8 @@ * @property {string} address * @property {string} zId * @property {boolean} active - * @property {string} createdAt - * @property {string} updatedAt + * @property {number} createdAt + * @property {number} updatedAt */ /** @@ -101,8 +101,8 @@ * @property {string} frontend * @property {string} backend * @property {module:types.serviceMetrics} metrics - * @property {string} createdAt - * @property {string} updatedAt + * @property {number} createdAt + * @property {number} updatedAt */ /**