This commit is contained in:
Sebastien Blot 2024-04-22 09:58:48 +02:00
parent be64f619f2
commit 2b940a45f8
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
4 changed files with 73 additions and 7 deletions

View file

@ -3,7 +3,6 @@ package apiserver
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"strings" "strings"
"time" "time"
@ -76,6 +75,9 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
metrics.FeatureFlags = strings.Split(lp.Featureflags, ",") metrics.FeatureFlags = strings.Split(lp.Featureflags, ",")
metrics.Version = &lp.Version metrics.Version = &lp.Version
metrics.Name = lpName
metrics.LastPush = lp.LastPush.UTC().Unix()
allMetrics.LogProcessors = append(allMetrics.LogProcessors, models.LogProcessorsMetrics{&metrics}) allMetrics.LogProcessors = append(allMetrics.LogProcessors, models.LogProcessorsMetrics{&metrics})
metricsIds = append(metricsIds, lpsMetric.ID) metricsIds = append(metricsIds, lpsMetric.ID)
} }
@ -109,6 +111,8 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
metrics.Type = bouncer.Type metrics.Type = bouncer.Type
metrics.FeatureFlags = strings.Split(bouncer.Featureflags, ",") metrics.FeatureFlags = strings.Split(bouncer.Featureflags, ",")
metrics.Version = &bouncer.Version metrics.Version = &bouncer.Version
metrics.Name = bouncerName
metrics.LastPull = bouncer.LastPull.UTC().Unix()
allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, models.RemediationComponentsMetrics{&metrics}) allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, models.RemediationComponentsMetrics{&metrics})
metricsIds = append(metricsIds, bouncersMetric.ID) metricsIds = append(metricsIds, bouncersMetric.ID)
@ -288,15 +292,21 @@ func (a *apic) SendUsageMetrics() {
if err != nil { if err != nil {
log.Errorf("unable to get usage metrics (%s)", err) log.Errorf("unable to get usage metrics (%s)", err)
} }
jsonStr, err := json.Marshal(metrics) /*jsonStr, err := json.Marshal(metrics)
if err != nil { if err != nil {
log.Errorf("unable to marshal usage metrics (%s)", err) log.Errorf("unable to marshal usage metrics (%s)", err)
} }*/
fmt.Printf("Usage metrics: %s\n", string(jsonStr)) //fmt.Printf("Usage metrics: %s\n", string(jsonStr))
//TODO: actually send the data _, _, err = a.apiClient.UsageMetrics.Add(context.Background(), metrics)
err = a.MarkUsageMetricsAsSent(metricsId)
if err != nil { if err != nil {
log.Errorf("unable to mark usage metrics as sent (%s)", err) log.Errorf("unable to send usage metrics (%s)", err)
} else {
err = a.MarkUsageMetricsAsSent(metricsId)
if err != nil {
log.Errorf("unable to mark usage metrics as sent (%s)", err)
}
} }
} }
} }

View file

@ -1036,6 +1036,12 @@ definitions:
type: type:
type: string type: string
description: type of the remediation component description: type of the remediation component
name:
type: string
description: name of the remediation component
last_pull:
type: integer
description: last pull date
LogProcessorsMetrics: LogProcessorsMetrics:
title: LogProcessorsMetrics title: LogProcessorsMetrics
type: array type: array
@ -1054,6 +1060,12 @@ definitions:
description: Number of datasources per type description: Number of datasources per type
additionalProperties: additionalProperties:
type: integer type: integer
name:
type: string
description: name of the log processor
last_push:
type: integer
description: last push date
AllMetrics: AllMetrics:
title: AllMetrics title: AllMetrics
type: object type: object

View file

@ -98,6 +98,12 @@ type LogProcessorsMetricsItems0 struct {
// hub items // hub items
HubItems HubItems `json:"hub_items,omitempty"` HubItems HubItems `json:"hub_items,omitempty"`
// last push date
LastPush int64 `json:"last_push,omitempty"`
// name of the log processor
Name string `json:"name,omitempty"`
} }
// UnmarshalJSON unmarshals this object from a JSON structure // UnmarshalJSON unmarshals this object from a JSON structure
@ -116,6 +122,10 @@ func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error {
Datasources map[string]int64 `json:"datasources,omitempty"` Datasources map[string]int64 `json:"datasources,omitempty"`
HubItems HubItems `json:"hub_items,omitempty"` HubItems HubItems `json:"hub_items,omitempty"`
LastPush int64 `json:"last_push,omitempty"`
Name string `json:"name,omitempty"`
} }
if err := swag.ReadJSON(raw, &dataAO1); err != nil { if err := swag.ReadJSON(raw, &dataAO1); err != nil {
return err return err
@ -127,6 +137,10 @@ func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error {
m.HubItems = dataAO1.HubItems m.HubItems = dataAO1.HubItems
m.LastPush = dataAO1.LastPush
m.Name = dataAO1.Name
return nil return nil
} }
@ -145,6 +159,10 @@ func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) {
Datasources map[string]int64 `json:"datasources,omitempty"` Datasources map[string]int64 `json:"datasources,omitempty"`
HubItems HubItems `json:"hub_items,omitempty"` HubItems HubItems `json:"hub_items,omitempty"`
LastPush int64 `json:"last_push,omitempty"`
Name string `json:"name,omitempty"`
} }
dataAO1.ConsoleOptions = m.ConsoleOptions dataAO1.ConsoleOptions = m.ConsoleOptions
@ -153,6 +171,10 @@ func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) {
dataAO1.HubItems = m.HubItems dataAO1.HubItems = m.HubItems
dataAO1.LastPush = m.LastPush
dataAO1.Name = m.Name
jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
if errAO1 != nil { if errAO1 != nil {
return nil, errAO1 return nil, errAO1

View file

@ -90,6 +90,12 @@ func (m RemediationComponentsMetrics) ContextValidate(ctx context.Context, forma
type RemediationComponentsMetricsItems0 struct { type RemediationComponentsMetricsItems0 struct {
BaseMetrics BaseMetrics
// last pull date
LastPull int64 `json:"last_pull,omitempty"`
// name of the remediation component
Name string `json:"name,omitempty"`
// type of the remediation component // type of the remediation component
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }
@ -105,12 +111,20 @@ func (m *RemediationComponentsMetricsItems0) UnmarshalJSON(raw []byte) error {
// AO1 // AO1
var dataAO1 struct { var dataAO1 struct {
LastPull int64 `json:"last_pull,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }
if err := swag.ReadJSON(raw, &dataAO1); err != nil { if err := swag.ReadJSON(raw, &dataAO1); err != nil {
return err return err
} }
m.LastPull = dataAO1.LastPull
m.Name = dataAO1.Name
m.Type = dataAO1.Type m.Type = dataAO1.Type
return nil return nil
@ -126,9 +140,17 @@ func (m RemediationComponentsMetricsItems0) MarshalJSON() ([]byte, error) {
} }
_parts = append(_parts, aO0) _parts = append(_parts, aO0)
var dataAO1 struct { var dataAO1 struct {
LastPull int64 `json:"last_pull,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }
dataAO1.LastPull = m.LastPull
dataAO1.Name = m.Name
dataAO1.Type = m.Type dataAO1.Type = m.Type
jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)