Sfoglia il codice sorgente

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

blotus 3 anni fa
parent
commit
19323ba4aa
1 ha cambiato i file con 7 aggiunte e 1 eliminazioni
  1. 7 1
      pkg/apiserver/apic.go

+ 7 - 1
pkg/apiserver/apic.go

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