Fixed inconsistency between HasIntField and IntField (#2813)
This commit is contained in:
parent
bfeb3020a3
commit
ac5ac3161f
|
@ -24,7 +24,7 @@ func TestAerospikeStatistics(t *testing.T) {
|
||||||
|
|
||||||
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
||||||
assert.True(t, acc.HasMeasurement("aerospike_namespace"))
|
assert.True(t, acc.HasMeasurement("aerospike_namespace"))
|
||||||
assert.True(t, acc.HasIntField("aerospike_node", "batch_error"))
|
assert.True(t, acc.HasInt64Field("aerospike_node", "batch_error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAerospikeStatisticsPartialErr(t *testing.T) {
|
func TestAerospikeStatisticsPartialErr(t *testing.T) {
|
||||||
|
@ -45,7 +45,7 @@ func TestAerospikeStatisticsPartialErr(t *testing.T) {
|
||||||
|
|
||||||
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
||||||
assert.True(t, acc.HasMeasurement("aerospike_namespace"))
|
assert.True(t, acc.HasMeasurement("aerospike_namespace"))
|
||||||
assert.True(t, acc.HasIntField("aerospike_node", "batch_error"))
|
assert.True(t, acc.HasInt64Field("aerospike_node", "batch_error"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAerospikeParseValue(t *testing.T) {
|
func TestAerospikeParseValue(t *testing.T) {
|
||||||
|
|
|
@ -355,7 +355,7 @@ func TestTimeout(t *testing.T) {
|
||||||
Address: ts.URL + "/twosecondnap",
|
Address: ts.URL + "/twosecondnap",
|
||||||
Body: "{ 'test': 'data'}",
|
Body: "{ 'test': 'data'}",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
ResponseTimeout: internal.Duration{Duration: time.Millisecond},
|
ResponseTimeout: internal.Duration{Duration: time.Second},
|
||||||
Headers: map[string]string{
|
Headers: map[string]string{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
|
@ -363,7 +363,7 @@ func TestTimeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
err := h.Gather(&acc)
|
err := h.Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
ok := acc.HasIntField("http_response", "http_response_code")
|
ok := acc.HasIntField("http_response", "http_response_code")
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
||||||
"bytes_read", "bytes_written", "threads", "conn_yields"}
|
"bytes_read", "bytes_written", "threads", "conn_yields"}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntField("memcached", metric), metric)
|
assert.True(t, acc.HasInt64Field("memcached", metric), metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ func TestAddNonReplStats(t *testing.T) {
|
||||||
d.flush(&acc)
|
d.flush(&acc)
|
||||||
|
|
||||||
for key, _ := range DefaultStats {
|
for key, _ := range DefaultStats {
|
||||||
assert.True(t, acc.HasIntField("mongodb", key))
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func TestAddReplStats(t *testing.T) {
|
||||||
d.flush(&acc)
|
d.flush(&acc)
|
||||||
|
|
||||||
for key, _ := range MmapStats {
|
for key, _ := range MmapStats {
|
||||||
assert.True(t, acc.HasIntField("mongodb", key))
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,6 @@ func TestAddDefaultStats(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
for key, _ := range DefaultStats {
|
for key, _ := range DefaultStats {
|
||||||
assert.True(t, acc.HasIntField("mongodb", key))
|
assert.True(t, acc.HasInt64Field("mongodb", key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,19 +217,19 @@ func TestFatalPingGather(t *testing.T) {
|
||||||
acc.GatherError(p.Gather)
|
acc.GatherError(p.Gather)
|
||||||
assert.True(t, acc.HasFloatField("ping", "errors"),
|
assert.True(t, acc.HasFloatField("ping", "errors"),
|
||||||
"Fatal ping should have packet measurements")
|
"Fatal ping should have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "packets_transmitted"),
|
assert.False(t, acc.HasInt64Field("ping", "packets_transmitted"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "packets_received"),
|
assert.False(t, acc.HasInt64Field("ping", "packets_received"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasFloatField("ping", "percent_packet_loss"),
|
assert.False(t, acc.HasFloatField("ping", "percent_packet_loss"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasFloatField("ping", "percent_reply_loss"),
|
assert.False(t, acc.HasFloatField("ping", "percent_reply_loss"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "average_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "average_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "maximum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "maximum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "minimum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "minimum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,11 +273,11 @@ func TestUnreachablePingGather(t *testing.T) {
|
||||||
|
|
||||||
assert.False(t, acc.HasFloatField("ping", "errors"),
|
assert.False(t, acc.HasFloatField("ping", "errors"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "average_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "average_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "maximum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "maximum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "minimum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "minimum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,10 +319,10 @@ func TestTTLExpiredPingGather(t *testing.T) {
|
||||||
|
|
||||||
assert.False(t, acc.HasFloatField("ping", "errors"),
|
assert.False(t, acc.HasFloatField("ping", "errors"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "average_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "average_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "maximum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "maximum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
assert.False(t, acc.HasIntField("ping", "minimum_response_ms"),
|
assert.False(t, acc.HasInt64Field("ping", "minimum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
_, ok := availableColumns[metric]
|
_, ok := availableColumns[metric]
|
||||||
if ok {
|
if ok {
|
||||||
assert.True(t, acc.HasIntField("postgresql", metric))
|
assert.True(t, acc.HasInt64Field("postgresql", metric))
|
||||||
metricsCounted++
|
metricsCounted++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
_, ok := availableColumns[metric]
|
_, ok := availableColumns[metric]
|
||||||
if ok {
|
if ok {
|
||||||
assert.True(t, acc.HasIntField("postgresql", metric))
|
assert.True(t, acc.HasInt64Field("postgresql", metric))
|
||||||
metricsCounted++
|
metricsCounted++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
||||||
"meta-cache-size", "qsize-q", "signature-cache-size", "sys-msec", "uptime", "user-msec"}
|
"meta-cache-size", "qsize-q", "signature-cache-size", "sys-msec", "uptime", "user-msec"}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntField("powerdns", metric), metric)
|
assert.True(t, acc.HasInt64Field("powerdns", metric), metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -419,7 +419,7 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntField("rabbitmq_overview", metric))
|
assert.True(t, acc.HasInt64Field("rabbitmq_overview", metric))
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeIntMetrics := []string{
|
nodeIntMetrics := []string{
|
||||||
|
@ -437,7 +437,7 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range nodeIntMetrics {
|
for _, metric := range nodeIntMetrics {
|
||||||
assert.True(t, acc.HasIntField("rabbitmq_node", metric))
|
assert.True(t, acc.HasInt64Field("rabbitmq_node", metric))
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.True(t, acc.HasMeasurement("rabbitmq_queue"))
|
assert.True(t, acc.HasMeasurement("rabbitmq_queue"))
|
||||||
|
|
|
@ -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.HasIntField("rethinkdb_engine", metric))
|
assert.True(t, acc.HasInt64Field("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.HasIntField("rethinkdb", metric))
|
assert.False(t, acc.HasInt64Field("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.HasIntField("rethinkdb", metric))
|
assert.True(t, acc.HasInt64Field("rethinkdb", metric))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ func TestProcesses(t *testing.T) {
|
||||||
err := processes.Gather(&acc)
|
err := processes.Gather(&acc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.True(t, acc.HasIntField("processes", "running"))
|
assert.True(t, acc.HasInt64Field("processes", "running"))
|
||||||
assert.True(t, acc.HasIntField("processes", "sleeping"))
|
assert.True(t, acc.HasInt64Field("processes", "sleeping"))
|
||||||
assert.True(t, acc.HasIntField("processes", "stopped"))
|
assert.True(t, acc.HasInt64Field("processes", "stopped"))
|
||||||
assert.True(t, acc.HasIntField("processes", "total"))
|
assert.True(t, acc.HasInt64Field("processes", "total"))
|
||||||
total, ok := acc.Get("processes")
|
total, ok := acc.Get("processes")
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
assert.True(t, total.Fields["total"].(int64) > 0)
|
assert.True(t, total.Fields["total"].(int64) > 0)
|
||||||
|
|
|
@ -37,6 +37,6 @@ func TestZookeeperGeneratesMetrics(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, metric := range intMetrics {
|
for _, metric := range intMetrics {
|
||||||
assert.True(t, acc.HasIntField("zookeeper", metric), metric)
|
assert.True(t, acc.HasInt64Field("zookeeper", metric), metric)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -317,6 +317,24 @@ func (a *Accumulator) HasField(measurement string, field string) bool {
|
||||||
|
|
||||||
// HasIntField returns true if the measurement has an Int value
|
// HasIntField returns true if the measurement has an Int value
|
||||||
func (a *Accumulator) HasIntField(measurement string, field string) bool {
|
func (a *Accumulator) HasIntField(measurement string, field string) bool {
|
||||||
|
a.Lock()
|
||||||
|
defer a.Unlock()
|
||||||
|
for _, p := range a.Metrics {
|
||||||
|
if p.Measurement == measurement {
|
||||||
|
for fieldname, value := range p.Fields {
|
||||||
|
if fieldname == field {
|
||||||
|
_, ok := value.(int)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasInt64Field returns true if the measurement has an Int64 value
|
||||||
|
func (a *Accumulator) HasInt64Field(measurement string, field string) bool {
|
||||||
a.Lock()
|
a.Lock()
|
||||||
defer a.Unlock()
|
defer a.Unlock()
|
||||||
for _, p := range a.Metrics {
|
for _, p := range a.Metrics {
|
||||||
|
|
Loading…
Reference in New Issue