From 2444bd7ccdbcdd4c33572721352f1f9d54d48346 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Wed, 18 Jun 2025 13:44:55 +0200 Subject: [PATCH] test: impact metrics collection e2e (#10162) --- .../metrics/impact/impact-metrics.e2e.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/lib/features/metrics/impact/impact-metrics.e2e.test.ts diff --git a/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts b/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts new file mode 100644 index 0000000000..dcd2f3218c --- /dev/null +++ b/src/lib/features/metrics/impact/impact-metrics.e2e.test.ts @@ -0,0 +1,69 @@ +import { + type IUnleashTest, + setupAppWithCustomConfig, +} from '../../../../test/e2e/helpers/test-helper.js'; +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'; + +let app: IUnleashTest; +let db: ITestDb; + +beforeAll(async () => { + db = await dbInit('impact_metrics', getLogger); + app = await setupAppWithCustomConfig(db.stores, { + experimental: { + flags: { + impactMetrics: true, + }, + }, + }); +}); + +afterAll(async () => { + await app.destroy(); + await db.destroy(); +}); + +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); + + 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, + }, + ], + }); + + const response = await app.request + .get('/internal-backstage/impact/metrics') + .expect('Content-Type', /text/) + .expect(200); + + const metricsText = response.text; + + expect(metricsText).toContain('# HELP labeled_counter with labels'); + expect(metricsText).toContain('# TYPE labeled_counter counter'); + expect(metricsText).toMatch(/labeled_counter{foo="bar"} 15/); +});