From 2bd58ee4df3a5376479f2a9d2ec0902bef4e5cbd Mon Sep 17 00:00:00 2001 From: Evan Phoenix Date: Tue, 26 May 2015 22:14:55 -0700 Subject: [PATCH] A set of fixes to fix the tests --- plugins/mysql/mysql_test.go | 6 +- plugins/redis/redis_test.go | 2 +- plugins/system/net.go | 3 +- plugins/system/system_test.go | 184 +++++++++++++++++----------------- 4 files changed, 97 insertions(+), 98 deletions(-) diff --git a/plugins/mysql/mysql_test.go b/plugins/mysql/mysql_test.go index 0e9e94a23..33643861a 100644 --- a/plugins/mysql/mysql_test.go +++ b/plugins/mysql/mysql_test.go @@ -11,11 +11,7 @@ import ( func TestMysqlGeneratesMetrics(t *testing.T) { m := &Mysql{ - Servers: []*Server{ - { - Address: "", - }, - }, + Servers: []string{""}, } var acc testutil.Accumulator diff --git a/plugins/redis/redis_test.go b/plugins/redis/redis_test.go index cab691d35..52f3c9b62 100644 --- a/plugins/redis/redis_test.go +++ b/plugins/redis/redis_test.go @@ -43,7 +43,7 @@ func TestRedisGeneratesMetrics(t *testing.T) { addr := l.Addr().String() r := &Redis{ - Address: addr, + Servers: []string{addr}, } var acc testutil.Accumulator diff --git a/plugins/system/net.go b/plugins/system/net.go index ec419d9ee..014b01ea9 100644 --- a/plugins/system/net.go +++ b/plugins/system/net.go @@ -10,6 +10,7 @@ import ( type NetIOStats struct { ps PS + skipChecks bool Interfaces []string } @@ -49,7 +50,7 @@ func (s *NetIOStats) Gather(acc plugins.Accumulator) error { if !found { continue } - } else { + } else if !s.skipChecks { iface, err := net.InterfaceByName(io.Name) if err != nil { continue diff --git a/plugins/system/system_test.go b/plugins/system/system_test.go index 83242020a..b8e0e169c 100644 --- a/plugins/system/system_test.go +++ b/plugins/system/system_test.go @@ -166,9 +166,9 @@ func TestSystemStats_GenerateStats(t *testing.T) { err := ss.Gather(&acc) require.NoError(t, err) - assert.True(t, acc.CheckValue("system_load1", 0.3)) - assert.True(t, acc.CheckValue("system_load5", 1.5)) - assert.True(t, acc.CheckValue("system_load15", 0.8)) + assert.True(t, acc.CheckValue("load1", 0.3)) + assert.True(t, acc.CheckValue("load5", 1.5)) + assert.True(t, acc.CheckValue("load15", 0.8)) cs := &CPUStats{ps: &mps} @@ -179,17 +179,17 @@ func TestSystemStats_GenerateStats(t *testing.T) { err = cs.Gather(&acc) require.NoError(t, err) - assert.True(t, acc.CheckTaggedValue("cpu_user", 3.1, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_system", 8.2, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_idle", 80.1, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_nice", 1.3, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_iowait", 0.2, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_irq", 0.1, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_softirq", 0.11, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_steal", 0.0001, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_guest", 8.1, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_guestNice", 0.324, cputags)) - assert.True(t, acc.CheckTaggedValue("cpu_stolen", 0.051, cputags)) + assert.True(t, acc.CheckTaggedValue("user", 3.1, cputags)) + assert.True(t, acc.CheckTaggedValue("system", 8.2, cputags)) + assert.True(t, acc.CheckTaggedValue("idle", 80.1, cputags)) + assert.True(t, acc.CheckTaggedValue("nice", 1.3, cputags)) + assert.True(t, acc.CheckTaggedValue("iowait", 0.2, cputags)) + assert.True(t, acc.CheckTaggedValue("irq", 0.1, cputags)) + assert.True(t, acc.CheckTaggedValue("softirq", 0.11, cputags)) + assert.True(t, acc.CheckTaggedValue("steal", 0.0001, cputags)) + assert.True(t, acc.CheckTaggedValue("guest", 8.1, cputags)) + assert.True(t, acc.CheckTaggedValue("guestNice", 0.324, cputags)) + assert.True(t, acc.CheckTaggedValue("stolen", 0.051, cputags)) err = (&DiskStats{&mps}).Gather(&acc) require.NoError(t, err) @@ -198,28 +198,28 @@ func TestSystemStats_GenerateStats(t *testing.T) { "path": "/", } - assert.True(t, acc.CheckTaggedValue("disk_total", uint64(128), tags)) - assert.True(t, acc.CheckTaggedValue("disk_used", uint64(105), tags)) - assert.True(t, acc.CheckTaggedValue("disk_free", uint64(23), tags)) - assert.True(t, acc.CheckTaggedValue("disk_inodes_total", uint64(1234), tags)) - assert.True(t, acc.CheckTaggedValue("disk_inodes_free", uint64(234), tags)) - assert.True(t, acc.CheckTaggedValue("disk_inodes_used", uint64(1000), tags)) + assert.True(t, acc.CheckTaggedValue("total", uint64(128), tags)) + assert.True(t, acc.CheckTaggedValue("used", uint64(105), tags)) + assert.True(t, acc.CheckTaggedValue("free", uint64(23), tags)) + assert.True(t, acc.CheckTaggedValue("inodes_total", uint64(1234), tags)) + assert.True(t, acc.CheckTaggedValue("inodes_free", uint64(234), tags)) + assert.True(t, acc.CheckTaggedValue("inodes_used", uint64(1000), tags)) - err = (&NetIOStats{&mps}).Gather(&acc) + err = (&NetIOStats{ps: &mps, skipChecks: true}).Gather(&acc) require.NoError(t, err) ntags := map[string]string{ "interface": "eth0", } - assert.True(t, acc.CheckTaggedValue("net_bytes_sent", uint64(1123), ntags)) - assert.True(t, acc.CheckTaggedValue("net_bytes_recv", uint64(8734422), ntags)) - assert.True(t, acc.CheckTaggedValue("net_packets_sent", uint64(781), ntags)) - assert.True(t, acc.CheckTaggedValue("net_packets_recv", uint64(23456), ntags)) - assert.True(t, acc.CheckTaggedValue("net_err_in", uint64(832), ntags)) - assert.True(t, acc.CheckTaggedValue("net_err_out", uint64(8), ntags)) - assert.True(t, acc.CheckTaggedValue("net_drop_in", uint64(7), ntags)) - assert.True(t, acc.CheckTaggedValue("net_drop_out", uint64(1), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("bytes_sent", uint64(1123), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("bytes_recv", uint64(8734422), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("packets_sent", uint64(781), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("packets_recv", uint64(23456), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("err_in", uint64(832), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("err_out", uint64(8), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("drop_in", uint64(7), ntags)) + assert.NoError(t, acc.ValidateTaggedValue("drop_out", uint64(1), ntags)) err = (&DiskIOStats{&mps}).Gather(&acc) require.NoError(t, err) @@ -229,42 +229,44 @@ func TestSystemStats_GenerateStats(t *testing.T) { "serial": "ab-123-ad", } - assert.True(t, acc.CheckTaggedValue("io_reads", uint64(888), dtags)) - assert.True(t, acc.CheckTaggedValue("io_writes", uint64(5341), dtags)) - assert.True(t, acc.CheckTaggedValue("io_read_bytes", uint64(100000), dtags)) - assert.True(t, acc.CheckTaggedValue("io_write_bytes", uint64(200000), dtags)) - assert.True(t, acc.CheckTaggedValue("io_read_time", uint64(7123), dtags)) - assert.True(t, acc.CheckTaggedValue("io_write_time", uint64(9087), dtags)) - assert.True(t, acc.CheckTaggedValue("io_io_time", uint64(123552), dtags)) + assert.True(t, acc.CheckTaggedValue("reads", uint64(888), dtags)) + assert.True(t, acc.CheckTaggedValue("writes", uint64(5341), dtags)) + assert.True(t, acc.CheckTaggedValue("read_bytes", uint64(100000), dtags)) + assert.True(t, acc.CheckTaggedValue("write_bytes", uint64(200000), dtags)) + assert.True(t, acc.CheckTaggedValue("read_time", uint64(7123), dtags)) + assert.True(t, acc.CheckTaggedValue("write_time", uint64(9087), dtags)) + assert.True(t, acc.CheckTaggedValue("io_time", uint64(123552), dtags)) err = (&MemStats{&mps}).Gather(&acc) require.NoError(t, err) vmtags := map[string]string(nil) - assert.True(t, acc.CheckTaggedValue("mem_total", uint64(12400), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_available", uint64(7600), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_used", uint64(5000), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_used_prec", float64(47.1), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_free", uint64(1235), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_active", uint64(8134), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_inactive", uint64(1124), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_buffers", uint64(771), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_cached", uint64(4312), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_wired", uint64(134), vmtags)) - assert.True(t, acc.CheckTaggedValue("mem_shared", uint64(2142), vmtags)) + assert.True(t, acc.CheckTaggedValue("total", uint64(12400), vmtags)) + assert.True(t, acc.CheckTaggedValue("available", uint64(7600), vmtags)) + assert.True(t, acc.CheckTaggedValue("used", uint64(5000), vmtags)) + assert.True(t, acc.CheckTaggedValue("used_prec", float64(47.1), vmtags)) + assert.True(t, acc.CheckTaggedValue("free", uint64(1235), vmtags)) + assert.True(t, acc.CheckTaggedValue("active", uint64(8134), vmtags)) + assert.True(t, acc.CheckTaggedValue("inactive", uint64(1124), vmtags)) + assert.True(t, acc.CheckTaggedValue("buffers", uint64(771), vmtags)) + assert.True(t, acc.CheckTaggedValue("cached", uint64(4312), vmtags)) + assert.True(t, acc.CheckTaggedValue("wired", uint64(134), vmtags)) + assert.True(t, acc.CheckTaggedValue("shared", uint64(2142), vmtags)) + + acc.Points = nil err = (&SwapStats{&mps}).Gather(&acc) require.NoError(t, err) swaptags := map[string]string(nil) - assert.True(t, acc.CheckTaggedValue("swap_total", uint64(8123), swaptags)) - assert.True(t, acc.CheckTaggedValue("swap_used", uint64(1232), swaptags)) - assert.True(t, acc.CheckTaggedValue("swap_used_perc", float64(12.2), swaptags)) - assert.True(t, acc.CheckTaggedValue("swap_free", uint64(6412), swaptags)) - assert.True(t, acc.CheckTaggedValue("swap_in", uint64(7), swaptags)) - assert.True(t, acc.CheckTaggedValue("swap_out", uint64(830), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("total", uint64(8123), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("used", uint64(1232), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("used_perc", float64(12.2), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("free", uint64(6412), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("in", uint64(7), swaptags)) + assert.NoError(t, acc.ValidateTaggedValue("out", uint64(830), swaptags)) err = (&DockerStats{&mps}).Gather(&acc) require.NoError(t, err) @@ -273,43 +275,43 @@ func TestSystemStats_GenerateStats(t *testing.T) { "id": "blah", } - assert.True(t, acc.CheckTaggedValue("docker_user", 3.1, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_system", 8.2, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_idle", 80.1, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_nice", 1.3, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_iowait", 0.2, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_irq", 0.1, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_softirq", 0.11, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_steal", 0.0001, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_guest", 8.1, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_guestNice", 0.324, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_stolen", 0.051, dockertags)) + assert.True(t, acc.CheckTaggedValue("user", 3.1, dockertags)) + assert.True(t, acc.CheckTaggedValue("system", 8.2, dockertags)) + assert.True(t, acc.CheckTaggedValue("idle", 80.1, dockertags)) + assert.True(t, acc.CheckTaggedValue("nice", 1.3, dockertags)) + assert.True(t, acc.CheckTaggedValue("iowait", 0.2, dockertags)) + assert.True(t, acc.CheckTaggedValue("irq", 0.1, dockertags)) + assert.True(t, acc.CheckTaggedValue("softirq", 0.11, dockertags)) + assert.True(t, acc.CheckTaggedValue("steal", 0.0001, dockertags)) + assert.True(t, acc.CheckTaggedValue("guest", 8.1, dockertags)) + assert.True(t, acc.CheckTaggedValue("guestNice", 0.324, dockertags)) + assert.True(t, acc.CheckTaggedValue("stolen", 0.051, dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_cache", uint64(1), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_rss", uint64(2), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_rss_huge", uint64(3), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_mapped_file", uint64(4), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_swap_in", uint64(5), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_swap_out", uint64(6), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_page_fault", uint64(7), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_page_major_fault", uint64(8), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_inactive_anon", uint64(9), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_active_anon", uint64(10), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_inactive_file", uint64(11), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_active_file", uint64(12), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_unevictable", uint64(13), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_memory_limit", uint64(14), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_cache", uint64(15), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_rss", uint64(16), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_rss_huge", uint64(17), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_mapped_file", uint64(18), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_swap_in", uint64(19), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_swap_out", uint64(20), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_page_fault", uint64(21), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_page_major_fault", uint64(22), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_inactive_anon", uint64(23), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_active_anon", uint64(24), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_inactive_file", uint64(25), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_active_file", uint64(26), dockertags)) - assert.True(t, acc.CheckTaggedValue("docker_total_unevictable", uint64(27), dockertags)) + assert.True(t, acc.CheckTaggedValue("cache", uint64(1), dockertags)) + assert.True(t, acc.CheckTaggedValue("rss", uint64(2), dockertags)) + assert.True(t, acc.CheckTaggedValue("rss_huge", uint64(3), dockertags)) + assert.True(t, acc.CheckTaggedValue("mapped_file", uint64(4), dockertags)) + assert.True(t, acc.CheckTaggedValue("swap_in", uint64(5), dockertags)) + assert.True(t, acc.CheckTaggedValue("swap_out", uint64(6), dockertags)) + assert.True(t, acc.CheckTaggedValue("page_fault", uint64(7), dockertags)) + assert.True(t, acc.CheckTaggedValue("page_major_fault", uint64(8), dockertags)) + assert.True(t, acc.CheckTaggedValue("inactive_anon", uint64(9), dockertags)) + assert.True(t, acc.CheckTaggedValue("active_anon", uint64(10), dockertags)) + assert.True(t, acc.CheckTaggedValue("inactive_file", uint64(11), dockertags)) + assert.True(t, acc.CheckTaggedValue("active_file", uint64(12), dockertags)) + assert.True(t, acc.CheckTaggedValue("unevictable", uint64(13), dockertags)) + assert.True(t, acc.CheckTaggedValue("memory_limit", uint64(14), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_cache", uint64(15), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_rss", uint64(16), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_rss_huge", uint64(17), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_mapped_file", uint64(18), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_swap_in", uint64(19), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_swap_out", uint64(20), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_page_fault", uint64(21), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_page_major_fault", uint64(22), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_inactive_anon", uint64(23), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_active_anon", uint64(24), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_inactive_file", uint64(25), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_active_file", uint64(26), dockertags)) + assert.True(t, acc.CheckTaggedValue("total_unevictable", uint64(27), dockertags)) }