From c1f481e416bc397c9f3c7bebc498f245f64000a2 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 19 Oct 2022 13:06:05 -0400 Subject: [PATCH] add service metrics to overview endpoint (#74, #80) --- rest_model_zrok/service.go | 58 +++++++++++++++++++++++++++--- rest_model_zrok/service_metrics.go | 27 ++++++++++++++ rest_server_zrok/embedded_spec.go | 24 +++++++++---- specs/zrok.yml | 9 +++-- ui/src/api/types.js | 2 +- 5 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 rest_model_zrok/service_metrics.go diff --git a/rest_model_zrok/service.go b/rest_model_zrok/service.go index 6077a6b1..b4f1de28 100644 --- a/rest_model_zrok/service.go +++ b/rest_model_zrok/service.go @@ -8,6 +8,7 @@ package rest_model_zrok import ( "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" ) @@ -17,9 +18,6 @@ import ( // swagger:model service type Service struct { - // active - Active bool `json:"active,omitempty"` - // backend Backend string `json:"backend,omitempty"` @@ -29,6 +27,9 @@ type Service struct { // frontend Frontend string `json:"frontend,omitempty"` + // metrics + Metrics ServiceMetrics `json:"metrics,omitempty"` + // name Name string `json:"name,omitempty"` @@ -41,11 +42,60 @@ type Service struct { // Validate validates this service func (m *Service) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMetrics(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } return nil } -// ContextValidate validates this service based on context it is used +func (m *Service) validateMetrics(formats strfmt.Registry) error { + if swag.IsZero(m.Metrics) { // not required + return nil + } + + if err := m.Metrics.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("metrics") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("metrics") + } + return err + } + + return nil +} + +// ContextValidate validate this service based on the context it is used func (m *Service) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateMetrics(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Service) contextValidateMetrics(ctx context.Context, formats strfmt.Registry) error { + + if err := m.Metrics.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("metrics") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("metrics") + } + return err + } + return nil } diff --git a/rest_model_zrok/service_metrics.go b/rest_model_zrok/service_metrics.go new file mode 100644 index 00000000..d37a57d8 --- /dev/null +++ b/rest_model_zrok/service_metrics.go @@ -0,0 +1,27 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package rest_model_zrok + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" +) + +// ServiceMetrics service metrics +// +// swagger:model serviceMetrics +type ServiceMetrics []int64 + +// Validate validates this service metrics +func (m ServiceMetrics) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this service metrics based on context it is used +func (m ServiceMetrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index e59ae440..403a9b4e 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -520,9 +520,6 @@ func init() { "service": { "type": "object", "properties": { - "active": { - "type": "boolean" - }, "backend": { "type": "string" }, @@ -532,6 +529,9 @@ func init() { "frontend": { "type": "string" }, + "metrics": { + "$ref": "#/definitions/serviceMetrics" + }, "name": { "type": "string" }, @@ -543,6 +543,12 @@ func init() { } } }, + "serviceMetrics": { + "type": "array", + "items": { + "type": "integer" + } + }, "services": { "type": "array", "items": { @@ -1122,9 +1128,6 @@ func init() { "service": { "type": "object", "properties": { - "active": { - "type": "boolean" - }, "backend": { "type": "string" }, @@ -1134,6 +1137,9 @@ func init() { "frontend": { "type": "string" }, + "metrics": { + "$ref": "#/definitions/serviceMetrics" + }, "name": { "type": "string" }, @@ -1145,6 +1151,12 @@ func init() { } } }, + "serviceMetrics": { + "type": "array", + "items": { + "type": "integer" + } + }, "services": { "type": "array", "items": { diff --git a/specs/zrok.yml b/specs/zrok.yml index 520f093b..f7309739 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -349,13 +349,18 @@ definitions: type: string backend: type: string - active: - type: boolean + metrics: + $ref: "#/definitions/serviceMetrics" createdAt: type: string updatedAt: type: string + serviceMetrics: + type: array + items: + type: integer + tunnelRequest: type: object properties: diff --git a/ui/src/api/types.js b/ui/src/api/types.js index bbe23b2e..03a62d54 100644 --- a/ui/src/api/types.js +++ b/ui/src/api/types.js @@ -100,7 +100,7 @@ * @property {string} name * @property {string} frontend * @property {string} backend - * @property {boolean} active + * @property {module:types.serviceMetrics} metrics * @property {string} createdAt * @property {string} updatedAt */