type check

This commit is contained in:
Nan Deng 2014-07-02 16:20:05 -07:00
parent 84fefcdab9
commit 4115f73343

View File

@ -193,9 +193,13 @@ func (self *influxdbStorage) valuesToContainerStats(columns []string, values []i
stats.Timestamp, err = time.Parse(time.RFC3339Nano, str) stats.Timestamp, err = time.Parse(time.RFC3339Nano, str)
} }
case col == colMachineName: case col == colMachineName:
if v.(string) != self.machineName { if m, ok := v.(string); ok {
if m != self.machineName {
return nil, fmt.Errorf("different machine") return nil, fmt.Errorf("different machine")
} }
} else {
return nil, fmt.Errorf("machine name field is not a string: %v", v)
}
// Cumulative Cpu Usage // Cumulative Cpu Usage
case col == colCpuCumulativeUsage: case col == colCpuCumulativeUsage:
stats.Cpu.Usage.Total, err = convertToUint64(v) stats.Cpu.Usage.Total, err = convertToUint64(v)
@ -254,9 +258,13 @@ func (self *influxdbStorage) valuesToContainerSample(columns []string, values []
sample.Timestamp, err = time.Parse(time.RFC3339Nano, str) sample.Timestamp, err = time.Parse(time.RFC3339Nano, str)
} }
case col == colMachineName: case col == colMachineName:
if v.(string) != self.machineName { if m, ok := v.(string); ok {
if m != self.machineName {
return nil, fmt.Errorf("different machine") return nil, fmt.Errorf("different machine")
} }
} else {
return nil, fmt.Errorf("machine name field is not a string: %v", v)
}
// Memory Usage // Memory Usage
case col == colMemoryUsage: case col == colMemoryUsage:
sample.Memory.Usage, err = convertToUint64(v) sample.Memory.Usage, err = convertToUint64(v)