Skip to content

Commit

Permalink
force rfc 3339 date format in metrics push (#2402)
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus authored Nov 28, 2023
1 parent 05c1825 commit 380cbf7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions pkg/apiserver/apic_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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 sending metrics to CrowdSec Central API (interval: %s once, then %s)",
metInts[1].Round(time.Second), metInts[2])
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions pkg/apiserver/apic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand Down

0 comments on commit 380cbf7

Please sign in to comment.