0.3.0 unit tests: rethinkdb, twemproxy, zfs

This commit is contained in:
Cameron Sparr 2016-01-06 22:16:04 -07:00
parent 10f19fade1
commit 936c5a8a7a
4 changed files with 205 additions and 519 deletions

View File

@ -36,7 +36,7 @@ func TestAddEngineStats(t *testing.T) {
engine.AddEngineStats(keys, &acc, tags) engine.AddEngineStats(keys, &acc, tags)
for _, metric := range keys { for _, metric := range keys {
assert.True(t, acc.HasIntValue(metric)) assert.True(t, acc.HasIntField("rethinkdb_engine", metric))
} }
} }
@ -67,7 +67,7 @@ func TestAddEngineStatsPartial(t *testing.T) {
engine.AddEngineStats(keys, &acc, tags) engine.AddEngineStats(keys, &acc, tags)
for _, metric := range missing_keys { for _, metric := range missing_keys {
assert.False(t, acc.HasIntValue(metric)) assert.False(t, acc.HasIntField("rethinkdb", metric))
} }
} }
@ -107,6 +107,6 @@ func TestAddStorageStats(t *testing.T) {
storage.AddStats(&acc, tags) storage.AddStats(&acc, tags)
for _, metric := range keys { for _, metric := range keys {
assert.True(t, acc.HasIntValue(metric)) assert.True(t, acc.HasIntField("rethinkdb", metric))
} }
} }

View File

