1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00

test: impact metrics e2e (#10178)

This commit is contained in:
Mateusz Kwasniewski 2025-06-19 12:34:22 +02:00 committed by GitHub
parent 40c7c25db9
commit 63a354ab6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 29 deletions

View File

@ -6,12 +6,26 @@ import dbInit, {
type ITestDb,
} from '../../../../test/e2e/helpers/database-init.js';
import getLogger from '../../../../test/fixtures/no-logger.js';
import { MetricsTranslator } from './metrics-translator.js';
import { impactRegister } from './impact-register.js';
import type { Metric } from './metrics-translator.js';
let app: IUnleashTest;
let db: ITestDb;
const sendImpactMetrics = async (impactMetrics: Metric[]) =>
app.request
.post('/api/client/metrics')
.send({
appName: 'impact-metrics-app',
instanceId: 'instance-id',
bucket: {
start: Date.now(),
stop: Date.now(),
toggles: {},
},
impactMetrics,
})
.expect(202);
beforeAll(async () => {
db = await dbInit('impact_metrics', getLogger);
app = await setupAppWithCustomConfig(db.stores, {
@ -29,32 +43,33 @@ afterAll(async () => {
});
test('should store impact metrics in memory and be able to retrieve them', async () => {
// TODO: replace with POST metrics when it's ready
const metricsTranslator = new MetricsTranslator(impactRegister);
await sendImpactMetrics([
{
name: 'labeled_counter',
help: 'with labels',
type: 'counter',
samples: [
{
labels: { foo: 'bar' },
value: 5,
},
],
},
]);
metricsTranslator.translateMetric({
name: 'labeled_counter',
help: 'with labels',
type: 'counter' as const,
samples: [
{
labels: { foo: 'bar' },
value: 5,
},
],
});
metricsTranslator.translateMetric({
name: 'labeled_counter',
help: 'with labels',
type: 'counter' as const,
samples: [
{
labels: { foo: 'bar' },
value: 10,
},
],
});
await sendImpactMetrics([
{
name: 'labeled_counter',
help: 'with labels',
type: 'counter',
samples: [
{
labels: { foo: 'bar' },
value: 10,
},
],
},
]);
const response = await app.request
.get('/internal-backstage/impact/metrics')

View File

@ -1,11 +1,11 @@
import { Counter, Gauge, type Registry } from 'prom-client';
interface MetricSample {
export interface MetricSample {
labels?: Record<string, string | number>;
value: number;
}
interface Metric {
export interface Metric {
name: string;
help: string;
type: 'counter' | 'gauge';

View File

@ -56,6 +56,7 @@ process.nextTick(async () => {
customMetrics: true,
lifecycleMetrics: true,
improvedJsonDiff: true,
impactMetrics: true,
},
},
authentication: {