ShivamSharma43 opened a new issue, #9379:
URL: https://github.com/apache/devlake/issues/9379

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/devlake/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### What happened
   
   `CollectUserSpend` (`plugins/cursor/tasks/user_spend_collector.go`) pages 
through `POST /teams/spend` with `GetNextPageCustomData: nextPostPage`. 
`nextPostPage` was written for `POST /teams/filtered-usage-events`. It decodes 
a `pagination` object and stops unless `pagination.hasNextPage` is true:
   
   ```go
   pagination, err := parsePagination(prevPageResponse)
   ...
   if !pagination.HasNextPage {
        return nil, helper.ErrFinishCollect
   }
   ```
   
   The spend endpoint has no `pagination` object. Per the [Admin API 
docs](https://cursor.com/docs/account/teams/admin-api) ("Get Spending Data"), 
its response has `teamMemberSpend`, `subscriptionCycleStart`, `totalMembers` 
and a top-level `totalPages`. So `HasNextPage` always decodes as `false`, and 
the collector stops after page 1.
   
   The page size is `cursorApiPageSize` (100). For a team with more than 100 
members, only the first 100 members' spend reaches `_raw_cursor_user_spend`. 
The rest are missing from the spend data and dashboards.
   
   ### What do you expect to happen
   
   The spend collector should keep requesting pages until it reaches the 
response's `totalPages`.
   
   ### How to reproduce
   
   Connect a Cursor team with more than 100 members and run the collection. 
`_raw_cursor_user_spend` has 100 rows, and only one `POST teams/spend` request 
is made.
   
   ### Anything else
   
   Proposed fix (I have a PR ready): add a `nextSpendPage` that reads the 
top-level `totalPages` and stops when the current page reaches it, and use it 
in `CollectUserSpend`. `nextPostPage` stays as it is for usage events and daily 
usage, which do return `pagination.hasNextPage`.
   
   ### Version
   
   main
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to