fix(copilot): Improve metrics ingestion performance #4784
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey, I just made a Pull Request!
This PR aims to improve the performance of the co-pilot back-end task by limiting the number of teams that it is actively trying to get the metrics from.
GitHub does not provide metrics for teams with less than five members, therefore we should not query the API for any team that has less than five members.
reference - https://docs.github.com/en/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-a-team
We can't easily verify if a user in the team has a copilot license, so we simply filter out any team with less than five members.
I also found a bug where we are loading the entire org/enterprise copilot seat list for each team in the org/enterprise, in pages of 100 memers. This may work well for small orgs with a few hundred members. But larger orgs with 1000s or members and teams will quickly run into performance issues and run our of API rate limit.
Taking my org as an example we have 3500 teams and 7000 users. So thats 70 API calls to list all the org users for each of the teams.
List teams = 35 calls
Gather Metrics for each team 3500 calls
Query seats for each team = (70 * 3500) = 248,500 calls..
lets say > 250k API calls.
With these changes we reduce the number of active teams to about 1500 (teams over 5 members) and only make the calls for seats once.
35+70+3500 = <4k calls..
HUGE difference in performance and API use.
✔️ Checklist
Signed-off-by
line in the message. (more info)Related to #4367