From d70b40c310cf4b0a85e34df932b12501b5d7d373 Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Wed, 2 Aug 2023 17:48:45 +0200 Subject: [PATCH 1/2] force rfc3339 date format in metrics push --- pkg/apiserver/apic_metrics.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/apiserver/apic_metrics.go b/pkg/apiserver/apic_metrics.go index cfaf7914788..493129a577e 100644 --- a/pkg/apiserver/apic_metrics.go +++ b/pkg/apiserver/apic_metrics.go @@ -26,8 +26,8 @@ func (a *apic) GetMetrics() (*models.Metrics, error) { machinesInfo[i] = &models.MetricsAgentInfo{ Version: machine.Version, Name: machine.MachineId, - LastUpdate: machine.UpdatedAt.String(), - LastPush: ptr.OrEmpty(machine.LastPush).String(), + LastUpdate: machine.UpdatedAt.Format(time.RFC3339), + LastPush: ptr.OrEmpty(machine.LastPush).Format(time.RFC3339), } } @@ -43,7 +43,7 @@ func (a *apic) GetMetrics() (*models.Metrics, error) { Version: bouncer.Version, CustomName: bouncer.Name, Name: bouncer.Type, - LastPull: bouncer.LastPull.String(), + LastPull: bouncer.LastPull.Format(time.RFC3339), } } @@ -81,7 +81,7 @@ func (a *apic) SendMetrics(stop chan (bool)) { const checkInt = 20 * time.Second // intervals must always be > 0 - metInts := []time.Duration{1*time.Millisecond, a.metricsIntervalFirst, a.metricsInterval} + metInts := []time.Duration{1 * time.Millisecond, a.metricsIntervalFirst, a.metricsInterval} log.Infof("Start send metrics to CrowdSec Central API (interval: %s once, then %s)", metInts[1].Round(time.Second), metInts[2]) @@ -123,7 +123,7 @@ func (a *apic) SendMetrics(stop chan (bool)) { reloadMachineIDs() if !slices.Equal(oldIDs, machineIDs) { log.Infof("capi metrics: machines changed, immediate send") - metTicker.Reset(1*time.Millisecond) + metTicker.Reset(1 * time.Millisecond) } case <-metTicker.C: metTicker.Stop() From 384022492d2488ed17497fd17e45e79270eda86d Mon Sep 17 00:00:00 2001 From: Sebastien Blot Date: Tue, 28 Nov 2023 16:17:11 +0100 Subject: [PATCH 2/2] fix tests --- pkg/apiserver/apic_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/apiserver/apic_test.go b/pkg/apiserver/apic_test.go index 7d7a5e0152c..97127cad07c 100644 --- a/pkg/apiserver/apic_test.go +++ b/pkg/apiserver/apic_test.go @@ -309,30 +309,30 @@ func TestAPICGetMetrics(t *testing.T) { Bouncers: []*models.MetricsBouncerInfo{ { CustomName: "1", - LastPull: time.Time{}.String(), + LastPull: time.Time{}.Format(time.RFC3339), }, { CustomName: "2", - LastPull: time.Time{}.String(), + LastPull: time.Time{}.Format(time.RFC3339), }, { CustomName: "3", - LastPull: time.Time{}.String(), + LastPull: time.Time{}.Format(time.RFC3339), }, }, Machines: []*models.MetricsAgentInfo{ { Name: "a", - LastPush: time.Time{}.String(), - LastUpdate: time.Time{}.String(), + LastPush: time.Time{}.Format(time.RFC3339), + LastUpdate: time.Time{}.Format(time.RFC3339), }, { Name: "b", - LastPush: time.Time{}.String(), - LastUpdate: time.Time{}.String(), + LastPush: time.Time{}.Format(time.RFC3339), + LastUpdate: time.Time{}.Format(time.RFC3339), }, { Name: "c", - LastPush: time.Time{}.String(), - LastUpdate: time.Time{}.String(), + LastPush: time.Time{}.Format(time.RFC3339), + LastUpdate: time.Time{}.Format(time.RFC3339), }, }, },