communicate time as epoch ms; better disable of durations in ui (#33)

This commit is contained in:
Michael Quigley 2022-11-01 16:52:02 -04:00
parent 225e00861b
commit 95b4143a85
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
10 changed files with 52 additions and 34 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/openziti-test-kitchen/zrok/rest_model_zrok" "github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata" "github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/metadata"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"time"
) )
func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Principal) middleware.Responder { 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) logrus.Errorf("error finding services for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError() return metadata.NewOverviewInternalServerError()
} }
logrus.Infof("updatedAt: %v", time.Since(env.UpdatedAt.UTC()))
es := &rest_model_zrok.EnvironmentServices{ es := &rest_model_zrok.EnvironmentServices{
Environment: &rest_model_zrok.Environment{ Environment: &rest_model_zrok.Environment{
Address: env.Address, Address: env.Address,
CreatedAt: env.CreatedAt.String(), CreatedAt: env.CreatedAt.UnixMilli(),
Description: env.Description, Description: env.Description,
Host: env.Host, Host: env.Host,
UpdatedAt: env.UpdatedAt.String(), UpdatedAt: env.UpdatedAt.UnixMilli(),
ZID: env.ZId, ZID: env.ZId,
}, },
} }
@ -46,10 +48,10 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
} }
for _, svc := range svcs { for _, svc := range svcs {
es.Services = append(es.Services, &rest_model_zrok.Service{ es.Services = append(es.Services, &rest_model_zrok.Service{
CreatedAt: svc.CreatedAt.String(), CreatedAt: svc.CreatedAt.UnixMilli(),
Frontend: svc.Frontend, Frontend: svc.Frontend,
Backend: svc.Backend, Backend: svc.Backend,
UpdatedAt: svc.UpdatedAt.String(), UpdatedAt: svc.UpdatedAt.UnixMilli(),
ZID: svc.ZId, ZID: svc.ZId,
Name: svc.Name, Name: svc.Name,
Metrics: sparkData[svc.Name], Metrics: sparkData[svc.Name],

View File

@ -8,8 +8,8 @@ create table accounts (
email varchar(1024) not null unique, email varchar(1024) not null unique,
password char(128) not null, password char(128) not null,
token varchar(32) not null unique, token varchar(32) not null unique,
created_at timestamp not null default(current_timestamp), created_at timestamptz not null default(current_timestamp),
updated_at timestamp not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp),
constraint chk_email check (email <> ''), constraint chk_email check (email <> ''),
constraint chk_password check (password <> ''), constraint chk_password check (password <> ''),
@ -24,8 +24,8 @@ create table account_requests (
token varchar(32) not null unique, token varchar(32) not null unique,
email varchar(1024) not null unique, email varchar(1024) not null unique,
source_address varchar(64) not null, source_address varchar(64) not null,
created_at timestamp not null default(current_timestamp), created_at timestamptz not null default(current_timestamp),
updated_at timestamp not null default(current_timestamp) updated_at timestamptz not null default(current_timestamp)
); );
-- --
@ -38,8 +38,8 @@ create table environments (
host varchar(256), host varchar(256),
address varchar(64), address varchar(64),
z_id varchar(32) not null unique, z_id varchar(32) not null unique,
created_at timestamp not null default(current_timestamp), created_at timestamptz not null default(current_timestamp),
updated_at timestamp not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp),
constraint chk_z_id check (z_id <> '') constraint chk_z_id check (z_id <> '')
); );
@ -54,8 +54,8 @@ create table services (
name varchar(32) not null unique, name varchar(32) not null unique,
frontend varchar(1024), frontend varchar(1024),
backend varchar(1024), backend varchar(1024),
created_at timestamp not null default(current_timestamp), created_at timestamptz not null default(current_timestamp),
updated_at timestamp not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp),
constraint chk_z_id check (z_id <> ''), constraint chk_z_id check (z_id <> ''),
constraint chk_name check (name <> '') constraint chk_name check (name <> '')

View File

@ -24,7 +24,7 @@ type Environment struct {
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
// created at // created at
CreatedAt string `json:"createdAt,omitempty"` CreatedAt int64 `json:"createdAt,omitempty"`
// description // description
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
@ -33,7 +33,7 @@ type Environment struct {
Host string `json:"host,omitempty"` Host string `json:"host,omitempty"`
// updated at // updated at
UpdatedAt string `json:"updatedAt,omitempty"` UpdatedAt int64 `json:"updatedAt,omitempty"`
// z Id // z Id
ZID string `json:"zId,omitempty"` ZID string `json:"zId,omitempty"`

View File

@ -22,7 +22,7 @@ type Service struct {
Backend string `json:"backend,omitempty"` Backend string `json:"backend,omitempty"`
// created at // created at
CreatedAt string `json:"createdAt,omitempty"` CreatedAt int64 `json:"createdAt,omitempty"`
// frontend // frontend
Frontend string `json:"frontend,omitempty"` Frontend string `json:"frontend,omitempty"`
@ -34,7 +34,7 @@ type Service struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// updated at // updated at
UpdatedAt string `json:"updatedAt,omitempty"` UpdatedAt int64 `json:"updatedAt,omitempty"`
// z Id // z Id
ZID string `json:"zId,omitempty"` ZID string `json:"zId,omitempty"`

View File

@ -428,7 +428,7 @@ func init() {
"type": "string" "type": "string"
}, },
"createdAt": { "createdAt": {
"type": "string" "type": "integer"
}, },
"description": { "description": {
"type": "string" "type": "string"
@ -437,7 +437,7 @@ func init() {
"type": "string" "type": "string"
}, },
"updatedAt": { "updatedAt": {
"type": "string" "type": "integer"
}, },
"zId": { "zId": {
"type": "string" "type": "string"
@ -524,7 +524,7 @@ func init() {
"type": "string" "type": "string"
}, },
"createdAt": { "createdAt": {
"type": "string" "type": "integer"
}, },
"frontend": { "frontend": {
"type": "string" "type": "string"
@ -536,7 +536,7 @@ func init() {
"type": "string" "type": "string"
}, },
"updatedAt": { "updatedAt": {
"type": "string" "type": "integer"
}, },
"zId": { "zId": {
"type": "string" "type": "string"
@ -1036,7 +1036,7 @@ func init() {
"type": "string" "type": "string"
}, },
"createdAt": { "createdAt": {
"type": "string" "type": "integer"
}, },
"description": { "description": {
"type": "string" "type": "string"
@ -1045,7 +1045,7 @@ func init() {
"type": "string" "type": "string"
}, },
"updatedAt": { "updatedAt": {
"type": "string" "type": "integer"
}, },
"zId": { "zId": {
"type": "string" "type": "string"
@ -1132,7 +1132,7 @@ func init() {
"type": "string" "type": "string"
}, },
"createdAt": { "createdAt": {
"type": "string" "type": "integer"
}, },
"frontend": { "frontend": {
"type": "string" "type": "string"
@ -1144,7 +1144,7 @@ func init() {
"type": "string" "type": "string"
}, },
"updatedAt": { "updatedAt": {
"type": "string" "type": "integer"
}, },
"zId": { "zId": {
"type": "string" "type": "string"

View File

@ -282,9 +282,9 @@ definitions:
active: active:
type: boolean type: boolean
createdAt: createdAt:
type: string type: integer
updatedAt: updatedAt:
type: string type: integer
environmentServicesList: environmentServicesList:
type: array type: array
@ -352,9 +352,9 @@ definitions:
metrics: metrics:
$ref: "#/definitions/serviceMetrics" $ref: "#/definitions/serviceMetrics"
createdAt: createdAt:
type: string type: integer
updatedAt: updatedAt:
type: string type: integer
serviceMetrics: serviceMetrics:
type: array type: array

11
ui/package-lock.json generated
View File

@ -15,6 +15,7 @@
"@mui/material": "^5.10.4", "@mui/material": "^5.10.4",
"dagre": "^0.8.5", "dagre": "^0.8.5",
"eslint-config-react-app": "^7.0.1", "eslint-config-react-app": "^7.0.1",
"humanize-duration": "^3.27.3",
"react": "^18.2.0", "react": "^18.2.0",
"react-data-table-component": "^7.5.2", "react-data-table-component": "^7.5.2",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
@ -8964,6 +8965,11 @@
"node": ">=10.17.0" "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": { "node_modules/iconv-lite": {
"version": "0.4.24", "version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "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", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz",
"integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==" "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": { "iconv-lite": {
"version": "0.4.24", "version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",

View File

@ -10,6 +10,7 @@
"@mui/material": "^5.10.4", "@mui/material": "^5.10.4",
"dagre": "^0.8.5", "dagre": "^0.8.5",
"eslint-config-react-app": "^7.0.1", "eslint-config-react-app": "^7.0.1",
"humanize-duration": "^3.27.3",
"react": "^18.2.0", "react": "^18.2.0",
"react-data-table-component": "^7.5.2", "react-data-table-component": "^7.5.2",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",

View File

@ -2,6 +2,8 @@ import DataTable from 'react-data-table-component';
import Services from './Services'; import Services from './Services';
const Environments = (props) => { const Environments = (props) => {
const humanizeDuration = require("humanize-duration")
const columns = [ const columns = [
{ {
name: 'Description', name: 'Description',
@ -24,8 +26,8 @@ const Environments = (props) => {
sortable: true, sortable: true,
}, },
{ {
name: 'Updated', name: 'Uptime',
selector: row => row.environment.updatedAt, selector: row => humanizeDuration(new Date().getTime() - row.environment.updatedAt),
sortable: true, sortable: true,
}, },
] ]
@ -33,6 +35,8 @@ const Environments = (props) => {
const servicesComponent = ({ data }) => <Services services={data.services} /> const servicesComponent = ({ data }) => <Services services={data.services} />
const servicesExpanded = row => row.services != null && row.services.length > 0 const servicesExpanded = row => row.services != null && row.services.length > 0
console.log('now', Date.now())
return ( return (
<div> <div>
<h2>Environments</h2> <h2>Environments</h2>

View File

@ -48,8 +48,8 @@
* @property {string} address * @property {string} address
* @property {string} zId * @property {string} zId
* @property {boolean} active * @property {boolean} active
* @property {string} createdAt * @property {number} createdAt
* @property {string} updatedAt * @property {number} updatedAt
*/ */
/** /**
@ -101,8 +101,8 @@
* @property {string} frontend * @property {string} frontend
* @property {string} backend * @property {string} backend
* @property {module:types.serviceMetrics} metrics * @property {module:types.serviceMetrics} metrics
* @property {string} createdAt * @property {number} createdAt
* @property {string} updatedAt * @property {number} updatedAt
*/ */
/** /**