fix crash on upgrade with nil last push field (#1191)

This commit is contained in:
blotus 2022-01-20 09:10:40 -08:00 committed by GitHub
parent 363abafe4b
commit 19323ba4aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -510,12 +510,18 @@ func (a *apic) GetMetrics() (*models.Metrics, error) {
if err != nil {
return metric, err
}
var lastpush string
for _, machine := range machines {
if machine.LastPush == nil {
lastpush = time.Time{}.String()
} else {
lastpush = machine.LastPush.String()
}
m := &models.MetricsAgentInfo{
Version: machine.Version,
Name: machine.MachineId,
LastUpdate: machine.UpdatedAt.String(),
LastPush: machine.LastPush.String(),
LastPush: lastpush,
}
metric.Machines = append(metric.Machines, m)
}