mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[clsi] add metric for disk usage (#24303)
GitOrigin-RevId: e21b867a2fdaf54e9ec5b29b0f80b29349eb901c
This commit is contained in:
@@ -13,6 +13,7 @@ const CompileManager = require('./CompileManager')
|
|||||||
const async = require('async')
|
const async = require('async')
|
||||||
const logger = require('@overleaf/logger')
|
const logger = require('@overleaf/logger')
|
||||||
const oneDay = 24 * 60 * 60 * 1000
|
const oneDay = 24 * 60 * 60 * 1000
|
||||||
|
const Metrics = require('@overleaf/metrics')
|
||||||
const Settings = require('@overleaf/settings')
|
const Settings = require('@overleaf/settings')
|
||||||
const diskusage = require('diskusage')
|
const diskusage = require('diskusage')
|
||||||
const { callbackify } = require('node:util')
|
const { callbackify } = require('node:util')
|
||||||
@@ -31,7 +32,11 @@ async function refreshExpiryTimeout() {
|
|||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
try {
|
try {
|
||||||
const stats = await diskusage.check(path)
|
const stats = await diskusage.check(path)
|
||||||
const lowDisk = stats.available / stats.total < 0.1
|
const diskAvailablePercent = (stats.available / stats.total) * 100
|
||||||
|
Metrics.gauge('disk_available_percent', diskAvailablePercent, 1, {
|
||||||
|
path,
|
||||||
|
})
|
||||||
|
const lowDisk = diskAvailablePercent < 10
|
||||||
|
|
||||||
const lowerExpiry = ProjectPersistenceManager.EXPIRY_TIMEOUT * 0.9
|
const lowerExpiry = ProjectPersistenceManager.EXPIRY_TIMEOUT * 0.9
|
||||||
if (lowDisk && Settings.project_cache_length_ms / 2 < lowerExpiry) {
|
if (lowDisk && Settings.project_cache_length_ms / 2 < lowerExpiry) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ describe('ProjectPersistenceManager', function () {
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
this.ProjectPersistenceManager = SandboxedModule.require(modulePath, {
|
this.ProjectPersistenceManager = SandboxedModule.require(modulePath, {
|
||||||
requires: {
|
requires: {
|
||||||
|
'@overleaf/metrics': (this.Metrics = { gauge: sinon.stub() }),
|
||||||
'./UrlCache': (this.UrlCache = {}),
|
'./UrlCache': (this.UrlCache = {}),
|
||||||
'./CompileManager': (this.CompileManager = {}),
|
'./CompileManager': (this.CompileManager = {}),
|
||||||
diskusage: (this.diskusage = { check: sinon.stub() }),
|
diskusage: (this.diskusage = { check: sinon.stub() }),
|
||||||
@@ -49,6 +50,10 @@ describe('ProjectPersistenceManager', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
||||||
|
this.Metrics.gauge.should.have.been.calledWith(
|
||||||
|
'disk_available_percent',
|
||||||
|
40
|
||||||
|
)
|
||||||
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(
|
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(
|
||||||
this.settings.project_cache_length_ms
|
this.settings.project_cache_length_ms
|
||||||
)
|
)
|
||||||
@@ -63,6 +68,10 @@ describe('ProjectPersistenceManager', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
||||||
|
this.Metrics.gauge.should.have.been.calledWith(
|
||||||
|
'disk_available_percent',
|
||||||
|
5
|
||||||
|
)
|
||||||
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(900)
|
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(900)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
@@ -75,6 +84,10 @@ describe('ProjectPersistenceManager', function () {
|
|||||||
})
|
})
|
||||||
this.ProjectPersistenceManager.EXPIRY_TIMEOUT = 500
|
this.ProjectPersistenceManager.EXPIRY_TIMEOUT = 500
|
||||||
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
this.ProjectPersistenceManager.refreshExpiryTimeout(() => {
|
||||||
|
this.Metrics.gauge.should.have.been.calledWith(
|
||||||
|
'disk_available_percent',
|
||||||
|
5
|
||||||
|
)
|
||||||
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(500)
|
this.ProjectPersistenceManager.EXPIRY_TIMEOUT.should.equal(500)
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user