Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Removed checking not allowed characters
Browse files Browse the repository at this point in the history
  • Loading branch information
IzabellaRaulin committed Jan 16, 2017
1 parent 23c00fa commit 4154a15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ env:
- SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG}
matrix:
- TEST_TYPE=small
- TEST_TYPE=medium
- TEST_TYPE=legacy
- TEST_TYPE=build
matrix:
exclude:
Expand Down
12 changes: 2 additions & 10 deletions perfevents/perfevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const (
// Name of plugin
name = "perfevents"
// Version of plugin
version = 8
version = 9
// Type of plugin
pluginType = plugin.CollectorPluginType
// Namespace definition
Expand Down Expand Up @@ -276,7 +276,7 @@ func list_cgroups() ([]string, error) {
if info.IsDir() {
cgroup_name := strings.TrimPrefix(path, base_path)
if len(cgroup_name) > 0 {
cgroups = append(cgroups, removeNotAllowChars(cgroup_name))
cgroups = append(cgroups, cgroup_name)
}
}
return nil
Expand All @@ -287,14 +287,6 @@ func list_cgroups() ([]string, error) {
return cgroups, nil
}

func removeNotAllowChars(str string) string {
notAllowedChars := []string{"(", ")", "[", "]", "{", "}", " ", ".", ",", ";", "?", "!"}

for _, chr := range notAllowedChars {
str = strings.Replace(str, chr, "_", -1)
}
return str
}
func validateNamespace(namespace []string) error {
if len(namespace) != 6 {
return errors.New(fmt.Sprintf("unknown metricType %s (should containt exactly 6 segments)", namespace))
Expand Down
19 changes: 15 additions & 4 deletions perfevents/perfevents_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,25 @@ func TestPerfEventsCollector(t *testing.T) {
Convey("set_supported_metrics", func() {
cg := []string{"cgroup1", "cgroup2", "cgroup3"}
events := []string{"event1", "event2", "event3"}
a := set_supported_metrics(ns_subtype, cg, events)
a := get_supported_metrics(ns_subtype, cg, events)
So(len(a), ShouldEqual, 9)
So(a[len(a)-1].Namespace().Strings(), ShouldResemble, []string{ns_vendor, ns_class, ns_type, ns_subtype, "event3", "cgroup3"})
})
Convey("set_supported_metrics with special characters", func() {
cg := []string{"machine_slice:machine-quemu\x2d1\x2dinstance\x2d001"}
events := []string{"event1"}
a := get_supported_metrics(ns_subtype, cg, events)
So(a, ShouldNotBeNil)
So(len(a), ShouldEqual, 1)
So(a[0].Namespace().Strings(), ShouldResemble, []string{ns_vendor, ns_class, ns_type, ns_subtype, "event1", "machine_slice:machine-quemu\x2d1\x2dinstance\x2d001"})
})
Convey("flatten cgroup name", func() {
cg := []string{"cg_root/cg_sub1/cg_sub2"}
events := []string{"event"}
a := set_supported_metrics(ns_subtype, cg, events)
So(a[len(a)-1].Namespace().Strings(), ShouldContain, "cg_root_cg_sub1_cg_sub2")
events := []string{"event1"}
a := get_supported_metrics(ns_subtype, cg, events)
So(a, ShouldNotBeNil)
So(len(a), ShouldEqual, 1)
So(a[0].Namespace().Strings(), ShouldResemble, []string{ns_vendor, ns_class, ns_type, ns_subtype, "event1", "cg_root:cg_sub1:cg_sub2"})
})
})
Convey("CollectMetrics error cases", t, func() {
Expand Down

0 comments on commit 4154a15

Please sign in to comment.