Fixed inconsistency between HasIntField and IntField (#2813)
This commit is contained in:
parent
f29cd638c9
commit
ec3c27a555
|
@ -24,7 +24,7 @@ func TestAerospikeStatistics(t *testing.T) {
|
|||
|
||||
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
||||
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) {
|
||||
|
@ -45,7 +45,7 @@ func TestAerospikeStatisticsPartialErr(t *testing.T) {
|
|||
|
||||
assert.True(t, acc.HasMeasurement("aerospike_node"))
|
||||
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) {
|
||||
|
|
|
@ -355,7 +355,7 @@ func TestTimeout(t *testing.T) {
|
|||
Address: ts.URL + "/twosecondnap",
|
||||
Body: "{ 'test': 'data'}",
|
||||
Method: "GET",
|
||||
ResponseTimeout: internal.Duration{Duration: time.Millisecond},
|
||||
ResponseTimeout: internal.Duration{Duration: time.Second},
|
||||
Headers: map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
|
@ -363,7 +363,7 @@ func TestTimeout(t *testing.T) {
|
|||
}
|
||||
var acc testutil.Accumulator
|
||||
err := h.Gather(&acc)
|
||||
require.NoError(t, err)
|
||||
require.Error(t, err)
|
||||
|
||||
ok := acc.HasIntField("http_response", "http_response_code")
|
||||
require.False(t, ok)
|
||||
|
|
|
@ -32,7 +32,7 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
|||
"bytes_read", "bytes_written", "threads", "conn_yields"}
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
assert.True(t, acc.HasFloatField("ping", "errors"),
|
||||
"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")
|
||||
assert.False(t, acc.HasIntField("ping", "packets_received"),
|
||||
assert.False(t, acc.HasInt64Field("ping", "packets_received"),
|
||||
"Fatal ping should not have packet measurements")
|
||||
assert.False(t, acc.HasFloatField("ping", "percent_packet_loss"),
|
||||
"Fatal ping should not have packet measurements")
|
||||
assert.False(t, acc.HasFloatField("ping", "percent_reply_loss"),
|
||||
"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")
|
||||
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")
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -273,11 +273,11 @@ func TestUnreachablePingGather(t *testing.T) {
|
|||
|
||||
assert.False(t, acc.HasFloatField("ping", "errors"),
|
||||
"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")
|
||||
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")
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -319,10 +319,10 @@ func TestTTLExpiredPingGather(t *testing.T) {
|
|||
|
||||
assert.False(t, acc.HasFloatField("ping", "errors"),
|
||||
"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")
|
||||
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")
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|||
for _, metric := range intMetrics {
|
||||
_, ok := availableColumns[metric]
|
||||
if ok {
|
||||
assert.True(t, acc.HasIntField("postgresql", metric))
|
||||
assert.True(t, acc.HasInt64Field("postgresql", metric))
|
||||
metricsCounted++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ func TestPostgresqlGeneratesMetrics(t *testing.T) {
|
|||
for _, metric := range intMetrics {
|
||||
_, ok := availableColumns[metric]
|
||||
if ok {
|
||||
assert.True(t, acc.HasIntField("postgresql", metric))
|
||||
assert.True(t, acc.HasInt64Field("postgresql", metric))
|
||||
metricsCounted++
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ func TestMemcachedGeneratesMetrics(t *testing.T) {
|
|||
"meta-cache-size", "qsize-q", "signature-cache-size", "sys-msec", "uptime", "user-msec"}
|
||||
|
||||
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 {
|
||||
assert.True(t, acc.HasIntField("rabbitmq_overview", metric))
|
||||
assert.True(t, acc.HasInt64Field("rabbitmq_overview", metric))
|
||||
}
|
||||
|
||||
nodeIntMetrics := []string{
|
||||
|
@ -437,7 +437,7 @@ func TestRabbitMQGeneratesMetrics(t *testing.T) {
|
|||
}
|
||||
|
||||
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"))
|
||||
|
|
|
@ -36,7 +36,7 @@ func TestAddEngineStats(t *testing.T) {
|
|||
engine.AddEngineStats(keys, &acc, tags)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, acc.HasIntField("processes", "running"))
|
||||
assert.True(t, acc.HasIntField("processes", "sleeping"))
|
||||
assert.True(t, acc.HasIntField("processes", "stopped"))
|
||||
assert.True(t, acc.HasIntField("processes", "total"))
|
||||
assert.True(t, acc.HasInt64Field("processes", "running"))
|
||||
assert.True(t, acc.HasInt64Field("processes", "sleeping"))
|
||||
assert.True(t, acc.HasInt64Field("processes", "stopped"))
|
||||
assert.True(t, acc.HasInt64Field("processes", "total"))
|
||||
total, ok := acc.Get("processes")
|
||||
require.True(t, ok)
|
||||
assert.True(t, total.Fields["total"].(int64) > 0)
|
||||
|
|
|
@ -37,6 +37,6 @@ func TestZookeeperGeneratesMetrics(t *testing.T) {
|
|||
}
|
||||
|
||||
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
|
||||
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()
|
||||
defer a.Unlock()
|
||||
for _, p := range a.Metrics {
|
||||
|
|
Loading…
Reference in New Issue