Skip to content

Commit 9d3fe0a

Browse files
authored
fix: improve monitoring (#690)
1 parent a33d97d commit 9d3fe0a

File tree

4 files changed

+263
-241
lines changed

4 files changed

+263
-241
lines changed

src/internal/database/pool.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { logger, logSchema } from '@internal/monitoring'
55
import { getSslSettings } from '@internal/database/util'
66
import { wait } from '@internal/concurrency'
77
import { JWTPayload } from 'jose'
8+
import { DbActivePool } from '@internal/monitoring/metrics'
89

910
const {
11+
region,
1012
isMultitenant,
1113
databaseSSLRootCert,
1214
databaseMaxConnections,
@@ -75,6 +77,25 @@ const tenantPools = new TTLCache<string, PoolStrategy>({
7577
* It creates a new pool for each tenant and reuses existing pools.
7678
*/
7779
export class PoolManager {
80+
monitor(signal: AbortSignal) {
81+
const monitorInterval = setInterval(() => {
82+
DbActivePool.set(
83+
{
84+
region,
85+
},
86+
tenantPools.size
87+
)
88+
}, 2000)
89+
90+
signal.addEventListener(
91+
'abort',
92+
() => {
93+
clearInterval(monitorInterval)
94+
},
95+
{ once: true }
96+
)
97+
}
98+
7899
rebalanceAll(data: { clusterSize: number }) {
79100
for (const pool of tenantPools.values()) {
80101
pool.rebalance({
@@ -122,7 +143,6 @@ export class PoolManager {
122143
promises.push(pool.destroy())
123144
tenantPools.delete(connectionString)
124145
}
125-
126146
return Promise.allSettled(promises)
127147
}
128148

src/internal/monitoring/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const S3UploadPart = new client.Histogram({
6060
export const DbActivePool = new client.Gauge({
6161
name: 'storage_api_db_pool',
6262
help: 'Number of database pools created',
63-
labelNames: ['region', 'is_external'],
63+
labelNames: ['region'],
6464
})
6565

6666
export const DbActiveConnection = new client.Gauge({

0 commit comments

Comments
 (0)