diff --git a/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts b/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts index dcd2f3218c..fcea2ff321 100644 --- a/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts +++ b/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts @@ -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') diff --git a/src/lib/features/metrics/impact/metrics-translator.ts b/src/lib/features/metrics/impact/metrics-translator.ts index 0f43128606..f27999d837 100644 --- a/src/lib/features/metrics/impact/metrics-translator.ts +++ b/src/lib/features/metrics/impact/metrics-translator.ts @@ -1,11 +1,11 @@ import { Counter, Gauge, type Registry } from 'prom-client'; -interface MetricSample { +export interface MetricSample { labels?: Record; value: number; } -interface Metric { +export interface Metric { name: string; help: string; type: 'counter' | 'gauge'; diff --git a/src/server-dev.ts b/src/server-dev.ts index bfc14360ca..b49244861d 100644 --- a/src/server-dev.ts +++ b/src/server-dev.ts @@ -56,6 +56,7 @@ process.nextTick(async () => { customMetrics: true, lifecycleMetrics: true, improvedJsonDiff: true, + impactMetrics: true, }, }, authentication: {