0.3.0 unit tests: procstat, prometheus, puppetagent
This commit is contained in:
parent
6eb49dee5d
commit
ccbd7bb785
|
@ -5,6 +5,8 @@
|
|||
- **breaking change** Plugin measurements aggregated into a single measurement.
|
||||
- **breaking change** `jolokia` plugin: must use global tag/drop/pass parameters
|
||||
for configuration.
|
||||
- **breaking change** `procstat` plugin has `*cpu*` fields renamed to
|
||||
`*cpu_time*`
|
||||
- `twemproxy` plugin: `prefix` option removed.
|
||||
- `procstat` cpu measurements are now prepended with `cpu_time_` instead of
|
||||
only `cpu_`
|
||||
|
|
|
@ -20,11 +20,11 @@ func TestGather(t *testing.T) {
|
|||
file.Write([]byte(strconv.Itoa(pid)))
|
||||
file.Close()
|
||||
defer os.Remove(file.Name())
|
||||
specifications := []*Specification{&Specification{PidFile: file.Name(), Prefix: "foo"}}
|
||||
p := Procstat{
|
||||
Specifications: specifications,
|
||||
PidFile: file.Name(),
|
||||
Prefix: "foo",
|
||||
}
|
||||
p.Gather(&acc)
|
||||
assert.True(t, acc.HasFloatValue("foo_cpu_user"))
|
||||
assert.True(t, acc.HasUIntValue("foo_memory_vms"))
|
||||
assert.True(t, acc.HasFloatField("procstat", "foo_cpu_time_user"))
|
||||
assert.True(t, acc.HasUIntField("procstat", "foo_memory_vms"))
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@ func (g *Prometheus) gatherURL(url string, acc plugins.Accumulator) error {
|
|||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("error getting processing samples for %s: %s", url, err)
|
||||
return fmt.Errorf("error getting processing samples for %s: %s",
|
||||
url, err)
|
||||
}
|
||||
for _, sample := range samples {
|
||||
tags := make(map[string]string)
|
||||
|
|
|
@ -45,11 +45,11 @@ func TestPrometheusGeneratesMetrics(t *testing.T) {
|
|||
value float64
|
||||
tags map[string]string
|
||||
}{
|
||||
{"go_gc_duration_seconds_count", 7, map[string]string{}},
|
||||
{"go_goroutines", 15, map[string]string{}},
|
||||
{"prometheus_go_gc_duration_seconds_count", 7, map[string]string{}},
|
||||
{"prometheus_go_goroutines", 15, map[string]string{}},
|
||||
}
|
||||
|
||||
for _, e := range expected {
|
||||
assert.NoError(t, acc.ValidateValue(e.name, e.value))
|
||||
assert.True(t, acc.HasFloatField(e.name, "value"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package puppetagent
|
|||
|
||||
import (
|
||||
"github.com/influxdb/telegraf/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
@ -14,61 +13,36 @@ func TestGather(t *testing.T) {
|
|||
}
|
||||
pa.Gather(&acc)
|
||||
|
||||
checkInt := []struct {
|
||||
name string
|
||||
value int64
|
||||
}{
|
||||
{"events_failure", 0},
|
||||
{"events_total", 0},
|
||||
{"events_success", 0},
|
||||
{"resources_failed", 0},
|
||||
{"resources_scheduled", 0},
|
||||
{"resources_changed", 0},
|
||||
{"resources_skipped", 0},
|
||||
{"resources_total", 109},
|
||||
{"resources_failedtorestart", 0},
|
||||
{"resources_restarted", 0},
|
||||
{"resources_outofsync", 0},
|
||||
{"changes_total", 0},
|
||||
{"time_lastrun", 1444936531},
|
||||
{"version_config", 1444936521},
|
||||
}
|
||||
|
||||
for _, c := range checkInt {
|
||||
assert.Equal(t, true, acc.CheckValue(c.name, c.value))
|
||||
}
|
||||
|
||||
checkFloat := []struct {
|
||||
name string
|
||||
value float64
|
||||
}{
|
||||
{"time_user", 0.004331},
|
||||
{"time_schedule", 0.001123},
|
||||
{"time_filebucket", 0.000353},
|
||||
{"time_file", 0.441472},
|
||||
{"time_exec", 0.508123},
|
||||
{"time_anchor", 0.000555},
|
||||
{"time_sshauthorizedkey", 0.000764},
|
||||
{"time_service", 1.807795},
|
||||
{"time_package", 1.325788},
|
||||
{"time_total", 8.85354707064819},
|
||||
{"time_configretrieval", 4.75567007064819},
|
||||
{"time_cron", 0.000584},
|
||||
}
|
||||
|
||||
for _, f := range checkFloat {
|
||||
assert.Equal(t, true, acc.CheckValue(f.name, f.value))
|
||||
}
|
||||
|
||||
checkString := []struct {
|
||||
name string
|
||||
value string
|
||||
}{
|
||||
{"version_puppet", "3.7.5"},
|
||||
}
|
||||
|
||||
for _, s := range checkString {
|
||||
assert.Equal(t, true, acc.CheckValue(s.name, s.value))
|
||||
tags := map[string]string{"location": "last_run_summary.yaml"}
|
||||
fields := map[string]interface{}{
|
||||
"events_failure": int64(0),
|
||||
"events_total": int64(0),
|
||||
"events_success": int64(0),
|
||||
"resources_failed": int64(0),
|
||||
"resources_scheduled": int64(0),
|
||||
"resources_changed": int64(0),
|
||||
"resources_skipped": int64(0),
|
||||
"resources_total": int64(109),
|
||||
"resources_failedtorestart": int64(0),
|
||||
"resources_restarted": int64(0),
|
||||
"resources_outofsync": int64(0),
|
||||
"changes_total": int64(0),
|
||||
"time_lastrun": int64(1444936531),
|
||||
"version_config": int64(1444936521),
|
||||
"time_user": float64(0.004331),
|
||||
"time_schedule": float64(0.001123),
|
||||
"time_filebucket": float64(0.000353),
|
||||
"time_file": float64(0.441472),
|
||||
"time_exec": float64(0.508123),
|
||||
"time_anchor": float64(0.000555),
|
||||
"time_sshauthorizedkey": float64(0.000764),
|
||||
"time_service": float64(1.807795),
|
||||
"time_package": float64(1.325788),
|
||||
"time_total": float64(8.85354707064819),
|
||||
"time_configretrieval": float64(4.75567007064819),
|
||||
"time_cron": float64(0.000584),
|
||||
"version_puppet": "3.7.5",
|
||||
}
|
||||
|
||||
acc.AssertContainsTaggedFields(t, "puppetagent", fields, tags)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue