1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

fix: fix variant metrics (#3947)

This commit is contained in:
Jaanus Sellin 2023-06-09 15:48:32 +03:00 committed by GitHub
parent dbb95ceed4
commit ea21c753bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -108,3 +108,54 @@ test('collapseHourlyMetrics', () => {
}, },
]); ]);
}); });
test('collapseHourlyMetrics variants', () => {
const timestamp = startOfHour(new Date());
const metricsWithoutVariant: IClientMetricsEnv = {
featureName: 'a',
appName: 'x',
environment: 'x',
timestamp: addMinutes(timestamp, 1),
yes: 1,
no: 11,
};
const metricsWithVariant1: IClientMetricsEnv = {
featureName: 'a',
appName: 'x',
environment: 'x',
timestamp: addMinutes(timestamp, 2),
yes: 2,
no: 12,
variants: { disabled: 3, red: 2 },
};
const metricsWithVariant2: IClientMetricsEnv = {
featureName: 'a',
appName: 'x',
environment: 'x',
timestamp: addMinutes(timestamp, 2),
yes: 2,
no: 12,
variants: { disabled: 1, red: 3 },
};
expect(
collapseHourlyMetrics([
metricsWithoutVariant,
metricsWithVariant1,
metricsWithVariant2,
]),
).toEqual([
{
featureName: 'a',
appName: 'x',
environment: 'x',
timestamp,
yes: 5,
no: 35,
variants: { disabled: 4, red: 5 },
},
]);
});

View File

@ -51,7 +51,7 @@ export const collapseHourlyMetrics = (
if (metric.variants) { if (metric.variants) {
grouped[key].variants = mergeRecords( grouped[key].variants = mergeRecords(
metric.variants, metric.variants,
grouped[key].variants, grouped[key].variants ?? {},
); );
} }
} }