From 6f1884aae757e93704b45bb9a0346c77713d1058 Mon Sep 17 00:00:00 2001 From: rahulguptajss Date: Thu, 5 Dec 2024 22:29:35 +0530 Subject: [PATCH] fix: rest no instance handling --- cmd/collectors/rest/rest.go | 2 +- cmd/tools/rest/rest.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/collectors/rest/rest.go b/cmd/collectors/rest/rest.go index 5eef91991..67b0c2fb6 100644 --- a/cmd/collectors/rest/rest.go +++ b/cmd/collectors/rest/rest.go @@ -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 diff --git a/cmd/tools/rest/rest.go b/cmd/tools/rest/rest.go index d0b21d83b..66807bb12 100644 --- a/cmd/tools/rest/rest.go +++ b/cmd/tools/rest/rest.go @@ -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 @@ -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 @@ -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 }