update swagger and models

This commit is contained in:
Sebastien Blot 2024-04-22 14:25:23 +02:00
parent c6ebd7ae04
commit f0853188ce
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
7 changed files with 119 additions and 238 deletions

View file

@ -125,7 +125,7 @@ func (m *MetricsProvider) metricsPayload() *models.AllMetrics {
FeatureFlags: m.static.featureFlags,
}
item0 := &models.LogProcessorsMetricsItems0{
met := &models.LogProcessorsMetrics{
BaseMetrics: base,
ConsoleOptions: m.static.consoleOptions,
Datasources: m.static.datasourceMap,
@ -135,7 +135,7 @@ func (m *MetricsProvider) metricsPayload() *models.AllMetrics {
// TODO: more metric details... ?
return &models.AllMetrics{
LogProcessors: []models.LogProcessorsMetrics{{item0}},
LogProcessors: []*models.LogProcessorsMetrics{met},
}
}
@ -153,7 +153,7 @@ func (m *MetricsProvider) Run(ctx context.Context, myTomb *tomb.Tomb) error {
for {
select {
case <-ticker.C:
met.LogProcessors[0][0].Meta.UtcNowTimestamp = time.Now().Unix()
met.LogProcessors[0].Meta.UtcNowTimestamp = time.Now().Unix()
ctxTime, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

View file

@ -42,7 +42,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
for _, lpsMetric := range lpsMetrics {
lpName := lpsMetric.GeneratedBy
metrics := models.LogProcessorsMetricsItems0{}
metrics := models.LogProcessorsMetrics{}
err := json.Unmarshal([]byte(lpsMetric.Payload), &metrics)
if err != nil {
@ -78,13 +78,13 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
metrics.Name = lpName
metrics.LastPush = lp.LastPush.UTC().Unix()
allMetrics.LogProcessors = append(allMetrics.LogProcessors, models.LogProcessorsMetrics{&metrics})
allMetrics.LogProcessors = append(allMetrics.LogProcessors, &metrics)
metricsIds = append(metricsIds, lpsMetric.ID)
}
for _, bouncersMetric := range bouncersMetrics {
bouncerName := bouncersMetric.GeneratedBy
metrics := models.RemediationComponentsMetricsItems0{}
metrics := models.RemediationComponentsMetrics{}
err := json.Unmarshal([]byte(bouncersMetric.Payload), &metrics)
if err != nil {
@ -114,7 +114,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
metrics.Name = bouncerName
metrics.LastPull = bouncer.LastPull.UTC().Unix()
allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, models.RemediationComponentsMetrics{&metrics})
allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, &metrics)
metricsIds = append(metricsIds, bouncersMetric.ID)
}

View file

@ -83,7 +83,7 @@ func (c *Controller) UsageMetrics(gctx *gin.Context) {
case 1:
// the final slice can't have more than one item,
// guaranteed by the swagger schema
item0 := input.LogProcessors[0][0]
item0 := input.LogProcessors[0]
payload = map[string]any{
"console_options": item0.ConsoleOptions,
"datasources": item0.Datasources,
@ -103,7 +103,7 @@ func (c *Controller) UsageMetrics(gctx *gin.Context) {
case 0:
break
case 1:
item0 := input.RemediationComponents[0][0]
item0 := input.RemediationComponents[0]
payload = map[string]any{
"type": item0.Type,
"metrics": item0.Metrics,

View file

@ -20,10 +20,10 @@ import (
type AllMetrics struct {
// log processors metrics
LogProcessors []LogProcessorsMetrics `json:"log_processors"`
LogProcessors []*LogProcessorsMetrics `json:"log_processors"`
// remediation components metrics
RemediationComponents []RemediationComponentsMetrics `json:"remediation_components"`
RemediationComponents []*RemediationComponentsMetrics `json:"remediation_components"`
}
// Validate validates this all metrics
@ -50,7 +50,11 @@ func (m *AllMetrics) validateLogProcessors(formats strfmt.Registry) error {
}
for i := 0; i < len(m.LogProcessors); i++ {
if swag.IsZero(m.LogProcessors[i]) { // not required
continue
}
if m.LogProcessors[i] != nil {
if err := m.LogProcessors[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("log_processors" + "." + strconv.Itoa(i))
@ -59,6 +63,7 @@ func (m *AllMetrics) validateLogProcessors(formats strfmt.Registry) error {
}
return err
}
}
}
@ -71,7 +76,11 @@ func (m *AllMetrics) validateRemediationComponents(formats strfmt.Registry) erro
}
for i := 0; i < len(m.RemediationComponents); i++ {
if swag.IsZero(m.RemediationComponents[i]) { // not required
continue
}
if m.RemediationComponents[i] != nil {
if err := m.RemediationComponents[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("remediation_components" + "." + strconv.Itoa(i))
@ -80,6 +89,7 @@ func (m *AllMetrics) validateRemediationComponents(formats strfmt.Registry) erro
}
return err
}
}
}
@ -108,6 +118,12 @@ func (m *AllMetrics) contextValidateLogProcessors(ctx context.Context, formats s
for i := 0; i < len(m.LogProcessors); i++ {
if m.LogProcessors[i] != nil {
if swag.IsZero(m.LogProcessors[i]) { // not required
return nil
}
if err := m.LogProcessors[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("log_processors" + "." + strconv.Itoa(i))
@ -116,6 +132,7 @@ func (m *AllMetrics) contextValidateLogProcessors(ctx context.Context, formats s
}
return err
}
}
}
@ -126,6 +143,12 @@ func (m *AllMetrics) contextValidateRemediationComponents(ctx context.Context, f
for i := 0; i < len(m.RemediationComponents); i++ {
if m.RemediationComponents[i] != nil {
if swag.IsZero(m.RemediationComponents[i]) { // not required
return nil
}
if err := m.RemediationComponents[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("remediation_components" + "." + strconv.Itoa(i))
@ -134,6 +157,7 @@ func (m *AllMetrics) contextValidateRemediationComponents(ctx context.Context, f
}
return err
}
}
}

View file

@ -1026,13 +1026,10 @@ definitions:
type: string
RemediationComponentsMetrics:
title: RemediationComponentsMetrics
type: array
maxItems: 1
items:
type: object
allOf:
- $ref: '#/definitions/BaseMetrics'
- type: object
properties:
- properties:
type:
type: string
description: type of the remediation component
@ -1044,13 +1041,10 @@ definitions:
description: last pull date
LogProcessorsMetrics:
title: LogProcessorsMetrics
type: array
maxItems: 1
items:
type: object
allOf:
- $ref: '#/definitions/BaseMetrics'
- type: object
properties:
- properties:
console_options:
$ref: '#/definitions/ConsoleOptions'
hub_items:
@ -1066,6 +1060,11 @@ definitions:
last_push:
type: integer
description: last push date
#items:
# allOf:
# - $ref: '#/definitions/BaseMetrics'
# - type: object
AllMetrics:
title: AllMetrics
type: object

View file

@ -7,87 +7,16 @@ package models
import (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// LogProcessorsMetrics LogProcessorsMetrics
//
// swagger:model LogProcessorsMetrics
type LogProcessorsMetrics []*LogProcessorsMetricsItems0
// Validate validates this log processors metrics
func (m LogProcessorsMetrics) Validate(formats strfmt.Registry) error {
var res []error
iLogProcessorsMetricsSize := int64(len(m))
if err := validate.MaxItems("", "body", iLogProcessorsMetricsSize, 1); err != nil {
return err
}
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// ContextValidate validate this log processors metrics based on the context it is used
func (m LogProcessorsMetrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if m[i] != nil {
if swag.IsZero(m[i]) { // not required
return nil
}
if err := m[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// LogProcessorsMetricsItems0 log processors metrics items0
//
// swagger:model LogProcessorsMetricsItems0
type LogProcessorsMetricsItems0 struct {
type LogProcessorsMetrics struct {
BaseMetrics
// console options
@ -107,7 +36,7 @@ type LogProcessorsMetricsItems0 struct {
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error {
func (m *LogProcessorsMetrics) UnmarshalJSON(raw []byte) error {
// AO0
var aO0 BaseMetrics
if err := swag.ReadJSON(raw, &aO0); err != nil {
@ -145,7 +74,7 @@ func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error {
}
// MarshalJSON marshals this object to a JSON structure
func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) {
func (m LogProcessorsMetrics) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
aO0, err := swag.WriteJSON(m.BaseMetrics)
@ -183,8 +112,8 @@ func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) {
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this log processors metrics items0
func (m *LogProcessorsMetricsItems0) Validate(formats strfmt.Registry) error {
// Validate validates this log processors metrics
func (m *LogProcessorsMetrics) Validate(formats strfmt.Registry) error {
var res []error
// validation for a type composition with BaseMetrics
@ -206,7 +135,7 @@ func (m *LogProcessorsMetricsItems0) Validate(formats strfmt.Registry) error {
return nil
}
func (m *LogProcessorsMetricsItems0) validateConsoleOptions(formats strfmt.Registry) error {
func (m *LogProcessorsMetrics) validateConsoleOptions(formats strfmt.Registry) error {
if swag.IsZero(m.ConsoleOptions) { // not required
return nil
@ -224,7 +153,7 @@ func (m *LogProcessorsMetricsItems0) validateConsoleOptions(formats strfmt.Regis
return nil
}
func (m *LogProcessorsMetricsItems0) validateHubItems(formats strfmt.Registry) error {
func (m *LogProcessorsMetrics) validateHubItems(formats strfmt.Registry) error {
if swag.IsZero(m.HubItems) { // not required
return nil
@ -244,8 +173,8 @@ func (m *LogProcessorsMetricsItems0) validateHubItems(formats strfmt.Registry) e
return nil
}
// ContextValidate validate this log processors metrics items0 based on the context it is used
func (m *LogProcessorsMetricsItems0) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
// ContextValidate validate this log processors metrics based on the context it is used
func (m *LogProcessorsMetrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
// validation for a type composition with BaseMetrics
@ -267,7 +196,7 @@ func (m *LogProcessorsMetricsItems0) ContextValidate(ctx context.Context, format
return nil
}
func (m *LogProcessorsMetricsItems0) contextValidateConsoleOptions(ctx context.Context, formats strfmt.Registry) error {
func (m *LogProcessorsMetrics) contextValidateConsoleOptions(ctx context.Context, formats strfmt.Registry) error {
if err := m.ConsoleOptions.ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
@ -281,7 +210,7 @@ func (m *LogProcessorsMetricsItems0) contextValidateConsoleOptions(ctx context.C
return nil
}
func (m *LogProcessorsMetricsItems0) contextValidateHubItems(ctx context.Context, formats strfmt.Registry) error {
func (m *LogProcessorsMetrics) contextValidateHubItems(ctx context.Context, formats strfmt.Registry) error {
if swag.IsZero(m.HubItems) { // not required
return nil
@ -300,7 +229,7 @@ func (m *LogProcessorsMetricsItems0) contextValidateHubItems(ctx context.Context
}
// MarshalBinary interface implementation
func (m *LogProcessorsMetricsItems0) MarshalBinary() ([]byte, error) {
func (m *LogProcessorsMetrics) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
@ -308,8 +237,8 @@ func (m *LogProcessorsMetricsItems0) MarshalBinary() ([]byte, error) {
}
// UnmarshalBinary interface implementation
func (m *LogProcessorsMetricsItems0) UnmarshalBinary(b []byte) error {
var res LogProcessorsMetricsItems0
func (m *LogProcessorsMetrics) UnmarshalBinary(b []byte) error {
var res LogProcessorsMetrics
if err := swag.ReadJSON(b, &res); err != nil {
return err
}

View file

@ -7,87 +7,16 @@ package models
import (
"context"
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// RemediationComponentsMetrics RemediationComponentsMetrics
//
// swagger:model RemediationComponentsMetrics
type RemediationComponentsMetrics []*RemediationComponentsMetricsItems0
// Validate validates this remediation components metrics
func (m RemediationComponentsMetrics) Validate(formats strfmt.Registry) error {
var res []error
iRemediationComponentsMetricsSize := int64(len(m))
if err := validate.MaxItems("", "body", iRemediationComponentsMetricsSize, 1); err != nil {
return err
}
for i := 0; i < len(m); i++ {
if swag.IsZero(m[i]) { // not required
continue
}
if m[i] != nil {
if err := m[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// ContextValidate validate this remediation components metrics based on the context it is used
func (m RemediationComponentsMetrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
for i := 0; i < len(m); i++ {
if m[i] != nil {
if swag.IsZero(m[i]) { // not required
return nil
}
if err := m[i].ContextValidate(ctx, formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName(strconv.Itoa(i))
} else if ce, ok := err.(*errors.CompositeError); ok {
return ce.ValidateName(strconv.Itoa(i))
}
return err
}
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// RemediationComponentsMetricsItems0 remediation components metrics items0
//
// swagger:model RemediationComponentsMetricsItems0
type RemediationComponentsMetricsItems0 struct {
type RemediationComponentsMetrics struct {
BaseMetrics
// last pull date
@ -101,7 +30,7 @@ type RemediationComponentsMetricsItems0 struct {
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *RemediationComponentsMetricsItems0) UnmarshalJSON(raw []byte) error {
func (m *RemediationComponentsMetrics) UnmarshalJSON(raw []byte) error {
// AO0
var aO0 BaseMetrics
if err := swag.ReadJSON(raw, &aO0); err != nil {
@ -131,7 +60,7 @@ func (m *RemediationComponentsMetricsItems0) UnmarshalJSON(raw []byte) error {
}
// MarshalJSON marshals this object to a JSON structure
func (m RemediationComponentsMetricsItems0) MarshalJSON() ([]byte, error) {
func (m RemediationComponentsMetrics) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
aO0, err := swag.WriteJSON(m.BaseMetrics)
@ -161,8 +90,8 @@ func (m RemediationComponentsMetricsItems0) MarshalJSON() ([]byte, error) {
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this remediation components metrics items0
func (m *RemediationComponentsMetricsItems0) Validate(formats strfmt.Registry) error {
// Validate validates this remediation components metrics
func (m *RemediationComponentsMetrics) Validate(formats strfmt.Registry) error {
var res []error
// validation for a type composition with BaseMetrics
@ -176,8 +105,8 @@ func (m *RemediationComponentsMetricsItems0) Validate(formats strfmt.Registry) e
return nil
}
// ContextValidate validate this remediation components metrics items0 based on the context it is used
func (m *RemediationComponentsMetricsItems0) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
// ContextValidate validate this remediation components metrics based on the context it is used
func (m *RemediationComponentsMetrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error
// validation for a type composition with BaseMetrics
@ -192,7 +121,7 @@ func (m *RemediationComponentsMetricsItems0) ContextValidate(ctx context.Context
}
// MarshalBinary interface implementation
func (m *RemediationComponentsMetricsItems0) MarshalBinary() ([]byte, error) {
func (m *RemediationComponentsMetrics) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
@ -200,8 +129,8 @@ func (m *RemediationComponentsMetricsItems0) MarshalBinary() ([]byte, error) {
}
// UnmarshalBinary interface implementation
func (m *RemediationComponentsMetricsItems0) UnmarshalBinary(b []byte) error {
var res RemediationComponentsMetricsItems0
func (m *RemediationComponentsMetrics) UnmarshalBinary(b []byte) error {
var res RemediationComponentsMetrics
if err := swag.ReadJSON(b, &res); err != nil {
return err
}