Skip to content

Commit

Permalink
refactor: remove unused method in rest collector
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss authored and cgrinds committed Nov 20, 2024
1 parent 67790ce commit 74d756d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 72 deletions.
29 changes: 0 additions & 29 deletions cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,35 +295,6 @@ func TemplateFn(n *node.Node, obj string) string {
return fn
}

// Returns a slice of keys in dot notation from json
func getFieldName(source string, parent string) []string {
res := make([]string, 0)
var arr map[string]gjson.Result
r := gjson.Parse(source)
switch {
case r.IsArray():
newR := r.Get("0")
arr = newR.Map()
case r.IsObject():
arr = r.Map()
default:
return []string{parent}
}
if len(arr) == 0 {
return []string{parent}
}
for key, val := range arr {
var temp []string
if parent == "" {
temp = getFieldName(val.Raw, key)
} else {
temp = getFieldName(val.Raw, parent+"."+key)
}
res = append(res, temp...)
}
return res
}

// PollCounter performs daily tasks such as updating the cluster info and caching href.
func (r *Rest) PollCounter() (map[string]*matrix.Matrix, error) {

Expand Down
43 changes: 0 additions & 43 deletions cmd/collectors/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,6 @@ const (
pollerName = "test"
)

func Test_getFieldName(t *testing.T) {

type test struct {
name string
source string
parent string
want int
}

var tests = []test{
{
name: "Test1",
source: readFile("testdata/cluster.json"),
parent: "",
want: 52,
},
{
name: "Test2",
source: readFile("testdata/sample.json"),
parent: "",
want: 3,
},
{
name: "Test3",
source: readFile("testdata/test.json"),
parent: "",
want: 9,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getFieldName(tt.source, tt.parent); len(got) != tt.want {
t.Errorf("length of output slice = %v, want %v", len(got), tt.want)
}
})
}
}

func readFile(path string) string {
b, _ := os.ReadFile(path)
return string(b)
}

var (
ms []*matrix.Matrix
benchRest *Rest
Expand Down

0 comments on commit 74d756d

Please sign in to comment.