Skip to content

Commit

Permalink
fix: rest no instance handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Dec 5, 2024
1 parent bb6faf6 commit 6f1884a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/collectors/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (r *Rest) PollData() (map[string]*matrix.Matrix, error) {

processBatch := func(records []gjson.Result) error {
if len(records) == 0 {
return errs.New(errs.ErrNoInstance, "no "+r.Object+" instances on cluster")
return nil
}

// Process the current batch of records
Expand Down
14 changes: 11 additions & 3 deletions cmd/tools/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ func FetchAnalytics(client *Client, href string) ([]gjson.Result, gjson.Result,
func FetchAllStream(client *Client, href string, processBatch func([]gjson.Result) error, headers ...map[string]string) error {
var prevLink string
nextLink := href
recordsFound := false

for {
var records []gjson.Result
Expand All @@ -483,12 +484,16 @@ func FetchAllStream(client *Client, href string, processBatch func([]gjson.Resul

output := gjson.ParseBytes(response)
data := output.Get("records")
numRecords := output.Get("num_records")
next := output.Get("_links.next.href")

if data.Exists() {
// Process the current batch of records
if err := processBatch(data.Array()); err != nil {
return err
if numRecords.Int() > 0 {
recordsFound = true
// Process the current batch of records
if err := processBatch(data.Array()); err != nil {
return err
}
}

prevLink = nextLink
Expand All @@ -513,6 +518,9 @@ func FetchAllStream(client *Client, href string, processBatch func([]gjson.Resul
break
}
}
if !recordsFound {
return errs.New(errs.ErrNoInstance, "no instances found")
}

return nil
}
Expand Down

0 comments on commit 6f1884a

Please sign in to comment.