Skip to content

Commit a5cfc56

Browse files
authored
Merge pull request #138 from github-copilot-resources/feature/new-copilot-metrics
Feature/new copilot metrics API - replaces #125
2 parents 495fcfc + b5a8a41 commit a5cfc56

33 files changed

+5852
-298
lines changed

.github/workflows/playwright.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
-e SESSION_SECRET=dummy \
5757
api:test "@org"
5858
- uses: actions/upload-artifact@v4
59-
if: ${{ !cancelled() }}
59+
if: always()
6060
with:
6161
name: playwright-report-docker-org
6262
path: test-results-docker-org/
@@ -89,7 +89,7 @@ jobs:
8989
-e SESSION_SECRET=dummy \
9090
api:test "@ent"
9191
- uses: actions/upload-artifact@v4
92-
if: ${{ !cancelled() }}
92+
if: always()
9393
with:
9494
name: playwright-report-docker-ent
9595
path: test-results-docker-ent/

README.md

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,51 @@ This application displays a set of charts with various metrics related to GitHub
1111

1212
https://github.com/github-copilot-resources/copilot-metrics-viewer/assets/3329307/bc7e2a16-cc73-43c4-887a-b50809c08533
1313

14-
1514
## Charts
1615

1716
## Key Metrics
17+
>[!NOTE]
18+
> Metrics details are described in detail in [GitHub API response schema](https://docs.github.com/en/rest/copilot/copilot-metrics?apiVersion=2022-11-28#get-copilot-metrics-for-an-organization)
19+
1820
Here are the key metrics visualized in these charts:
19-
1. **Acceptance Rate:** This metric represents the ratio of accepted lines to the total lines suggested by GitHub Copilot. This rate is an indicator of the relevance and usefulness of Copilot's suggestions.
2021
<p align="center">
21-
<img width="800" alt="image" src="https://github.com/martedesco/copilot-metrics-viewer/assets/3329307/875a5f5f-5d8a-44bd-a4e9-0f663f2b2628">
22+
<img width="800" alt="image" src="./images/KeyMetrics.png">
2223
</p>
2324

24-
2. **Total Suggestions** This chart illustrates the total number of code suggestions made by GitHub Copilot. It offers a view of the tool's activity and its engagement with users over time.
25+
1. **Acceptance Rate:** This metric represents the ratio of accepted lines and suggestions to the total suggested by GitHub Copilot. This rate is an indicator of the relevance and usefulness of Copilot's suggestions. However, as with any metric, it should be used with caution as developers use Copilot in many different ways (research, confirm, verify, etc., not always "inject").
26+
<p align="center">
27+
<img width="800" alt="image" src="./images/Acceptance_rate_bycount.png">
28+
</p>
2529

26-
3. **Total Acceptances:** This visualization focuses on the total number of suggestions accepted by users.
30+
2. **Total Suggestions:** This chart illustrates the total number of code suggestions made by GitHub Copilot. It offers a view of the tool's activity and its engagement with users over time.
2731

32+
3. **Total Acceptances:** This visualization focuses on the total number of suggestions accepted by users.
2833
<p align="center">
29-
<img width="800" alt="image" src="https://github.com/martedesco/copilot-metrics-viewer/assets/3329307/b84220ae-fbdc-4503-b50b-4689362bf364">
34+
<img width="800" alt="image" src="./images/Total_suggestions_count.png">
3035
</p>
3136

3237
4. **Total Lines Suggested:** Showcases the total number of lines of code suggested by GitHub Copilot. This gives an idea of the volume of code generation and assistance provided.
3338

34-
5. **Total Lines Accepted:** As the name says, the total lines of code accepted by users (full acceptances) offering insights into how much of the suggested code is actually being utilized incorporated to the codebase.
35-
39+
5. **Total Lines Accepted:** As the name suggests, the total lines of code accepted by users (full acceptances) offering insights into how much of the suggested code is actually being utilized and incorporated into the codebase.
3640
<p align="center">
37-
<img width="800" alt="image" src="https://github.com/martedesco/copilot-metrics-viewer/assets/3329307/788c9b33-8e63-43a5-9ab9-98d8938dd9d9">
41+
<img width="800" alt="image" src="./images/Total Lines.png">
3842
</p>
3943

4044
6. **Total Active Users:** Represents the number of active users engaging with GitHub Copilot. This helps in understanding the user base growth and adoption rate.
41-
4245
<p align="center">
43-
<img width="800" alt="image" src="https://github.com/martedesco/copilot-metrics-viewer/assets/3329307/bd92918f-3a11-492b-8490-877aaa768ca3">
46+
<img width="800" alt="image" src="./images/Total_Active_users.png">
4447
</p>
4548

4649
## Languages Breakdown Analysis
4750

48-
Pie charts with the top 5 languages by accepted prompts and acceptance rate are displayed at the top.
51+
Pie charts with the top 5 languages by accepted prompts and acceptance rate (by count/by lines) are displayed at the top.
4952
<p align="center">
50-
<img width="800" alt="image" src="https://github.com/github-copilot-resources/copilot-metrics-viewer/assets/3329307/8ab0488a-89e6-486d-aa61-df3d178cd57c">
53+
<img width="800" alt="image" src="./images/Language_breakdown.png">
5154
</p>
5255

5356
The language breakdown analysis tab also displays a table showing the Accepted Prompts, Accepted Lines of Code, and Acceptance Rate (%) for each language over the past 28 days. The entries are sorted by the number of _accepted lines of code descending_.
54-
5557
<p align="center">
56-
<img width="800" alt="image" src="https://github.com/github-copilot-resources/copilot-metrics-viewer/assets/3329307/38a4ff57-4974-4f60-a154-91db17b03678">
58+
<img width="800" alt="image" src="./images/Language_breakdown_list.png">
5759
</p>
5860

5961
## Copilot Chat Metrics
@@ -66,25 +68,24 @@ The language breakdown analysis tab also displays a table showing the Accepted P
6668

6769
2. **Cumulative Number of Acceptances:** This metric shows the total number of lines of code suggested by Copilot that have been accepted by users over the past 28 days.
6870

69-
3. **Total Turns | Total Acceptances Count:** This is a chart that displays the total number of turns and acceptances
71+
3. **Total Turns | Total Acceptances Count:** This is a chart that displays the total number of turns and acceptances.
7072

71-
4. **Total Active Copilot Chat Users:** a bar chart that illustrates the total number of users who have actively interacted with Copilot over the past 28 days.
73+
4. **Total Active Copilot Chat Users:** A bar chart that illustrates the total number of users who have actively interacted with Copilot over the past 28 days.
7274

7375
## Seat Analysis
7476
<p align="center">
7577
<img width="800" alt="image" src="https://github.com/github-copilot-resources/copilot-metrics-viewer/assets/54096296/51747194-df30-4bfb-8849-54a0510fffcb">
7678
</p>
7779

78-
1. **Total Assigned:** This metric represents the total number of Copilot seats assigned within current organization/enterprise.
80+
1. **Total Assigned:** This metric represents the total number of Copilot seats assigned within the current organization/enterprise.
7981

8082
2. **Assigned But Never Used:** This metric shows seats that were assigned but never used within the current organization/enterprise. The assigned timestamp is also displayed in the chart.
8183

82-
3. **No Activity in the Last 7 days:** never used seats or seats used, but with no activity in the past 7 days.
84+
3. **No Activity in the Last 7 Days:** Never used seats or seats used, but with no activity in the past 7 days.
8385

84-
4. **No Activity in the last 7 days (including never used seats):** a table to display seats that have had no activity in the past 7 days, ordered by the date of last activity. Seats that were used earlier are displayed at the top.
86+
4. **No Activity in the Last 7 Days (including never used seats):** A table to display seats that have had no activity in the past 7 days, ordered by the date of last activity. Seats that were used earlier are displayed at the top.
8587

86-
87-
## Setup instructions
88+
## Setup Instructions
8889

8990
In the `.env` file, you can configure several environment variables that control the behavior of the application.
9091

@@ -100,77 +101,81 @@ For example, if you want to target the API calls to an organization, you would s
100101
````
101102
VUE_APP_SCOPE=organization
102103
103-
VUE_APP_GITHUB_ORG= <YOUR-ORGANIZATION>
104+
VUE_APP_GITHUB_ORG=<YOUR-ORGANIZATION>
104105
105106
VUE_APP_GITHUB_ENT=
106107
````
108+
107109
#### VUE_APP_GITHUB_TEAM
108110

109111
The `VUE_APP_GITHUB_TEAM` environment variable filters metrics for a specific GitHub team within an Enterprise or Organization account.
110112
‼️ Important ‼️ When this variable is set, all displayed metrics will pertain exclusively to the specified team. To view metrics for the entire Organization or Enterprise, remove this environment variable.
111113

112114
````
113115
VUE_APP_GITHUB_TEAM=
114-
115116
````
116117

117118
#### VUE_APP_MOCKED_DATA
118119

119120
To access Copilot metrics from the last 28 days via the API and display actual data, set the following boolean environment variable to `false`:
120121

121-
```
122-
VUE_APP_MOCKED_DATA=false
123-
```
122+
````
123+
VUE_APP_MOCKED_DATA=false
124+
````
124125

125126
#### VUE_APP_GITHUB_TOKEN
127+
126128
Specifies the GitHub Personal Access Token utilized for API requests. Generate this token with the following scopes: _copilot_, _manage_billing:copilot_, _manage_billing:enterprise_, _read:enterprise_, _read:org_.
127129

128-
```
129-
VUE_APP_GITHUB_TOKEN=
130-
```
130+
````
131+
VUE_APP_GITHUB_TOKEN=
132+
````
131133

132-
## Install dependencies
133-
```
134+
## Install Dependencies
135+
136+
```bash
134137
npm install
135138
```
136139

137-
### Compiles and runs the application
138-
```
140+
### Compiles and Runs the Application
141+
142+
```bash
139143
npm run serve
140144
```
141145

142-
### Docker build
143-
```
146+
### Docker Build
147+
148+
```bash
144149
docker build -t copilot-metrics-viewer .
145150
```
146151

147-
### Docker run
148-
```
152+
### Docker Run
153+
154+
```bash
149155
docker run -p 8080:80 --env-file ./.env copilot-metrics-viewer
150156
```
157+
151158
The application will be accessible at http://localhost:8080
152159

153160
## Running with API Proxy
154161

155-
Project can run with an API proxy which hides GitHub tokens and is secure enough to be deployed.
156-
Api Proxy project is in `\api` directory. Vue app makes the calls to `/api/github` which then are proxied to `https://api.github.com` with appropriate bearer token.
157-
158-
Proxy can authenticate user using GitHub App. In order to do that, following environment variables are required:
162+
The project can run with an API proxy which hides GitHub tokens and is secure enough to be deployed.
163+
The API Proxy project is in the `\api` directory. The Vue app makes the calls to `/api/github` which are then proxied to `https://api.github.com` with the appropriate bearer token.
159164

160-
* `GITHUB_CLIENT_ID` - client Id of the GitHub App registered and installed in the enterprise/org with permissions listed above.
161-
* `GITHUB_CLIENT_SECRET` - client secret of the GitHub App
162-
* `SESSION_SECRET` - random string for securing session state
165+
The proxy can authenticate the user using a GitHub App. In order to do that, the following environment variables are required:
163166

164-
If you want use a custom path for your `.env` file you can set the environment variable `DOTENV_CONFIG_PATH`.
167+
* `GITHUB_CLIENT_ID` - client ID of the GitHub App registered and installed in the enterprise/org with permissions listed above.
168+
* `GITHUB_CLIENT_SECRET` - client secret of the GitHub App.
169+
* `SESSION_SECRET` - random string for securing session state.
165170

166-
https://github.com/user-attachments/assets/e5596067-da9c-409d-9b9f-0a688cc1f2c4
171+
If you want to use a custom path for your `.env` file, you can set the environment variable `DOTENV_CONFIG_PATH`.
167172

168-
It's also possible to run with **PAT Token**, see examples below for required variables.
173+
It's also possible to run with a **PAT Token**, see examples below for required variables.
169174

170-
For local development register `http://localhost:3000/callback` as GH App callback Uri.
171-
For deployed version use the Uri of your app.
175+
For local development, register `http://localhost:3000/callback` as the GitHub App callback URI.
176+
For the deployed version, use the URI of your app.
172177

173-
To build and run the app with API proxy:
178+
To build and run the app with the API proxy:
174179

175180
```bash
176181
docker build -t copilot-metrics-viewer-with-proxy -f api.Dockerfile .
@@ -182,7 +187,7 @@ To run:
182187
docker run -it --rm -p 8080:3000 --env-file ./.env copilot-metrics-viewer-with-proxy
183188
```
184189

185-
Or with custom path for your `.env` file:
190+
Or with a custom path for your `.env` file:
186191

187192
```bash
188193
docker run -it --rm -p 8080:3000 \
@@ -191,7 +196,7 @@ docker run -it --rm -p 8080:3000 \
191196
copilot-metrics-viewer-with-proxy
192197
```
193198

194-
Proxy can also run with token hardcoded on the backend (which hides it from frontend calls), here's a sample:
199+
The proxy can also run with the token hardcoded on the backend (which hides it from frontend calls), here's a sample:
195200

196201
```bash
197202
docker run -it --rm -p 3000:3000 \
@@ -225,6 +230,6 @@ This project is licensed under the terms of the MIT open source license. Please
225230

226231
## Support
227232

228-
This project is independently developed and maintained, and is not an official GitHub product. It thrives through the dedicated efforts of ([@martedesco](https://github.com/martedesco)), ([@karpikpl](https://github.com/karpikpl)) our wonderful contributors. A heartfelt thanks to all our contributors! ✨
233+
This project is independently developed and maintained, and is not an official GitHub product. It thrives through the dedicated efforts of ([@martedesco](https://github.com/martedesco)), ([@karpikpl](https://github.com/karpikpl)) and our wonderful contributors. A heartfelt thanks to all our contributors! ✨
229234

230235
I aim to provide support through [GitHub Issues](https://github.com/github-copilot-resources/copilot-metrics-viewer/issues). While I strive to stay responsive, I can't guarantee immediate responses. For critical issues, please include "CRITICAL" in the title for quicker attention. 🙏🏼

api/server.mjs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ const MemoryStore = MemoryStoreFactory(session);
1717
const limiter = RateLimit({
1818
windowMs: 15 * 60 * 1000, // 15 minutes
1919
max: 100, // max 100 requests per windowMs
20+
skip: (req) => {
21+
// Skip rate limiting for localhost
22+
return isLocalhost(req);
23+
}
2024
});
2125

2226
if (DOTENV_CONFIG_PATH) {
@@ -27,8 +31,13 @@ if (DOTENV_CONFIG_PATH) {
2731
}
2832

2933
const app = express();
34+
console.log('ENVIRONMENT: ', app.get('env'));
35+
36+
// Disable rate limiter and secure cookies for localhost
37+
const isLocalhost = (req) => {
38+
return req.hostname === 'localhost' || req.hostname === '127.0.0.1';
39+
};
3040

31-
// apply rate limiter to all requests
3241
app.use(limiter);
3342

3443
app.use(session({
@@ -38,7 +47,8 @@ app.use(session({
3847
store: new MemoryStore({
3948
checkPeriod: 86400000 // prune expired entries every 24h
4049
}),
41-
cookie: { secure: process.env.IS_PROD ? true : false, maxAge: 86400000 }
50+
// may need to use secure: false if using http during local development
51+
cookie: { secure: app.get('env') === 'production', maxAge: 86400000 }
4252
}));
4353

4454
// Middleware to add Authorization header
@@ -70,16 +80,24 @@ const mockResponses = (proxyServer, options) => {
7080
// Do not send to GitHub when mocked
7181
switch (req.path) {
7282
case "/orgs/octodemo/copilot/usage":
73-
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_response_sample.json'), 'utf8')));
83+
case "/orgs/octodemo/team/the-a-team/copilot/usage":
84+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_usage_response_sample.json'), 'utf8')));
85+
break;
86+
case "/orgs/octodemo/copilot/metrics":
87+
case "/orgs/octodemo/team/the-a-team/copilot/metrics":
88+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_metrics_response_sample.json'), 'utf8')));
7489
break;
7590
case "/orgs/octodemo/copilot/billing/seats":
76-
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_response_sample_seats.json'), 'utf8')));
91+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/organization_seats_response_sample.json'), 'utf8')));
7792
break;
7893
case "/enterprises/octodemo/copilot/usage":
79-
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_response_sample.json'), 'utf8')));
94+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_usage_response_sample.json'), 'utf8')));
95+
break;
96+
case "/enterprises/octodemo/copilot/metrics":
97+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_metrics_response_sample.json'), 'utf8')));
8098
break;
8199
case "/enterprises/octodemo/copilot/billing/seats":
82-
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_response_sample_seats.json'), 'utf8')));
100+
res.json(JSON.parse(readFileSync(path.join(__dirname, '../mock-data/enterprise_seats_response_sample.json'), 'utf8')));
83101
break;
84102
default:
85103
res.status(418).send('🫖Request Not Mocked');

images/Acceptance_rate_by_lines.png

119 KB
Loading

images/Acceptance_rate_bycount.png

177 KB
Loading

images/KeyMetrics.png

107 KB
Loading

images/Language_breakdown.png

152 KB
Loading

images/Language_breakdown_list.png

155 KB
Loading

images/MainMetrics.png

107 KB
Loading

images/Total Lines.png

157 KB
Loading

0 commit comments

Comments
 (0)