fix(core): Fix telemetry for concurrency control (#9845)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Iván Ovejero
2024-06-27 10:54:40 +02:00
committed by GitHub
parent 6cb3072a5d
commit e25682ddad
4 changed files with 143 additions and 23 deletions

View File

@@ -1,6 +1,10 @@
import { mock } from 'jest-mock-extended';
import config from '@/config';
import { ConcurrencyControlService } from '@/concurrency/concurrency-control.service';
import {
CLOUD_TEMP_PRODUCTION_LIMIT,
CLOUD_TEMP_REPORTABLE_THRESHOLDS,
ConcurrencyControlService,
} from '@/concurrency/concurrency-control.service';
import type { Logger } from '@/Logger';
import { InvalidConcurrencyLimitError } from '@/errors/invalid-concurrency-limit.error';
import { ConcurrencyQueue } from '../concurrency-queue';
@@ -366,4 +370,91 @@ describe('ConcurrencyControlService', () => {
});
});
});
// ----------------------------------
// telemetry
// ----------------------------------
describe('telemetry', () => {
describe('on cloud', () => {
test.each(CLOUD_TEMP_REPORTABLE_THRESHOLDS)(
'for capacity %d, should report temp cloud threshold if reached',
(threshold) => {
/**
* Arrange
*/
config.set('executions.concurrency.productionLimit', CLOUD_TEMP_PRODUCTION_LIMIT);
config.set('deployment.type', 'cloud');
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);
/**
* Act
*/
// @ts-expect-error Private property
service.productionQueue.emit('concurrency-check', {
capacity: CLOUD_TEMP_PRODUCTION_LIMIT - threshold,
});
/**
* Assert
*/
expect(telemetry.track).toHaveBeenCalledWith('User hit concurrency limit', { threshold });
},
);
test.each(CLOUD_TEMP_REPORTABLE_THRESHOLDS.map((t) => t - 1))(
'for capacity %d, should not report temp cloud threshold if not reached',
(threshold) => {
/**
* Arrange
*/
config.set('executions.concurrency.productionLimit', CLOUD_TEMP_PRODUCTION_LIMIT);
config.set('deployment.type', 'cloud');
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);
/**
* Act
*/
// @ts-expect-error Private property
service.productionQueue.emit('concurrency-check', {
capacity: CLOUD_TEMP_PRODUCTION_LIMIT - threshold,
});
/**
* Assert
*/
expect(telemetry.track).not.toHaveBeenCalledWith('User hit concurrency limit', {
threshold,
});
},
);
test.each(CLOUD_TEMP_REPORTABLE_THRESHOLDS.map((t) => t + 1))(
'for capacity %d, should not report temp cloud threshold if exceeded',
(threshold) => {
/**
* Arrange
*/
config.set('executions.concurrency.productionLimit', CLOUD_TEMP_PRODUCTION_LIMIT);
config.set('deployment.type', 'cloud');
const service = new ConcurrencyControlService(logger, executionRepository, telemetry);
/**
* Act
*/
// @ts-expect-error Private property
service.productionQueue.emit('concurrency-check', {
capacity: CLOUD_TEMP_PRODUCTION_LIMIT - threshold,
});
/**
* Assert
*/
expect(telemetry.track).not.toHaveBeenCalledWith('User hit concurrency limit', {
threshold,
});
},
);
});
});
});