Fix dmcache tests with 32bit int

(cherry picked from commit ef5c12bd86)
This commit is contained in:
Daniel Nelson 2017-09-25 15:49:36 -07:00
parent 761ea06d6a
commit 293b1a0093
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
2 changed files with 84 additions and 84 deletions

View File

@ -16,21 +16,21 @@ const metricName = "dmcache"
type cacheStatus struct { type cacheStatus struct {
device string device string
length int length int64
target string target string
metadataBlocksize int metadataBlocksize int64
metadataUsed int metadataUsed int64
metadataTotal int metadataTotal int64
cacheBlocksize int cacheBlocksize int64
cacheUsed int cacheUsed int64
cacheTotal int cacheTotal int64
readHits int readHits int64
readMisses int readMisses int64
writeHits int writeHits int64
writeMisses int writeMisses int64
demotions int demotions int64
promotions int promotions int64
dirty int dirty int64
} }
func (c *DMCache) Gather(acc telegraf.Accumulator) error { func (c *DMCache) Gather(acc telegraf.Accumulator) error {
@ -69,12 +69,12 @@ func parseDMSetupStatus(line string) (cacheStatus, error) {
} }
status.device = strings.TrimRight(values[0], ":") status.device = strings.TrimRight(values[0], ":")
status.length, err = strconv.Atoi(values[2]) status.length, err = strconv.ParseInt(values[2], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.target = values[3] status.target = values[3]
status.metadataBlocksize, err = strconv.Atoi(values[4]) status.metadataBlocksize, err = strconv.ParseInt(values[4], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
@ -82,15 +82,15 @@ func parseDMSetupStatus(line string) (cacheStatus, error) {
if len(metadata) != 2 { if len(metadata) != 2 {
return cacheStatus{}, parseError return cacheStatus{}, parseError
} }
status.metadataUsed, err = strconv.Atoi(metadata[0]) status.metadataUsed, err = strconv.ParseInt(metadata[0], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.metadataTotal, err = strconv.Atoi(metadata[1]) status.metadataTotal, err = strconv.ParseInt(metadata[1], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.cacheBlocksize, err = strconv.Atoi(values[6]) status.cacheBlocksize, err = strconv.ParseInt(values[6], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
@ -98,39 +98,39 @@ func parseDMSetupStatus(line string) (cacheStatus, error) {
if len(cache) != 2 { if len(cache) != 2 {
return cacheStatus{}, parseError return cacheStatus{}, parseError
} }
status.cacheUsed, err = strconv.Atoi(cache[0]) status.cacheUsed, err = strconv.ParseInt(cache[0], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.cacheTotal, err = strconv.Atoi(cache[1]) status.cacheTotal, err = strconv.ParseInt(cache[1], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.readHits, err = strconv.Atoi(values[8]) status.readHits, err = strconv.ParseInt(values[8], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.readMisses, err = strconv.Atoi(values[9]) status.readMisses, err = strconv.ParseInt(values[9], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.writeHits, err = strconv.Atoi(values[10]) status.writeHits, err = strconv.ParseInt(values[10], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.writeMisses, err = strconv.Atoi(values[11]) status.writeMisses, err = strconv.ParseInt(values[11], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.demotions, err = strconv.Atoi(values[12]) status.demotions, err = strconv.ParseInt(values[12], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.promotions, err = strconv.Atoi(values[13]) status.promotions, err = strconv.ParseInt(values[13], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }
status.dirty, err = strconv.Atoi(values[14]) status.dirty, err = strconv.ParseInt(values[14], 10, 64)
if err != nil { if err != nil {
return cacheStatus{}, err return cacheStatus{}, err
} }

View File

@ -35,20 +35,20 @@ func TestPerDeviceGoodOutput(t *testing.T) {
"device": "cs-1", "device": "cs-1",
} }
fields1 := map[string]interface{}{ fields1 := map[string]interface{}{
"length": 4883791872, "length": int64(4883791872),
"metadata_blocksize": 8, "metadata_blocksize": int64(8),
"metadata_used": 1018, "metadata_used": int64(1018),
"metadata_total": 1501122, "metadata_total": int64(1501122),
"cache_blocksize": 512, "cache_blocksize": int64(512),
"cache_used": 7, "cache_used": int64(7),
"cache_total": 464962, "cache_total": int64(464962),
"read_hits": 139, "read_hits": int64(139),
"read_misses": 352643, "read_misses": int64(352643),
"write_hits": 15, "write_hits": int64(15),
"write_misses": 46, "write_misses": int64(46),
"demotions": 0, "demotions": int64(0),
"promotions": 7, "promotions": int64(7),
"dirty": 0, "dirty": int64(0),
} }
acc.AssertContainsTaggedFields(t, measurement, fields1, tags1) acc.AssertContainsTaggedFields(t, measurement, fields1, tags1)
@ -56,20 +56,20 @@ func TestPerDeviceGoodOutput(t *testing.T) {
"device": "cs-2", "device": "cs-2",
} }
fields2 := map[string]interface{}{ fields2 := map[string]interface{}{
"length": 4294967296, "length": int64(4294967296),
"metadata_blocksize": 8, "metadata_blocksize": int64(8),
"metadata_used": 72352, "metadata_used": int64(72352),
"metadata_total": 1310720, "metadata_total": int64(1310720),
"cache_blocksize": 128, "cache_blocksize": int64(128),
"cache_used": 26, "cache_used": int64(26),
"cache_total": 24327168, "cache_total": int64(24327168),
"read_hits": 2409, "read_hits": int64(2409),
"read_misses": 286, "read_misses": int64(286),
"write_hits": 265, "write_hits": int64(265),
"write_misses": 524682, "write_misses": int64(524682),
"demotions": 0, "demotions": int64(0),
"promotions": 0, "promotions": int64(0),
"dirty": 0, "dirty": int64(0),
} }
acc.AssertContainsTaggedFields(t, measurement, fields2, tags2) acc.AssertContainsTaggedFields(t, measurement, fields2, tags2)
@ -78,20 +78,20 @@ func TestPerDeviceGoodOutput(t *testing.T) {
} }
fields3 := map[string]interface{}{ fields3 := map[string]interface{}{
"length": 9178759168, "length": int64(9178759168),
"metadata_blocksize": 16, "metadata_blocksize": int64(16),
"metadata_used": 73370, "metadata_used": int64(73370),
"metadata_total": 2811842, "metadata_total": int64(2811842),
"cache_blocksize": 640, "cache_blocksize": int64(640),
"cache_used": 33, "cache_used": int64(33),
"cache_total": 24792130, "cache_total": int64(24792130),
"read_hits": 2548, "read_hits": int64(2548),
"read_misses": 352929, "read_misses": int64(352929),
"write_hits": 280, "write_hits": int64(280),
"write_misses": 524728, "write_misses": int64(524728),
"demotions": 0, "demotions": int64(0),
"promotions": 7, "promotions": int64(7),
"dirty": 0, "dirty": int64(0),
} }
acc.AssertContainsTaggedFields(t, measurement, fields3, tags3) acc.AssertContainsTaggedFields(t, measurement, fields3, tags3)
} }
@ -113,20 +113,20 @@ func TestNotPerDeviceGoodOutput(t *testing.T) {
} }
fields := map[string]interface{}{ fields := map[string]interface{}{
"length": 9178759168, "length": int64(9178759168),
"metadata_blocksize": 16, "metadata_blocksize": int64(16),
"metadata_used": 73370, "metadata_used": int64(73370),
"metadata_total": 2811842, "metadata_total": int64(2811842),
"cache_blocksize": 640, "cache_blocksize": int64(640),
"cache_used": 33, "cache_used": int64(33),
"cache_total": 24792130, "cache_total": int64(24792130),
"read_hits": 2548, "read_hits": int64(2548),
"read_misses": 352929, "read_misses": int64(352929),
"write_hits": 280, "write_hits": int64(280),
"write_misses": 524728, "write_misses": int64(524728),
"demotions": 0, "demotions": int64(0),
"promotions": 7, "promotions": int64(7),
"dirty": 0, "dirty": int64(0),
} }
acc.AssertContainsTaggedFields(t, measurement, fields, tags) acc.AssertContainsTaggedFields(t, measurement, fields, tags)
} }