Skip to content

Commit 3f586dd

Browse files
authored
make repo garbage collection async (#211)
* add gc queue logic * fix missing switch cases for gc status * style org create form better with new staging domain * change repo rm logic to be async * simplify repo for inactive org query * add grace period for garbage collecting repos * make prom scrape interval 500ms
1 parent 88fe84e commit 3f586dd

File tree

14 files changed

+316
-150
lines changed

14 files changed

+316
-150
lines changed

demo-site-config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"$schema": "./schemas/v2/index.json",
33
"settings": {
4-
"autoDeleteStaleRepos": true,
54
"reindexInterval": 86400000, // 24 hours
65
"resyncInterval": 86400000 // 24 hours
76
},

grafana.alloy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ prometheus.scrape "local_app" {
99
]
1010

1111
metrics_path = "/metrics"
12-
scrape_interval = "10s"
12+
scrape_timeout = "500ms"
13+
scrape_interval = "500ms"
1314

1415
job_name = sys.env("GRAFANA_ENVIRONMENT")
1516

packages/backend/src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { Settings } from "./types.js";
55
*/
66
export const DEFAULT_SETTINGS: Settings = {
77
maxFileSize: 2 * 1024 * 1024, // 2MB in bytes
8-
autoDeleteStaleRepos: true,
98
reindexIntervalMs: 1000 * 60 * 60, // 1 hour
109
resyncConnectionPollingIntervalMs: 1000,
1110
reindexRepoPollingIntervalMs: 1000,
1211
indexConcurrencyMultiple: 3,
1312
configSyncConcurrencyMultiple: 3,
13+
gcConcurrencyMultiple: 1,
14+
gcGracePeriodMs: 10 * 1000, // 10 seconds
1415
}

packages/backend/src/promClient.ts

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ export class PromClient {
66
private app: express.Application;
77
public activeRepoIndexingJobs: Gauge<string>;
88
public repoIndexingDuration: Histogram<string>;
9-
public repoIndexingErrors: Counter<string>;
10-
public repoIndexingFails: Counter<string>;
11-
public repoIndexingSuccesses: Counter<string>;
9+
public repoIndexingErrorTotal: Counter<string>;
10+
public repoIndexingFailTotal: Counter<string>;
11+
public repoIndexingSuccessTotal: Counter<string>;
12+
13+
public activeRepoGarbageCollectionJobs: Gauge<string>;
14+
public repoGarbageCollectionDuration: Histogram<string>;
15+
public repoGarbageCollectionErrorTotal: Counter<string>;
16+
public repoGarbageCollectionFailTotal: Counter<string>;
17+
public repoGarbageCollectionSuccessTotal: Counter<string>;
18+
1219
public readonly PORT = 3060;
1320

1421
constructor() {
@@ -28,26 +35,61 @@ export class PromClient {
2835
});
2936
this.registry.registerMetric(this.repoIndexingDuration);
3037

31-
this.repoIndexingErrors = new Counter({
38+
this.repoIndexingErrorTotal = new Counter({
3239
name: 'repo_indexing_errors',
3340
help: 'The number of repo indexing errors',
3441
labelNames: ['repo'],
3542
});
36-
this.registry.registerMetric(this.repoIndexingErrors);
43+
this.registry.registerMetric(this.repoIndexingErrorTotal);
3744

38-
this.repoIndexingFails = new Counter({
45+
this.repoIndexingFailTotal = new Counter({
3946
name: 'repo_indexing_fails',
4047
help: 'The number of repo indexing fails',
4148
labelNames: ['repo'],
4249
});
43-
this.registry.registerMetric(this.repoIndexingFails);
50+
this.registry.registerMetric(this.repoIndexingFailTotal);
4451

45-
this.repoIndexingSuccesses = new Counter({
52+
this.repoIndexingSuccessTotal = new Counter({
4653
name: 'repo_indexing_successes',
4754
help: 'The number of repo indexing successes',
4855
labelNames: ['repo'],
4956
});
50-
this.registry.registerMetric(this.repoIndexingSuccesses);
57+
this.registry.registerMetric(this.repoIndexingSuccessTotal);
58+
59+
this.activeRepoGarbageCollectionJobs = new Gauge({
60+
name: 'active_repo_garbage_collection_jobs',
61+
help: 'The number of repo garbage collection jobs in progress',
62+
labelNames: ['repo'],
63+
});
64+
this.registry.registerMetric(this.activeRepoGarbageCollectionJobs);
65+
66+
this.repoGarbageCollectionDuration = new Histogram({
67+
name: 'repo_garbage_collection_duration',
68+
help: 'The duration of repo garbage collection jobs',
69+
labelNames: ['repo'],
70+
});
71+
this.registry.registerMetric(this.repoGarbageCollectionDuration);
72+
73+
this.repoGarbageCollectionErrorTotal = new Counter({
74+
name: 'repo_garbage_collection_errors',
75+
help: 'The number of repo garbage collection errors',
76+
labelNames: ['repo'],
77+
});
78+
this.registry.registerMetric(this.repoGarbageCollectionErrorTotal);
79+
80+
this.repoGarbageCollectionFailTotal = new Counter({
81+
name: 'repo_garbage_collection_fails',
82+
help: 'The number of repo garbage collection fails',
83+
labelNames: ['repo'],
84+
});
85+
this.registry.registerMetric(this.repoGarbageCollectionFailTotal);
86+
87+
this.repoGarbageCollectionSuccessTotal = new Counter({
88+
name: 'repo_garbage_collection_successes',
89+
help: 'The number of repo garbage collection successes',
90+
labelNames: ['repo'],
91+
});
92+
this.registry.registerMetric(this.repoGarbageCollectionSuccessTotal);
5193

5294
client.collectDefaultMetrics({
5395
register: this.registry,

0 commit comments

Comments
 (0)