add service metrics to overview endpoint (#74, #80)

This commit is contained in:
Michael Quigley 2022-10-19 13:06:05 -04:00
parent 40252f7a10
commit c1f481e416
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 107 additions and 13 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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": {

View File

@ -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:

View File

@ -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
*/