Commit 9d8c345e authored by Olivier Bourdon's avatar Olivier Bourdon

Fix test for proper execution with dynamic metrics

- increase plugin version
- adapt task example to dynamic metrics
- adapt task to new name of file publisher plugin
parent c79dfaaa
......@@ -44,7 +44,7 @@ const (
// PluginName df collector plugin name
PluginName = "df"
// Version of plugin
Version = 2
Version = 3
nsVendor = "intel"
nsClass = "procfs"
......@@ -134,16 +134,17 @@ func (p *dfCollector) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricTy
return metrics, fmt.Errorf(fmt.Sprintf("Unable to collect metrics from df: %s", err))
}
for _, mt := range mts {
ns := mt.Namespace()
if len(ns) < 5 {
return nil, fmt.Errorf("Wrong namespace length %d", len(ns))
for _, m := range mts {
ns := m.Namespace()
lns := len(ns)
if lns < 5 {
return nil, fmt.Errorf("Wrong namespace length %d", lns)
}
if ns[len(ns)-2].Value == "*" {
if ns[lns-2].Value == "*" {
for _, dfm := range dfms {
kind := ns[len(ns)-1].Value
kind := ns[lns-1].Value
ns1 := core.NewNamespace(createNamespace(dfm.MountPoint, kind)...)
ns1[len(ns1)-2].Name = ns[len(ns)-2].Name
ns1[len(ns1)-2].Name = ns[lns-2].Name
metric := plugin.MetricType{
Timestamp_: curTime,
Namespace_: ns1,
......@@ -153,12 +154,12 @@ func (p *dfCollector) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricTy
}
} else {
for _, dfm := range dfms {
if ns[len(ns)-2].Value == dfm.MountPoint {
if ns[lns-2].Value == dfm.MountPoint {
metric := plugin.MetricType{
Timestamp_: curTime,
Namespace_: ns,
}
kind := ns[len(ns)-1].Value
kind := ns[lns-1].Value
fillMetric(kind, dfm, &metric)
metrics = append(metrics, metric)
}
......
......@@ -75,7 +75,6 @@ func (dfp *DfPluginSuite) SetupSuite() {
func (dfp *DfPluginSuite) TestGetMetricTypes() {
Convey("Given df plugin is initialized", dfp.T(), func() {
//dfPlg := NewDfCollector()
dfPlg := dfCollector{
stats: dfp.mockCollector,
}
......@@ -117,7 +116,6 @@ func (dfp *DfPluginSuite) TestGetMetricTypes() {
func (dfp *DfPluginSuite) TestCollectMetrics() {
Convey("Given df plugin is initialized", dfp.T(), func() {
//dfPlg := NewDfCollector()
dfPlg := dfCollector{
stats: dfp.mockCollector,
}
......@@ -135,35 +133,21 @@ func (dfp *DfPluginSuite) TestCollectMetrics() {
for _, m := range mts {
ns = append(ns, m.Namespace().String())
}
So(len(mts), ShouldEqual, 28)
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/space_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/inodes_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/device_name")
So(ns, ShouldContain, "/intel/procfs/filesystem/rootfs/device_type")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/space_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/inodes_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/device_name")
So(ns, ShouldContain, "/intel/procfs/filesystem/big/device_type")
So(len(mts), ShouldEqual, 14)
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/space_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_percent_free")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_percent_reserved")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/inodes_percent_used")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/device_name")
So(ns, ShouldContain, "/intel/procfs/filesystem/*/device_type")
})
})
})
......
......@@ -7,12 +7,12 @@
"workflow": {
"collect": {
"metrics": {
"/intel/procfs/filesystem/rootfs/space_free": {},
"/intel/procfs/filesystem/rootfs/space_reserved": {},
"/intel/procfs/filesystem/rootfs/inodes_percent_free": {},
"/intel/procfs/filesystem/rootfs/inodes_percent_used": {},
"/intel/procfs/filesystem/rootfs/device_name": {},
"/intel/procfs/filesystem/sys_fs_cgroup/inodes_used": {}
"/intel/procfs/filesystem/*/space_free": {},
"/intel/procfs/filesystem/*/space_reserved": {},
"/intel/procfs/filesystem/*/inodes_percent_free": {},
"/intel/procfs/filesystem/*/inodes_percent_used": {},
"/intel/procfs/filesystem/*/device_name": {},
"/intel/procfs/filesystem/*/inodes_used": {}
},
"config": {
"/intel/procfs/filesystem": {
......@@ -22,7 +22,7 @@
"process": null,
"publish": [
{
"plugin_name": "file",
"plugin_name": "mock-file",
"config": {
"file": "/tmp/published_df.log"
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment