1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-04 11:17:02 +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, type ITestDb,
} from '../../../../test/e2e/helpers/database-init.js'; } from '../../../../test/e2e/helpers/database-init.js';
import getLogger from '../../../../test/fixtures/no-logger.js'; import getLogger from '../../../../test/fixtures/no-logger.js';
import { MetricsTranslator } from './metrics-translator.js'; import type { Metric } from './metrics-translator.js';
import { impactRegister } from './impact-register.js';
let app: IUnleashTest; let app: IUnleashTest;
let db: ITestDb; 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 () => { beforeAll(async () => {
db = await dbInit('impact_metrics', getLogger); db = await dbInit('impact_metrics', getLogger);
app = await setupAppWithCustomConfig(db.stores, { 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 () => { test('should store impact metrics in memory and be able to retrieve them', async () => {
// TODO: replace with POST metrics when it's ready await sendImpactMetrics([
const metricsTranslator = new MetricsTranslator(impactRegister); {
metricsTranslator.translateMetric({
name: 'labeled_counter', name: 'labeled_counter',
help: 'with labels', help: 'with labels',
type: 'counter' as const, type: 'counter',
samples: [ samples: [
{ {
labels: { foo: 'bar' }, labels: { foo: 'bar' },
value: 5, value: 5,
}, },
], ],
}); },
]);
metricsTranslator.translateMetric({ await sendImpactMetrics([
{
name: 'labeled_counter', name: 'labeled_counter',
help: 'with labels', help: 'with labels',
type: 'counter' as const, type: 'counter',
samples: [ samples: [
{ {
labels: { foo: 'bar' }, labels: { foo: 'bar' },
value: 10, value: 10,
}, },
], ],
}); },
]);
const response = await app.request const response = await app.request
.get('/internal-backstage/impact/metrics') .get('/internal-backstage/impact/metrics')

View File

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

View File

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