@ -130,7 +130,7 @@ func (t *Twemproxy) processServer(
} }
} }
} }
acc.AddFields("twemproxy_pool", fields, tags) acc.AddFields("twemproxy_pool_server", fields, tags)
} }
// Tags is not expected to be mutated after passing to Add. // Tags is not expected to be mutated after passing to Add.

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
"github.com/influxdb/telegraf/testutil" "github.com/influxdb/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -85,16 +84,13 @@ func TestGather(t *testing.T) {
defer mockServer.Close() defer mockServer.Close()
twemproxy := &Twemproxy{ twemproxy := &Twemproxy{
Instances: []TwemproxyInstance{ Addr: sampleAddr,
TwemproxyInstance{ Pools: []string{"demo"},
Addr: sampleAddr,
Pools: []string{"demo"},
},
},
} }
var acc testutil.Accumulator var acc testutil.Accumulator
err = twemproxy.Instances[0].Gather(&acc) acc.SetDebug(true)
err = twemproxy.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
var sourceData map[string]interface{} var sourceData map[string]interface{}
@ -102,33 +98,74 @@ func TestGather(t *testing.T) {
panic(err) panic(err)
} }
metrics := []string{"total_connections", "curr_connections", "timestamp"} fields := map[string]interface{}{
"total_connections": float64(276448),
"curr_connections": float64(1322),
"timestamp": float64(1.447312436e+09),
}
tags := map[string]string{ tags := map[string]string{
"twemproxy": sampleAddr, "twemproxy": sampleAddr,
"source": sourceData["source"].(string), "source": sourceData["source"].(string),
} }
for _, m := range metrics { acc.AssertContainsTaggedFields(t, "twemproxy", fields, tags)
assert.NoError(t, acc.ValidateTaggedValue(m, sourceData[m].(float64), tags))
}
poolName := "demo" poolName := "demo"
poolMetrics := []string{ poolFields := map[string]interface{}{
"client_connections", "forward_error", "client_err", "server_ejects", "client_connections": float64(1305),
"fragments", "client_eof", "client_eof": float64(126813),
"client_err": float64(147942),
"forward_error": float64(11684),
"fragments": float64(0),
"server_ejects": float64(0),
} }
tags["pool"] = poolName tags["pool"] = poolName
poolData := sourceData[poolName].(map[string]interface{}) acc.AssertContainsTaggedFields(t, "twemproxy_pool", poolFields, tags)
for _, m := range poolMetrics {
measurement := poolName + "_" + m poolServerTags1 := map[string]string{
assert.NoError(t, acc.ValidateTaggedValue(measurement, poolData[m].(float64), tags)) "pool": "demo",
"server": "10.16.29.2:6379",
"source": "server1.website.com",
"twemproxy": "127.0.0.1:22222",
} }
poolServers := []string{"10.16.29.1:6379", "10.16.29.2:6379"} poolServerFields1 := map[string]interface{}{
for _, s := range poolServers { "in_queue": float64(0),
tags["server"] = s "in_queue_bytes": float64(0),
serverData := poolData[s].(map[string]interface{}) "out_queue": float64(0),
for k, v := range serverData { "out_queue_bytes": float64(0),
measurement := poolName + "_" + k "request_bytes": float64(2.412114759e+09),
assert.NoError(t, acc.ValidateTaggedValue(measurement, v, tags)) "requests": float64(3.7870211e+07),
} "response_bytes": float64(5.228980582e+09),
"responses": float64(3.7869551e+07),
"server_connections": float64(1),
"server_ejected_at": float64(0),
"server_eof": float64(0),
"server_err": float64(0),
"server_timedout": float64(25),
} }
acc.AssertContainsTaggedFields(t, "twemproxy_pool_server",
poolServerFields1, poolServerTags1)
poolServerTags2 := map[string]string{
"pool": "demo",
"server": "10.16.29.1:6379",
"source": "server1.website.com",
"twemproxy": "127.0.0.1:22222",
}
poolServerFields2 := map[string]interface{}{
"in_queue": float64(0),
"in_queue_bytes": float64(0),
"out_queue": float64(0),
"out_queue_bytes": float64(0),
"request_bytes": float64(2.7758404e+09),
"requests": float64(4.3604566e+07),
"response_bytes": float64(7.663182096e+09),
"responses": float64(4.36039e+07),
"server_connections": float64(1),
"server_ejected_at": float64(0),
"server_eof": float64(0),
"server_err": float64(0),
"server_timedout": float64(24),
}
acc.AssertContainsTaggedFields(t, "twemproxy_pool_server",
poolServerFields2, poolServerTags2)
} }

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
"github.com/influxdb/telegraf/testutil" "github.com/influxdb/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -127,11 +126,6 @@ nread nwritten reads writes wtime wlentime wupdate rtime rlentime
var testKstatPath = os.TempDir() + "/telegraf/proc/spl/kstat/zfs" var testKstatPath = os.TempDir() + "/telegraf/proc/spl/kstat/zfs"
type metrics struct {
name string
value int64
}
func TestZfsPoolMetrics(t *testing.T) { func TestZfsPoolMetrics(t *testing.T) {
err := os.MkdirAll(testKstatPath, 0755) err := os.MkdirAll(testKstatPath, 0755)
require.NoError(t, err) require.NoError(t, err)
@ -149,29 +143,24 @@ func TestZfsPoolMetrics(t *testing.T) {
var acc testutil.Accumulator var acc testutil.Accumulator
//one pool, all metrics
tags := map[string]string{
"pool": "HOME",
}
z := &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}} z := &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}}
err = z.Gather(&acc) err = z.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
for _, metric := range poolMetrics { require.False(t, acc.HasMeasurement("zfs_pool"))
assert.True(t, !acc.HasIntValue(metric.name), metric.name) acc.Points = nil
assert.True(t, !acc.CheckTaggedValue(metric.name, metric.value, tags))
}
z = &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}, PoolMetrics: true} z = &Zfs{KstatPath: testKstatPath, KstatMetrics: []string{"arcstats"}, PoolMetrics: true}
err = z.Gather(&acc) err = z.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
for _, metric := range poolMetrics { //one pool, all metrics
assert.True(t, acc.HasIntValue(metric.name), metric.name) tags := map[string]string{
assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags)) "pool": "HOME",
} }
acc.AssertContainsTaggedFields(t, "zfs_pool", poolMetrics, tags)
err = os.RemoveAll(os.TempDir() + "/telegraf") err = os.RemoveAll(os.TempDir() + "/telegraf")
require.NoError(t, err) require.NoError(t, err)
} }
@ -208,10 +197,8 @@ func TestZfsGeneratesMetrics(t *testing.T) {
err = z.Gather(&acc) err = z.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
for _, metric := range intMetrics { acc.AssertContainsTaggedFields(t, "zfs", intMetrics, tags)
assert.True(t, acc.HasIntValue(metric.name), metric.name) acc.Points = nil
assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
}
//two pools, all metrics //two pools, all metrics
err = os.MkdirAll(testKstatPath+"/STORAGE", 0755) err = os.MkdirAll(testKstatPath+"/STORAGE", 0755)
@ -229,10 +216,8 @@ func TestZfsGeneratesMetrics(t *testing.T) {
err = z.Gather(&acc) err = z.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
for _, metric := range intMetrics { acc.AssertContainsTaggedFields(t, "zfs", intMetrics, tags)
assert.True(t, acc.HasIntValue(metric.name), metric.name) acc.Points = nil
assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
}
intMetrics = getKstatMetricsArcOnly() intMetrics = getKstatMetricsArcOnly()
@ -242,476 +227,140 @@ func TestZfsGeneratesMetrics(t *testing.T) {
err = z.Gather(&acc) err = z.Gather(&acc)
require.NoError(t, err) require.NoError(t, err)
for _, metric := range intMetrics { acc.AssertContainsTaggedFields(t, "zfs", intMetrics, tags)
assert.True(t, acc.HasIntValue(metric.name), metric.name)
assert.True(t, acc.CheckTaggedValue(metric.name, metric.value, tags))
}
err = os.RemoveAll(os.TempDir() + "/telegraf") err = os.RemoveAll(os.TempDir() + "/telegraf")
require.NoError(t, err) require.NoError(t, err)
} }
func getKstatMetricsArcOnly() []*metrics { func getKstatMetricsArcOnly() map[string]interface{} {
return []*metrics{ return map[string]interface{}{
{ "arcstats_hits": int64(5968846374),
name: "arcstats_hits", "arcstats_misses": int64(1659178751),
value: 5968846374, "arcstats_demand_data_hits": int64(4860247322),
}, "arcstats_demand_data_misses": int64(501499535),
{ "arcstats_demand_metadata_hits": int64(708608325),
name: "arcstats_misses", "arcstats_demand_metadata_misses": int64(156591375),
value: 1659178751, "arcstats_prefetch_data_hits": int64(367047144),
}, "arcstats_prefetch_data_misses": int64(974529898),
{ "arcstats_prefetch_metadata_hits": int64(32943583),
name: "arcstats_demand_data_hits", "arcstats_prefetch_metadata_misses": int64(26557943),
value: 4860247322, "arcstats_mru_hits": int64(301176811),
}, "arcstats_mru_ghost_hits": int64(47066067),
{ "arcstats_mfu_hits": int64(5520612438),
name: "arcstats_demand_data_misses", "arcstats_mfu_ghost_hits": int64(45784009),
value: 501499535, "arcstats_deleted": int64(1718937704),
}, "arcstats_recycle_miss": int64(481222994),
{ "arcstats_mutex_miss": int64(20575623),
name: "arcstats_demand_metadata_hits", "arcstats_evict_skip": int64(14655903906543),
value: 708608325, "arcstats_evict_l2_cached": int64(145310202998272),
}, "arcstats_evict_l2_eligible": int64(16345402777088),
{ "arcstats_evict_l2_ineligible": int64(7437226893312),
name: "arcstats_demand_metadata_misses", "arcstats_hash_elements": int64(36617980),
value: 156591375, "arcstats_hash_elements_max": int64(36618318),
}, "arcstats_hash_collisions": int64(554145157),
{ "arcstats_hash_chains": int64(4187651),
name: "arcstats_prefetch_data_hits", "arcstats_hash_chain_max": int64(26),
value: 367047144, "arcstats_p": int64(13963222064),
}, "arcstats_c": int64(16381258376),
{ "arcstats_c_min": int64(4194304),
name: "arcstats_prefetch_data_misses", "arcstats_c_max": int64(16884125696),
value: 974529898, "arcstats_size": int64(16319887096),
}, "arcstats_hdr_size": int64(42567864),
{ "arcstats_data_size": int64(60066304),
name: "arcstats_prefetch_metadata_hits", "arcstats_meta_size": int64(1701534208),
value: 32943583, "arcstats_other_size": int64(1661543168),
}, "arcstats_anon_size": int64(94720),
{ "arcstats_anon_evict_data": int64(0),
name: "arcstats_prefetch_metadata_misses", "arcstats_anon_evict_metadata": int64(0),
value: 26557943, "arcstats_mru_size": int64(973099008),
}, "arcstats_mru_evict_data": int64(9175040),
{ "arcstats_mru_evict_metadata": int64(32768),
name: "arcstats_mru_hits", "arcstats_mru_ghost_size": int64(32768),
value: 301176811, "arcstats_mru_ghost_evict_data": int64(0),
}, "arcstats_mru_ghost_evict_metadata": int64(32768),
{ "arcstats_mfu_size": int64(788406784),
name: "arcstats_mru_ghost_hits", "arcstats_mfu_evict_data": int64(50881024),
value: 47066067, "arcstats_mfu_evict_metadata": int64(81920),
}, "arcstats_mfu_ghost_size": int64(0),
{ "arcstats_mfu_ghost_evict_data": int64(0),
name: "arcstats_mfu_hits", "arcstats_mfu_ghost_evict_metadata": int64(0),
value: 5520612438, "arcstats_l2_hits": int64(573868618),
}, "arcstats_l2_misses": int64(1085309718),
{ "arcstats_l2_feeds": int64(12182087),
name: "arcstats_mfu_ghost_hits", "arcstats_l2_rw_clash": int64(9610),
value: 45784009, "arcstats_l2_read_bytes": int64(32695938336768),
}, "arcstats_l2_write_bytes": int64(2826774778880),
{ "arcstats_l2_writes_sent": int64(4267687),
name: "arcstats_deleted", "arcstats_l2_writes_done": int64(4267687),
value: 1718937704, "arcstats_l2_writes_error": int64(0),
}, "arcstats_l2_writes_hdr_miss": int64(164),
{ "arcstats_l2_evict_lock_retry": int64(5),
name: "arcstats_recycle_miss", "arcstats_l2_evict_reading": int64(0),
value: 481222994, "arcstats_l2_free_on_write": int64(1606914),
}, "arcstats_l2_cdata_free_on_write": int64(1775),
{ "arcstats_l2_abort_lowmem": int64(83462),
name: "arcstats_mutex_miss", "arcstats_l2_cksum_bad": int64(393860640),
value: 20575623, "arcstats_l2_io_error": int64(53881460),
}, "arcstats_l2_size": int64(2471466648576),
{ "arcstats_l2_asize": int64(2461690072064),
name: "arcstats_evict_skip", "arcstats_l2_hdr_size": int64(12854175552),
value: 14655903906543, "arcstats_l2_compress_successes": int64(12184849),
}, "arcstats_l2_compress_zeros": int64(0),
{ "arcstats_l2_compress_failures": int64(0),
name: "arcstats_evict_l2_cached", "arcstats_memory_throttle_count": int64(0),
value: 145310202998272, "arcstats_duplicate_buffers": int64(0),
}, "arcstats_duplicate_buffers_size": int64(0),
{ "arcstats_duplicate_reads": int64(0),
name: "arcstats_evict_l2_eligible", "arcstats_memory_direct_count": int64(5159942),
value: 16345402777088, "arcstats_memory_indirect_count": int64(3034640),
}, "arcstats_arc_no_grow": int64(0),
{ "arcstats_arc_tempreserve": int64(0),
name: "arcstats_evict_l2_ineligible", "arcstats_arc_loaned_bytes": int64(0),
value: 7437226893312, "arcstats_arc_prune": int64(114554259559),
}, "arcstats_arc_meta_used": int64(16259820792),
{ "arcstats_arc_meta_limit": int64(12663094272),
name: "arcstats_hash_elements", "arcstats_arc_meta_max": int64(18327165696),
value: 36617980,
},
{
name: "arcstats_hash_elements_max",
value: 36618318,
},
{
name: "arcstats_hash_collisions",
value: 554145157,
},
{
name: "arcstats_hash_chains",
value: 4187651,
},
{
name: "arcstats_hash_chain_max",
value: 26,
},
{
name: "arcstats_p",
value: 13963222064,
},
{
name: "arcstats_c",
value: 16381258376,
},
{
name: "arcstats_c_min",
value: 4194304,
},
{
name: "arcstats_c_max",
value: 16884125696,
},
{
name: "arcstats_size",
value: 16319887096,
},
{
name: "arcstats_hdr_size",
value: 42567864,
},
{
name: "arcstats_data_size",
value: 60066304,
},
{
name: "arcstats_meta_size",
value: 1701534208,
},
{
name: "arcstats_other_size",
value: 1661543168,
},
{
name: "arcstats_anon_size",
value: 94720,
},
{
name: "arcstats_anon_evict_data",
value: 0,
},
{
name: "arcstats_anon_evict_metadata",
value: 0,
},
{
name: "arcstats_mru_size",
value: 973099008,
},
{
name: "arcstats_mru_evict_data",
value: 9175040,
},
{
name: "arcstats_mru_evict_metadata",
value: 32768,
},
{
name: "arcstats_mru_ghost_size",
value: 32768,
},
{
name: "arcstats_mru_ghost_evict_data",
value: 0,
},
{
name: "arcstats_mru_ghost_evict_metadata",
value: 32768,
},
{
name: "arcstats_mfu_size",
value: 788406784,
},
{
name: "arcstats_mfu_evict_data",
value: 50881024,
},
{
name: "arcstats_mfu_evict_metadata",
value: 81920,
},
{
name: "arcstats_mfu_ghost_size",
value: 0,
},
{
name: "arcstats_mfu_ghost_evict_data",
value: 0,
},
{
name: "arcstats_mfu_ghost_evict_metadata",
value: 0,
},
{
name: "arcstats_l2_hits",
value: 573868618,
},
{
name: "arcstats_l2_misses",
value: 1085309718,
},
{
name: "arcstats_l2_feeds",
value: 12182087,
},
{
name: "arcstats_l2_rw_clash",
value: 9610,
},
{
name: "arcstats_l2_read_bytes",
value: 32695938336768,
},
{
name: "arcstats_l2_write_bytes",
value: 2826774778880,
},
{
name: "arcstats_l2_writes_sent",
value: 4267687,
},
{
name: "arcstats_l2_writes_done",
value: 4267687,
},
{
name: "arcstats_l2_writes_error",
value: 0,
},
{
name: "arcstats_l2_writes_hdr_miss",
value: 164,
},
{
name: "arcstats_l2_evict_lock_retry",
value: 5,
},
{
name: "arcstats_l2_evict_reading",
value: 0,
},
{
name: "arcstats_l2_free_on_write",
value: 1606914,
},
{
name: "arcstats_l2_cdata_free_on_write",
value: 1775,
},
{
name: "arcstats_l2_abort_lowmem",
value: 83462,
},
{
name: "arcstats_l2_cksum_bad",
value: 393860640,
},
{
name: "arcstats_l2_io_error",
value: 53881460,
},
{
name: "arcstats_l2_size",
value: 2471466648576,
},
{
name: "arcstats_l2_asize",
value: 2461690072064,
},
{
name: "arcstats_l2_hdr_size",
value: 12854175552,
},
{
name: "arcstats_l2_compress_successes",
value: 12184849,
},
{
name: "arcstats_l2_compress_zeros",
value: 0,
},
{
name: "arcstats_l2_compress_failures",
value: 0,
},
{
name: "arcstats_memory_throttle_count",
value: 0,
},
{
name: "arcstats_duplicate_buffers",
value: 0,
},
{
name: "arcstats_duplicate_buffers_size",
value: 0,
},
{
name: "arcstats_duplicate_reads",
value: 0,
},
{
name: "arcstats_memory_direct_count",
value: 5159942,
},
{
name: "arcstats_memory_indirect_count",
value: 3034640,
},
{
name: "arcstats_arc_no_grow",
value: 0,
},
{
name: "arcstats_arc_tempreserve",
value: 0,
},
{
name: "arcstats_arc_loaned_bytes",
value: 0,
},
{
name: "arcstats_arc_prune",
value: 114554259559,
},
{
name: "arcstats_arc_meta_used",
value: 16259820792,
},
{
name: "arcstats_arc_meta_limit",
value: 12663094272,
},
{
name: "arcstats_arc_meta_max",
value: 18327165696,
},
} }
} }
func getKstatMetricsAll() []*metrics { func getKstatMetricsAll() map[string]interface{} {
otherMetrics := []*metrics{ otherMetrics := map[string]interface{}{
{ "zfetchstats_hits": int64(7812959060),
name: "zfetchstats_hits", "zfetchstats_misses": int64(4154484207),
value: 7812959060, "zfetchstats_colinear_hits": int64(1366368),
}, "zfetchstats_colinear_misses": int64(4153117839),
{ "zfetchstats_stride_hits": int64(7309776732),
name: "zfetchstats_misses", "zfetchstats_stride_misses": int64(222766182),
value: 4154484207, "zfetchstats_reclaim_successes": int64(107788388),
}, "zfetchstats_reclaim_failures": int64(4045329451),
{ "zfetchstats_streams_resets": int64(20989756),
name: "zfetchstats_colinear_hits", "zfetchstats_streams_noresets": int64(503182328),
value: 1366368, "zfetchstats_bogus_streams": int64(0),
}, "vdev_cache_stats_delegations": int64(0),
{ "vdev_cache_stats_hits": int64(0),
name: "zfetchstats_colinear_misses", "vdev_cache_stats_misses": int64(0),
value: 4153117839,
},
{
name: "zfetchstats_stride_hits",
value: 7309776732,
},
{
name: "zfetchstats_stride_misses",
value: 222766182,
},
{
name: "zfetchstats_reclaim_successes",
value: 107788388,
},
{
name: "zfetchstats_reclaim_failures",
value: 4045329451,
},
{
name: "zfetchstats_streams_resets",
value: 20989756,
},
{
name: "zfetchstats_streams_noresets",
value: 503182328,
},
{
name: "zfetchstats_bogus_streams",
value: 0,
},
{
name: "vdev_cache_stats_delegations",
value: 0,
},
{
name: "vdev_cache_stats_hits",
value: 0,
},
{
name: "vdev_cache_stats_misses",
value: 0,
},
} }
arcMetrics := getKstatMetricsArcOnly()
return append(getKstatMetricsArcOnly(), otherMetrics...) for k, v := range otherMetrics {
arcMetrics[k] = v
}
return arcMetrics
} }
func getPoolMetrics() []*metrics { func getPoolMetrics() map[string]interface{} {
return []*metrics{ return map[string]interface{}{
{ "nread": int64(1884160),
name: "nread", "nwritten": int64(6450688),
value: 1884160, "reads": int64(22),
}, "writes": int64(978),
{ "wtime": int64(272187126),
name: "nwritten", "wlentime": int64(2850519036),
value: 6450688, "wupdate": int64(2263669418655),
}, "rtime": int64(424226814),
{ "rlentime": int64(2850519036),
name: "reads", "rupdate": int64(2263669871823),
value: 22, "wcnt": int64(0),
}, "rcnt": int64(0),
{
name: "writes",
value: 978,
},
{
name: "wtime",
value: 272187126,
},
{
name: "wlentime",
value: 2850519036,
},
{
name: "wupdate",
value: 2263669418655,
},
{
name: "rtime",
value: 424226814,
},
{
name: "rlentime",
value: 2850519036,
},
{
name: "rupdate",
value: 2263669871823,
},
{
name: "wcnt",
value: 0,
},
{
name: "rcnt",
value: 0,
},
} }
} }