Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove unused method in rest collector #3308

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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