Skip to content

fix(copilot): Improve metrics ingestion performance #4784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ScottGuymer
Copy link
Contributor

@ScottGuymer ScottGuymer commented Jul 28, 2025

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.

CleanShot 2025-07-28 at 16 30 47

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

  • A changeset describing the change and affected packages. (more info)
  • Added or updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)
  • All your commits have a Signed-off-by line in the message. (more info)

Related to #4367

@ScottGuymer ScottGuymer requested a review from a team as a code owner July 28, 2025 14:36
@ScottGuymer ScottGuymer requested a review from BethGriggs July 28, 2025 14:36
@backstage-goalie
Copy link
Contributor

Changed Packages

Package Name Package Path Changeset Bump Current Version
@backstage-community/plugin-copilot-backend workspaces/copilot/plugins/copilot-backend minor v0.10.0

@ScottGuymer ScottGuymer changed the title Scott/copilot performance copilot: Improve ingestion performance by filtering teams smaller than 5 Jul 28, 2025
@ScottGuymer ScottGuymer changed the title copilot: Improve ingestion performance by filtering teams smaller than 5 fix(copilot): Improve ingestion performance by filtering teams smaller than 5 Jul 28, 2025
@ScottGuymer ScottGuymer force-pushed the scott/copilot_performance branch from 54582fe to a5d15a5 Compare July 31, 2025 12:38
Improve teams loading by only returning teams that have more than 5 people in them.

Signed-off-by: Scott Guymer <[email protected]>
Signed-off-by: Scott Guymer <[email protected]>
@ScottGuymer ScottGuymer force-pushed the scott/copilot_performance branch from a5d15a5 to cf8d38e Compare July 31, 2025 12:40
@ScottGuymer ScottGuymer changed the title fix(copilot): Improve ingestion performance by filtering teams smaller than 5 fix(copilot): Improve metrics ingestion performance Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant