diff --git a/pkg/apiserver/apic.go b/pkg/apiserver/apic.go index 7a069caf2..9ff40c128 100644 --- a/pkg/apiserver/apic.go +++ b/pkg/apiserver/apic.go @@ -409,8 +409,8 @@ func (a *apic) SendMetrics() error { version := cwversion.VersionStr() metric := &models.Metrics{ ApilVersion: &version, - Machines: make([]*models.MetricsSoftInfo, 0), - Bouncers: make([]*models.MetricsSoftInfo, 0), + Machines: make([]*models.MetricsAgentInfo, 0), + Bouncers: make([]*models.MetricsBouncerInfo, 0), } machines, err := a.dbClient.ListMachines() if err != nil { @@ -421,17 +421,20 @@ func (a *apic) SendMetrics() error { return err } for _, machine := range machines { - m := &models.MetricsSoftInfo{ - Version: machine.Version, - Name: machine.MachineId, + m := &models.MetricsAgentInfo{ + Version: machine.Version, + Name: machine.MachineId, + LastUpdate: machine.UpdatedAt.String(), } metric.Machines = append(metric.Machines, m) } for _, bouncer := range bouncers { - m := &models.MetricsSoftInfo{ - Version: bouncer.Version, - Name: bouncer.Type, + m := &models.MetricsBouncerInfo{ + Version: bouncer.Version, + Name: bouncer.Name, + Type: bouncer.Type, + LastPull: bouncer.LastPull.String(), } metric.Bouncers = append(metric.Bouncers, m) } diff --git a/pkg/models/localapi_swagger.yaml b/pkg/models/localapi_swagger.yaml index 796994947..587e08e2f 100644 --- a/pkg/models/localapi_swagger.yaml +++ b/pkg/models/localapi_swagger.yaml @@ -767,17 +767,34 @@ definitions: bouncers: type: array items: - $ref: '#/definitions/MetricsSoftInfo' + $ref: '#/definitions/MetricsBouncerInfo' machines: type: array items: - $ref: '#/definitions/MetricsSoftInfo' + $ref: '#/definitions/MetricsAgentInfo' required: - apil_version - bouncers - machines - MetricsSoftInfo: - title: MetricsSoftInfo + MetricsBouncerInfo: + title: MetricsBouncerInfo + description: Software version info (so we can warn users about out-of-date software). The software name and the version are "guessed" from the user-agent + type: object + properties: + name: + type: string + description: name of the component + type: + type: string + description: bouncer type (firewall, php ...) + version: + type: string + description: software version + last_pull: + type: string + description: last bouncer pull date + MetricsAgentInfo: + title: MetricsAgentInfo description: Software version info (so we can warn users about out-of-date software). The software name and the version are "guessed" from the user-agent type: object properties: @@ -787,6 +804,12 @@ definitions: version: type: string description: software version + last_update: + type: string + description: last agent update date + last_push: + type: string + description: last agent push date Decision: title: Decision type: object diff --git a/pkg/models/metrics.go b/pkg/models/metrics.go index 1e96d37c1..47a034f59 100644 --- a/pkg/models/metrics.go +++ b/pkg/models/metrics.go @@ -6,6 +6,7 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" "strconv" "github.com/go-openapi/errors" @@ -25,11 +26,11 @@ type Metrics struct { // bouncers // Required: true - Bouncers []*MetricsSoftInfo `json:"bouncers"` + Bouncers []*MetricsBouncerInfo `json:"bouncers"` // machines // Required: true - Machines []*MetricsSoftInfo `json:"machines"` + Machines []*MetricsAgentInfo `json:"machines"` } // Validate validates this metrics @@ -113,6 +114,60 @@ func (m *Metrics) validateMachines(formats strfmt.Registry) error { return nil } +// ContextValidate validate this metrics based on the context it is used +func (m *Metrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateBouncers(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMachines(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Metrics) contextValidateBouncers(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Bouncers); i++ { + + if m.Bouncers[i] != nil { + if err := m.Bouncers[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +func (m *Metrics) contextValidateMachines(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Machines); i++ { + + if m.Machines[i] != nil { + if err := m.Machines[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("machines" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + // MarshalBinary interface implementation func (m *Metrics) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/pkg/models/metrics_soft_info.go b/pkg/models/metrics_soft_info.go deleted file mode 100644 index 60aa727bb..000000000 --- a/pkg/models/metrics_soft_info.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -package models - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "github.com/go-openapi/strfmt" - "github.com/go-openapi/swag" -) - -// MetricsSoftInfo MetricsSoftInfo -// -// Software version info (so we can warn users about out-of-date software). The software name and the version are "guessed" from the user-agent -// -// swagger:model MetricsSoftInfo -type MetricsSoftInfo struct { - - // name of the component - Name string `json:"name,omitempty"` - - // software version - Version string `json:"version,omitempty"` -} - -// Validate validates this metrics soft info -func (m *MetricsSoftInfo) Validate(formats strfmt.Registry) error { - return nil -} - -// MarshalBinary interface implementation -func (m *MetricsSoftInfo) MarshalBinary() ([]byte, error) { - if m == nil { - return nil, nil - } - return swag.WriteJSON(m) -} - -// UnmarshalBinary interface implementation -func (m *MetricsSoftInfo) UnmarshalBinary(b []byte) error { - var res MetricsSoftInfo - if err := swag.ReadJSON(b, &res); err != nil { - return err - } - *m = res - return nil -}