Fix crash in stats for removed interfaces/nodes 28/18928/1
authorOndrej Fabry <ofabry@cisco.com>
Tue, 16 Apr 2019 13:13:18 +0000 (15:13 +0200)
committerOndrej Fabry <ofabry@cisco.com>
Tue, 16 Apr 2019 13:13:18 +0000 (15:13 +0200)
Change-Id: I36b4cd2625c7f0c5846fe402be7b2aeece4707f8
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
adapter/vppapiclient/stat_client.go
core/stats.go

index a2a9826..55705bd 100644 (file)
@@ -285,10 +285,11 @@ func (c *statClient) DumpStats(patterns ...string) (stats []*adapter.StatEntry,
                        var vector []adapter.Name
                        for k := 0; k < length; k++ {
                                s := C.govpp_stat_segment_data_get_name_vector_index(&v, C.int(k))
-                               if s == nil {
-                                       continue
+                               var name adapter.Name
+                               if s != nil {
+                                       name = adapter.Name(C.GoString(s))
                                }
-                               vector = append(vector, adapter.Name(C.GoString(s)))
+                               vector = append(vector, name)
                        }
                        stat.Data = adapter.NameStat(vector)
 
index 4cbd9f2..48b516c 100644 (file)
@@ -196,6 +196,9 @@ func (c *StatsConnection) GetNodeStats() (*api.NodeStats, error) {
                        }
                }
                for i, v := range perNode {
+                       if len(nodeStats.Nodes) <= i {
+                               break
+                       }
                        nodeCounters := nodeStats.Nodes[i]
                        fn(&nodeCounters, v)
                        nodeStats.Nodes[i] = nodeCounters
@@ -257,6 +260,9 @@ func (c *StatsConnection) GetInterfaceStats() (*api.InterfaceStats, error) {
                        }
                }
                for i, v := range perIf {
+                       if len(ifStats.Interfaces) <= i {
+                               break
+                       }
                        ifCounters := ifStats.Interfaces[i]
                        fn(&ifCounters, v)
                        ifStats.Interfaces[i] = ifCounters