fix: deduplicate filesystem mounts in monitoring
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { DEFAULT_ALERT_THRESHOLDS, InfrastructureAlertSettingsService } from './infrastructure-alert-settings.service';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
import { FILESYSTEM_INODE_USAGE_PERCENT, FILESYSTEM_USAGE_PERCENT } from './filesystem-metrics';
|
||||
|
||||
describe('InfrastructureAlertSettingsService', () => {
|
||||
const service = new InfrastructureAlertSettingsService({} as never, { get: () => undefined } as never);
|
||||
@@ -14,8 +17,25 @@ describe('InfrastructureAlertSettingsService', () => {
|
||||
expect(rules).toContain('sum(increase(cmpp_api_http_requests_total');
|
||||
expect(rules).not.toContain('mountpoint="/"');
|
||||
expect(rules).toContain('device=~"/dev/.+"');
|
||||
expect(rules).toContain('{{ $labels.mountpoint }}');
|
||||
expect(rules).not.toContain('{{ $labels.mountpoint }}');
|
||||
expect(rules).toContain('{{ $labels.device }}');
|
||||
expect(rules).toContain('{{ $labels.fstype }}');
|
||||
expect(rules).toContain(FILESYSTEM_USAGE_PERCENT);
|
||||
});
|
||||
|
||||
it('keeps static capacity and inode rules aligned with filesystem-level deduplication', () => {
|
||||
for (const file of ['cmpp-alerts.yml', 'cmpp-managed-alerts.yml']) {
|
||||
const content = readFileSync(resolve(__dirname, '../../../tools/monitoring', file), 'utf8');
|
||||
const blocks = [...content.matchAll(/ - alert: (HostRoot(?:Disk|Inode)Usage(?:Warning|Critical))\r?\n([\s\S]*?)(?=\r?\n - alert:|$)/g)];
|
||||
expect(blocks).toHaveLength(file === 'cmpp-alerts.yml' ? 4 : 2);
|
||||
for (const [, name, body] of blocks) {
|
||||
const expression = body.match(/^\s+expr: (.+)$/m)![1].trim();
|
||||
const base = name.includes('Inode') ? FILESYSTEM_INODE_USAGE_PERCENT : FILESYSTEM_USAGE_PERCENT;
|
||||
expect(expression).toBe(name.endsWith('Warning') ? `(${base} > 80) and (${base} <= 90)` : `${base} > 90`);
|
||||
expect(body).not.toContain('$labels.mountpoint');
|
||||
expect(body).toContain('$labels.device');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('rejects unknown keys and warning thresholds that are not below critical', () => {
|
||||
|
||||
Reference in New Issue
Block a user