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:
parent
40c7c25db9
commit
63a354ab6f
@ -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);
|
{
|
||||||
|
name: 'labeled_counter',
|
||||||
|
help: 'with labels',
|
||||||
|
type: 'counter',
|
||||||
|
samples: [
|
||||||
|
{
|
||||||
|
labels: { foo: 'bar' },
|
||||||
|
value: 5,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
metricsTranslator.translateMetric({
|
await sendImpactMetrics([
|
||||||
name: 'labeled_counter',
|
{
|
||||||
help: 'with labels',
|
name: 'labeled_counter',
|
||||||
type: 'counter' as const,
|
help: 'with labels',
|
||||||
samples: [
|
type: 'counter',
|
||||||
{
|
samples: [
|
||||||
labels: { foo: 'bar' },
|
{
|
||||||
value: 5,
|
labels: { foo: 'bar' },
|
||||||
},
|
value: 10,
|
||||||
],
|
},
|
||||||
});
|
],
|
||||||
|
},
|
||||||
metricsTranslator.translateMetric({
|
]);
|
||||||
name: 'labeled_counter',
|
|
||||||
help: 'with labels',
|
|
||||||
type: 'counter' as const,
|
|
||||||
samples: [
|
|
||||||
{
|
|
||||||
labels: { foo: 'bar' },
|
|
||||||
value: 10,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await app.request
|
const response = await app.request
|
||||||
.get('/internal-backstage/impact/metrics')
|
.get('/internal-backstage/impact/metrics')
|
||||||
|
@ -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';
|
||||||
|
@ -56,6 +56,7 @@ process.nextTick(async () => {
|
|||||||
customMetrics: true,
|
customMetrics: true,
|
||||||
lifecycleMetrics: true,
|
lifecycleMetrics: true,
|
||||||
improvedJsonDiff: true,
|
improvedJsonDiff: true,
|
||||||
|
impactMetrics: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authentication: {
|
authentication: {
|
||||||
|
Loading…
Reference in New Issue
Block a user