diff --git a/pkg/apiserver/apic_metrics.go b/pkg/apiserver/apic_metrics.go index dc1af6080..ab13a69fe 100644 --- a/pkg/apiserver/apic_metrics.go +++ b/pkg/apiserver/apic_metrics.go @@ -3,7 +3,6 @@ package apiserver import ( "context" "encoding/json" - "fmt" "strings" "time" @@ -76,6 +75,9 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) { metrics.FeatureFlags = strings.Split(lp.Featureflags, ",") metrics.Version = &lp.Version + metrics.Name = lpName + metrics.LastPush = lp.LastPush.UTC().Unix() + allMetrics.LogProcessors = append(allMetrics.LogProcessors, models.LogProcessorsMetrics{&metrics}) metricsIds = append(metricsIds, lpsMetric.ID) } @@ -109,6 +111,8 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) { metrics.Type = bouncer.Type metrics.FeatureFlags = strings.Split(bouncer.Featureflags, ",") metrics.Version = &bouncer.Version + metrics.Name = bouncerName + metrics.LastPull = bouncer.LastPull.UTC().Unix() allMetrics.RemediationComponents = append(allMetrics.RemediationComponents, models.RemediationComponentsMetrics{&metrics}) metricsIds = append(metricsIds, bouncersMetric.ID) @@ -288,15 +292,21 @@ func (a *apic) SendUsageMetrics() { if err != nil { log.Errorf("unable to get usage metrics (%s)", err) } - jsonStr, err := json.Marshal(metrics) + /*jsonStr, err := json.Marshal(metrics) if err != nil { log.Errorf("unable to marshal usage metrics (%s)", err) - } - fmt.Printf("Usage metrics: %s\n", string(jsonStr)) - //TODO: actually send the data - err = a.MarkUsageMetricsAsSent(metricsId) + }*/ + //fmt.Printf("Usage metrics: %s\n", string(jsonStr)) + _, _, err = a.apiClient.UsageMetrics.Add(context.Background(), metrics) + 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) + } } } } diff --git a/pkg/models/localapi_swagger.yaml b/pkg/models/localapi_swagger.yaml index 1d99389c3..4485490ee 100644 --- a/pkg/models/localapi_swagger.yaml +++ b/pkg/models/localapi_swagger.yaml @@ -1036,6 +1036,12 @@ definitions: type: type: string description: type of the remediation component + name: + type: string + description: name of the remediation component + last_pull: + type: integer + description: last pull date LogProcessorsMetrics: title: LogProcessorsMetrics type: array @@ -1054,6 +1060,12 @@ definitions: description: Number of datasources per type additionalProperties: type: integer + name: + type: string + description: name of the log processor + last_push: + type: integer + description: last push date AllMetrics: title: AllMetrics type: object diff --git a/pkg/models/log_processors_metrics.go b/pkg/models/log_processors_metrics.go index 197c215a4..f605e4ea4 100644 --- a/pkg/models/log_processors_metrics.go +++ b/pkg/models/log_processors_metrics.go @@ -98,6 +98,12 @@ type LogProcessorsMetricsItems0 struct { // hub items 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 @@ -116,6 +122,10 @@ func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error { Datasources map[string]int64 `json:"datasources,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 { return err @@ -127,6 +137,10 @@ func (m *LogProcessorsMetricsItems0) UnmarshalJSON(raw []byte) error { m.HubItems = dataAO1.HubItems + m.LastPush = dataAO1.LastPush + + m.Name = dataAO1.Name + return nil } @@ -145,6 +159,10 @@ func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) { Datasources map[string]int64 `json:"datasources,omitempty"` HubItems HubItems `json:"hub_items,omitempty"` + + LastPush int64 `json:"last_push,omitempty"` + + Name string `json:"name,omitempty"` } dataAO1.ConsoleOptions = m.ConsoleOptions @@ -153,6 +171,10 @@ func (m LogProcessorsMetricsItems0) MarshalJSON() ([]byte, error) { dataAO1.HubItems = m.HubItems + dataAO1.LastPush = m.LastPush + + dataAO1.Name = m.Name + jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1) if errAO1 != nil { return nil, errAO1 diff --git a/pkg/models/remediation_components_metrics.go b/pkg/models/remediation_components_metrics.go index 5506558c1..f3b5a0839 100644 --- a/pkg/models/remediation_components_metrics.go +++ b/pkg/models/remediation_components_metrics.go @@ -90,6 +90,12 @@ func (m RemediationComponentsMetrics) ContextValidate(ctx context.Context, forma type RemediationComponentsMetricsItems0 struct { 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 string `json:"type,omitempty"` } @@ -105,12 +111,20 @@ func (m *RemediationComponentsMetricsItems0) UnmarshalJSON(raw []byte) error { // AO1 var dataAO1 struct { + LastPull int64 `json:"last_pull,omitempty"` + + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` } if err := swag.ReadJSON(raw, &dataAO1); err != nil { return err } + m.LastPull = dataAO1.LastPull + + m.Name = dataAO1.Name + m.Type = dataAO1.Type return nil @@ -126,9 +140,17 @@ func (m RemediationComponentsMetricsItems0) MarshalJSON() ([]byte, error) { } _parts = append(_parts, aO0) var dataAO1 struct { + LastPull int64 `json:"last_pull,omitempty"` + + Name string `json:"name,omitempty"` + Type string `json:"type,omitempty"` } + dataAO1.LastPull = m.LastPull + + dataAO1.Name = m.Name + dataAO1.Type = m.Type jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)