Skip to content

Commit

Permalink
perf: Restperf should stream results while parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Dec 5, 2024
1 parent 9a0c0fe commit b08e040
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/collectors/restperf/restperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ func (r *RestPerf) PollData() (map[string]*matrix.Matrix, error) {

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

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

recordsFound := false
for {
response, err := client.GetRest(nextLink, headers...)
if err != nil {
Expand All @@ -487,15 +487,11 @@ func FetchRestPerfDataStream(client *Client, href string, processBatch func([]Pe
next := output.Get("_links.next.href")

if numRecords.Int() > 0 {
recordsFound = true
p := PerfRecord{Records: data, Timestamp: time.Now().UnixNano()}
if err := processBatch([]PerfRecord{p}); err != nil {
return err
}
} else {
// Call processBatch with an empty list to handle no records scenario
if err := processBatch([]PerfRecord{}); err != nil {
return err
}
}

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

return nil
}
Expand Down

0 comments on commit b08e040

Please sign in to comment.