summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-10-15 11:18:32 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-10-15 11:18:32 +0200
commit9bf7175a26f29a8c0133883152afb98765edd8ca (patch)
treeaa64e0df83a9e1f50cc2971884d4ed5576ab0ca0 /core
parent454aff1907d87c79ffb11e151e25953241c7f1be (diff)
fix: Add guards for converting Stat interface (might be nil)
Change-Id: I54cd9ca6fb6607a70031ba5e6318a9ea58db7e6c Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'core')
-rw-r--r--core/stats.go61
1 files changed, 33 insertions, 28 deletions
diff --git a/core/stats.go b/core/stats.go
index 23b3848..2a9e964 100644
--- a/core/stats.go
+++ b/core/stats.go
@@ -166,7 +166,7 @@ func (c *StatsConnection) updateStats(statDir **adapter.StatDir, patterns ...str
} else if err == adapter.ErrStatsDirStale || err == adapter.ErrStatsDataBusy {
// retrying
if r > 1 {
- log.Debugln("sleeping for %v before next try", RetryUpdateDelay)
+ log.Debugf("sleeping for %v before next try", RetryUpdateDelay)
time.Sleep(RetryUpdateDelay)
}
} else {
@@ -255,23 +255,25 @@ func (c *StatsConnection) GetNodeStats(nodeStats *api.NodeStats) (err error) {
}
}
perNode := func(stat adapter.StatEntry, fn func(*api.NodeCounters, uint64)) {
- s := stat.Data.(adapter.SimpleCounterStat)
- prepNodes(len(s[0]))
- for i := range nodeStats.Nodes {
- val := adapter.ReduceSimpleCounterStatIndex(s, i)
- fn(&nodeStats.Nodes[i], val)
+ if s, ok := stat.Data.(adapter.SimpleCounterStat); ok {
+ prepNodes(len(s[0]))
+ for i := range nodeStats.Nodes {
+ val := adapter.ReduceSimpleCounterStatIndex(s, i)
+ fn(&nodeStats.Nodes[i], val)
+ }
}
}
for _, stat := range c.nodeStatsData.Entries {
switch string(stat.Name) {
case NodeStats_Names:
- stat := stat.Data.(adapter.NameStat)
- prepNodes(len(stat))
- for i, nc := range nodeStats.Nodes {
- if nc.NodeName != string(stat[i]) {
- nc.NodeName = string(stat[i])
- nodeStats.Nodes[i] = nc
+ if stat, ok := stat.Data.(adapter.NameStat); ok {
+ prepNodes(len(stat))
+ for i, nc := range nodeStats.Nodes {
+ if nc.NodeName != string(stat[i]) {
+ nc.NodeName = string(stat[i])
+ nodeStats.Nodes[i] = nc
+ }
}
}
case NodeStats_Clocks:
@@ -311,31 +313,34 @@ func (c *StatsConnection) GetInterfaceStats(ifaceStats *api.InterfaceStats) (err
}
}
perNode := func(stat adapter.StatEntry, fn func(*api.InterfaceCounters, uint64)) {
- s := stat.Data.(adapter.SimpleCounterStat)
- prep(len(s[0]))
- for i := range ifaceStats.Interfaces {
- val := adapter.ReduceSimpleCounterStatIndex(s, i)
- fn(&ifaceStats.Interfaces[i], val)
+ if s, ok := stat.Data.(adapter.SimpleCounterStat); ok {
+ prep(len(s[0]))
+ for i := range ifaceStats.Interfaces {
+ val := adapter.ReduceSimpleCounterStatIndex(s, i)
+ fn(&ifaceStats.Interfaces[i], val)
+ }
}
}
perNodeComb := func(stat adapter.StatEntry, fn func(*api.InterfaceCounters, [2]uint64)) {
- s := stat.Data.(adapter.CombinedCounterStat)
- prep(len(s[0]))
- for i := range ifaceStats.Interfaces {
- val := adapter.ReduceCombinedCounterStatIndex(s, i)
- fn(&ifaceStats.Interfaces[i], val)
+ if s, ok := stat.Data.(adapter.CombinedCounterStat); ok {
+ prep(len(s[0]))
+ for i := range ifaceStats.Interfaces {
+ val := adapter.ReduceCombinedCounterStatIndex(s, i)
+ fn(&ifaceStats.Interfaces[i], val)
+ }
}
}
for _, stat := range c.ifaceStatsData.Entries {
switch string(stat.Name) {
case InterfaceStats_Names:
- stat := stat.Data.(adapter.NameStat)
- prep(len(stat))
- for i, nc := range ifaceStats.Interfaces {
- if nc.InterfaceName != string(stat[i]) {
- nc.InterfaceName = string(stat[i])
- ifaceStats.Interfaces[i] = nc
+ if stat, ok := stat.Data.(adapter.NameStat); ok {
+ prep(len(stat))
+ for i, nc := range ifaceStats.Interfaces {
+ if nc.InterfaceName != string(stat[i]) {
+ nc.InterfaceName = string(stat[i])
+ ifaceStats.Interfaces[i] = nc
+ }
}
}
case InterfaceStats_Drops: