You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: github-metrics/README.md
+109-5Lines changed: 109 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
This directory contains tooling to enable us to track various GitHub project metrics programmatically.
4
4
5
-
Currently, it contains a PoC for a simple pipeline to pull metrics from GitHub into MongoDB Atlas.
5
+
This tool runs as a Kubernetes CronJob on Kanopy, automatically collecting metrics from GitHub approximately every 13-14 days and storing them in MongoDB Atlas.
6
6
7
-
Planned future work:
7
+
Planned future work:
8
8
9
9
- Add logic to work with pulled maintenance metrics once available in the test repo
10
10
- Set up Atlas Charts to visualize the data
@@ -14,7 +14,7 @@ Planned future work:
14
14
### Get metrics from GitHub
15
15
16
16
This is a simple PoC that uses [octokit](https://github.com/octokit/octokit.js) to get the following data out of GitHub
17
-
for a given repository over a trailing 14day period:
17
+
for a given repository over a trailing 14-day period:
18
18
19
19
- Views
20
20
- Unique Views
@@ -24,7 +24,7 @@ for a given repository over a trailing 14 day period:
24
24
- Top 10 referral sources
25
25
- Top 10 paths/destinations in the repo
26
26
27
-
The intent is to also get the following maintenance-related stats for a given repository over a trailing 14day period:
27
+
The intent is to also get the following maintenance-related stats for a given repository over a trailing 14-day period:
28
28
29
29
- Code frequency
30
30
- Commit count
@@ -119,7 +119,7 @@ For this project, as a MongoDB org member, you must also auth your PAT with SSO.
119
119
npm install
120
120
```
121
121
122
-
3.**Run the utility**
122
+
3.**Manually run the utility**
123
123
124
124
From the root of the directory, run the following command to run the utility:
125
125
@@ -132,3 +132,107 @@ For this project, as a MongoDB org member, you must also auth your PAT with SSO.
132
132
```
133
133
A document was inserted into mongodb_docs-notebooks with the _id: 678197a0ffe1539ff213bd86
134
134
```
135
+
136
+
## Automated Deployment (Kanopy CronJob)
137
+
138
+
This tool is deployed as a Kubernetes CronJob on Kanopy that runs automatically approximately every 13-14 days.
139
+
140
+
### Deployment Architecture
141
+
142
+
The deployment consists of three main components:
143
+
144
+
1.**Dockerfile**: Containerizes the Node.js application
145
+
2.**cronjobs.yml**: Helm values file that configures the CronJob schedule and resources
146
+
3.**.drone.yml**: CI/CD pipeline that builds, publishes, and deploys the application
147
+
148
+
### CronJob Schedule
149
+
150
+
The cronjob is **scheduled to run weekly on Mondays at 8:00 AM UTC** (`0 8 * * 1`), but the application includes smart logic to prevent running too frequently:
151
+
152
+
- The cronjob triggers every Monday
153
+
- The application checks if 13 days have passed since the last successful run
154
+
- If less than 13 days have passed, the job exits early without collecting metrics
155
+
- If 13 days or more have passed, it collects metrics and updates the timestamp
156
+
157
+
The last run timestamp is stored in a persistent volume (`/data/last-run.json`) that survives between cronjob executions.
158
+
159
+
#### Environment Variables
160
+
161
+
The following environment variables can be configured:
162
+
163
+
-**`ATLAS_CONNECTION_STRING`** (required): MongoDB Atlas connection string for storing metrics
164
+
-**`GITHUB_TOKEN`** (required): GitHub Personal Access Token with `repo` permissions
165
+
-**`STATE_FILE_PATH`** (optional): Path to the state file for tracking last run timestamp. Default: `/data/last-run.json`
166
+
-**`MIN_DAYS_BETWEEN_RUNS`** (optional): Minimum number of days between metric collection runs. Default: `13`
167
+
168
+
The required secrets (`ATLAS_CONNECTION_STRING` and `GITHUB_TOKEN`) are configured in `cronjobs.yml` as Kubernetes secrets.
169
+
170
+
### Deployment Process
171
+
172
+
The deployment is fully automated via Drone CI/CD with the following steps:
173
+
174
+
1.**Check Changes**: Verifies if files in `github-metrics/` directory changed
175
+
2.**Test**: Validates dependencies with `npm ci`
176
+
3.**Build**: Builds Docker image using Kaniko and publishes to ECR
177
+
4.**Deploy**: Deploys to production Kanopy cluster using Helm
178
+
5.**Notify**: Sends Slack notification on success or failure
179
+
180
+
The pipeline only runs on pushes to the `main` branch and skips if no github-metrics files changed.
181
+
182
+
### Manual Deployment
183
+
184
+
To manually trigger a deployment:
185
+
186
+
1. Push changes to the `main` branch
187
+
2. Drone will automatically run the test, build, and deploy pipelines
188
+
189
+
### Manually Triggering the CronJob
190
+
191
+
To manually run the cronjob outside of its schedule:
0 commit comments