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 ( import (
"context" "context"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag" "github.com/go-openapi/swag"
) )
@ -17,9 +18,6 @@ import (
// swagger:model service // swagger:model service
type Service struct { type Service struct {
// active
Active bool `json:"active,omitempty"`
// backend // backend
Backend string `json:"backend,omitempty"` Backend string `json:"backend,omitempty"`
@ -29,6 +27,9 @@ type Service struct {
// frontend // frontend
Frontend string `json:"frontend,omitempty"` Frontend string `json:"frontend,omitempty"`
// metrics
Metrics ServiceMetrics `json:"metrics,omitempty"`
// name // name
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
@ -41,11 +42,60 @@ type Service struct {
// Validate validates this service // Validate validates this service
func (m *Service) Validate(formats strfmt.Registry) error { 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 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 { 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 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": { "service": {
"type": "object", "type": "object",
"properties": { "properties": {
"active": {
"type": "boolean"
},
"backend": { "backend": {
"type": "string" "type": "string"
}, },
@ -532,6 +529,9 @@ func init() {
"frontend": { "frontend": {
"type": "string" "type": "string"
}, },
"metrics": {
"$ref": "#/definitions/serviceMetrics"
},
"name": { "name": {
"type": "string" "type": "string"
}, },
@ -543,6 +543,12 @@ func init() {
} }
} }
}, },
"serviceMetrics": {
"type": "array",
"items": {
"type": "integer"
}
},
"services": { "services": {
"type": "array", "type": "array",
"items": { "items": {
@ -1122,9 +1128,6 @@ func init() {
"service": { "service": {
"type": "object", "type": "object",
"properties": { "properties": {
"active": {
"type": "boolean"
},
"backend": { "backend": {
"type": "string" "type": "string"
}, },
@ -1134,6 +1137,9 @@ func init() {
"frontend": { "frontend": {
"type": "string" "type": "string"
}, },
"metrics": {
"$ref": "#/definitions/serviceMetrics"
},
"name": { "name": {
"type": "string" "type": "string"
}, },
@ -1145,6 +1151,12 @@ func init() {
} }
} }
}, },
"serviceMetrics": {
"type": "array",
"items": {
"type": "integer"
}
},
"services": { "services": {
"type": "array", "type": "array",
"items": { "items": {

View File

@ -349,13 +349,18 @@ definitions:
type: string type: string
backend: backend:
type: string type: string
active: metrics:
type: boolean $ref: "#/definitions/serviceMetrics"
createdAt: createdAt:
type: string type: string
updatedAt: updatedAt:
type: string type: string
serviceMetrics:
type: array
items:
type: integer
tunnelRequest: tunnelRequest:
type: object type: object
properties: properties:

View File

@ -100,7 +100,7 @@
* @property {string} name * @property {string} name
* @property {string} frontend * @property {string} frontend
* @property {string} backend * @property {string} backend
* @property {boolean} active * @property {module:types.serviceMetrics} metrics
* @property {string} createdAt * @property {string} createdAt
* @property {string} updatedAt * @property {string} updatedAt
*/ */