Commit 385c9e7a authored by Olivier Bourdon's avatar Olivier Bourdon

Rename invalid into excluded

parent 5a30159c
......@@ -73,7 +73,7 @@ var (
"device_name",
"device_type",
}
dfltInvalidFSTypes = []string{
dfltExcludedFSTypes = []string{
"proc",
"binfmt_misc",
"fuse.gvfsd-fuse",
......@@ -114,15 +114,15 @@ func (p *dfCollector) setProcPath(cfg interface{}) error {
}
p.proc_path = procPath.(string)
}
invalidFSTypes, err := config.GetConfigItem(cfg, "invalid_fs_types")
excludedFSTypes, err := config.GetConfigItem(cfg, "excluded_fs_types")
if err == nil {
if len(invalidFSTypes.(string)) > 0 {
p.invalid_fs_types = strings.Split(invalidFSTypes.(string), ",")
if len(excludedFSTypes.(string)) > 0 {
p.excluded_fs_types = strings.Split(excludedFSTypes.(string), ",")
} else {
p.invalid_fs_types = []string{}
p.excluded_fs_types = []string{}
}
} else {
p.invalid_fs_types = dfltInvalidFSTypes
p.excluded_fs_types = dfltExcludedFSTypes
}
p.initialized = true
return nil
......@@ -152,7 +152,7 @@ func (p *dfCollector) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricTy
}
metrics := []plugin.MetricType{}
curTime := time.Now()
dfms, err := p.stats.collect(p.proc_path, p.invalid_fs_types)
dfms, err := p.stats.collect(p.proc_path, p.excluded_fs_types)
if err != nil {
return metrics, fmt.Errorf(fmt.Sprintf("Unable to collect metrics from df: %s", err))
}
......@@ -292,7 +292,7 @@ func (p *dfCollector) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
node := cpolicy.NewPolicyNode()
node.Add(rule)
cp.Add([]string{nsVendor, nsClass, PluginName}, node)
rule, _ = cpolicy.NewStringRule("invalid_fs_types", false, strings.Join(dfltInvalidFSTypes, ","))
rule, _ = cpolicy.NewStringRule("excluded_fs_types", false, strings.Join(dfltExcludedFSTypes, ","))
node.Add(rule)
return cp, nil
}
......@@ -302,11 +302,11 @@ func NewDfCollector() *dfCollector {
logger := log.New()
imutex := new(sync.Mutex)
return &dfCollector{
stats: &dfStats{},
logger: logger,
initializedMutex: imutex,
proc_path: procPath,
invalid_fs_types: dfltInvalidFSTypes,
stats: &dfStats{},
logger: logger,
initializedMutex: imutex,
proc_path: procPath,
excluded_fs_types: dfltExcludedFSTypes,
}
}
......@@ -323,12 +323,12 @@ func Meta() *plugin.PluginMeta {
}
type dfCollector struct {
initialized bool
initializedMutex *sync.Mutex
stats collector
logger *log.Logger
proc_path string
invalid_fs_types []string
initialized bool
initializedMutex *sync.Mutex
stats collector
logger *log.Logger
proc_path string
excluded_fs_types []string
}
type dfMetric struct {
......@@ -348,7 +348,7 @@ type collector interface {
type dfStats struct{}
func (dfs *dfStats) collect(procPath string, invalid_fs_types []string) ([]dfMetric, error) {
func (dfs *dfStats) collect(procPath string, excluded_fs_types []string) ([]dfMetric, error) {
dfms := []dfMetric{}
cpath := path.Join(procPath, "1", "mountinfo")
fh, err := os.Open(cpath)
......@@ -375,7 +375,7 @@ func (dfs *dfStats) collect(procPath string, invalid_fs_types []string) ([]dfMet
return nil, fmt.Errorf("Wrong format %d fields found on the right side instead of 7 min", len(rightFields))
}
// Keep only meaningfull filesystems
if invalidFSType(rightFields[0], invalid_fs_types) {
if excludedFSType(rightFields[0], excluded_fs_types) {
log.Debug(fmt.Sprintf("Ignoring mount point %s with FS type %s",
leftFields[4], rightFields[0]))
} else {
......@@ -418,8 +418,8 @@ func (dfs *dfStats) collect(procPath string, invalid_fs_types []string) ([]dfMet
}
// Return true if filesystem should not be taken into account
func invalidFSType(fs string, invalidFSTypes []string) bool {
for _, v := range invalidFSTypes {
func excludedFSType(fs string, excludedFSTypes []string) bool {
for _, v := range excludedFSTypes {
if fs == v {
return true
}
......
......@@ -71,8 +71,8 @@ func (dfp *DfPluginSuite) SetupSuite() {
IUse: 0.5,
},
}
mc.On("collect", "/proc", dfltInvalidFSTypes).Return(dfms, nil)
mc.On("collect", "/dummy", dfltInvalidFSTypes).Return(dfms, errors.New("Fake error"))
mc.On("collect", "/proc", dfltExcludedFSTypes).Return(dfms, nil)
mc.On("collect", "/dummy", dfltExcludedFSTypes).Return(dfms, errors.New("Fake error"))
dfp.mockCollector = mc
dfp.cfg = plugin.ConfigType{}
}
......@@ -436,31 +436,31 @@ func (dfp *DfPluginSuite) TestHelperRoutines() {
Convey("Then no error should be reported (already called)", func() {
So(err, ShouldBeNil)
So(len(dfPlg.invalid_fs_types), ShouldEqual, 18)
So(len(dfPlg.excluded_fs_types), ShouldEqual, 18)
})
node = cdata.NewNode()
node.AddItem("invalid_fs_types", ctypes.ConfigValueStr{Value: ""})
node.AddItem("excluded_fs_types", ctypes.ConfigValueStr{Value: ""})
dfPlg = NewDfCollector()
dfPlg.stats = dfp.mockCollector
cfg = plugin.ConfigType{ConfigDataNode: node}
err = dfPlg.setProcPath(cfg)
Convey("Then no error should be reported (invalid_fs_types with proper value for empty string)", func() {
Convey("Then no error should be reported (excluded_fs_types with proper value for empty string)", func() {
So(err, ShouldBeNil)
So(len(dfPlg.invalid_fs_types), ShouldEqual, 0)
So(len(dfPlg.excluded_fs_types), ShouldEqual, 0)
})
node = cdata.NewNode()
node.AddItem("invalid_fs_types", ctypes.ConfigValueStr{Value: "fs1,fs2"})
node.AddItem("excluded_fs_types", ctypes.ConfigValueStr{Value: "fs1,fs2"})
dfPlg = NewDfCollector()
dfPlg.stats = dfp.mockCollector
cfg = plugin.ConfigType{ConfigDataNode: node}
err = dfPlg.setProcPath(cfg)
Convey("Then no error should be reported (invalid_fs_types with proper value)", func() {
Convey("Then no error should be reported (excluded_fs_types with proper value)", func() {
So(err, ShouldBeNil)
So(len(dfPlg.invalid_fs_types), ShouldEqual, 2)
So(len(dfPlg.excluded_fs_types), ShouldEqual, 2)
})
})
......@@ -494,13 +494,13 @@ func (dfp *DfPluginSuite) TestHelperRoutines() {
})
l := []string{"1", "2", "3", "4"}
v = invalidFSType("3", l)
v = excludedFSType("3", l)
Convey("Then value should be reported as found", func() {
So(v, ShouldEqual, true)
})
v = invalidFSType("error", l)
v = excludedFSType("error", l)
Convey("Then value should be reported as not found", func() {
So(v, ShouldEqual, false)
......
......@@ -17,7 +17,7 @@
"config": {
"/intel/procfs/filesystem": {
"proc_path": "/proc",
"invalid_fs_types": "proc,binfmt_misc,fuse.gvfsd-fuse,sysfs,cgroup,fusectl,pstore,debugfs,securityfs,devpts,mqueue,hugetlbfs,nsfs,rpc_pipefs,devtmpfs,none,tmpfs,aufs"
"excluded_fs_types": "proc,binfmt_misc,fuse.gvfsd-fuse,sysfs,cgroup,fusectl,pstore,debugfs,securityfs,devpts,mqueue,hugetlbfs,nsfs,rpc_pipefs,devtmpfs,none,tmpfs,aufs"
}
},
"process": null,
......
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