mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +01:00
fix: lifecycle metrics on metrics insert (#7322)
This commit is contained in:
parent
d69d826586
commit
cedf19d2ec
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
CLIENT_METRICS,
|
CLIENT_METRICS_ADDED,
|
||||||
FEATURE_ARCHIVED,
|
FEATURE_ARCHIVED,
|
||||||
FEATURE_COMPLETED,
|
FEATURE_COMPLETED,
|
||||||
FEATURE_CREATED,
|
FEATURE_CREATED,
|
||||||
@ -33,7 +33,7 @@ test('can insert and read lifecycle stages', async () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
function emitMetricsEvent(environment: string) {
|
function emitMetricsEvent(environment: string) {
|
||||||
eventBus.emit(CLIENT_METRICS, [
|
eventBus.emit(CLIENT_METRICS_ADDED, [
|
||||||
{
|
{
|
||||||
featureName,
|
featureName,
|
||||||
environment,
|
environment,
|
||||||
@ -120,7 +120,7 @@ test('ignores lifecycle state updates when flag disabled', async () => {
|
|||||||
|
|
||||||
await eventStore.emit(FEATURE_CREATED, { featureName });
|
await eventStore.emit(FEATURE_CREATED, { featureName });
|
||||||
await eventStore.emit(FEATURE_COMPLETED, { featureName });
|
await eventStore.emit(FEATURE_COMPLETED, { featureName });
|
||||||
await eventBus.emit(CLIENT_METRICS, {
|
await eventBus.emit(CLIENT_METRICS_ADDED, {
|
||||||
bucket: { toggles: { [featureName]: 'irrelevant' } },
|
bucket: { toggles: { [featureName]: 'irrelevant' } },
|
||||||
environment: 'development',
|
environment: 'development',
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
CLIENT_METRICS,
|
CLIENT_METRICS_ADDED,
|
||||||
FEATURE_ARCHIVED,
|
FEATURE_ARCHIVED,
|
||||||
FEATURE_CREATED,
|
FEATURE_CREATED,
|
||||||
FEATURE_REVIVED,
|
FEATURE_REVIVED,
|
||||||
@ -9,8 +9,8 @@ import {
|
|||||||
type IEnvironmentStore,
|
type IEnvironmentStore,
|
||||||
type IEventStore,
|
type IEventStore,
|
||||||
type IFeatureEnvironmentStore,
|
type IFeatureEnvironmentStore,
|
||||||
type IProjectLifecycleStageDuration,
|
|
||||||
type IFlagResolver,
|
type IFlagResolver,
|
||||||
|
type IProjectLifecycleStageDuration,
|
||||||
type IUnleashConfig,
|
type IUnleashConfig,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
import type {
|
import type {
|
||||||
@ -95,7 +95,7 @@ export class FeatureLifecycleService extends EventEmitter {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
this.eventBus.on(
|
this.eventBus.on(
|
||||||
CLIENT_METRICS,
|
CLIENT_METRICS_ADDED,
|
||||||
async (events: IClientMetricsEnv[]) => {
|
async (events: IClientMetricsEnv[]) => {
|
||||||
if (events.length > 0) {
|
if (events.length > 0) {
|
||||||
const groupedByEnvironment = groupBy(events, 'environment');
|
const groupedByEnvironment = groupBy(events, 'environment');
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
} from '../../../test/e2e/helpers/test-helper';
|
} from '../../../test/e2e/helpers/test-helper';
|
||||||
import getLogger from '../../../test/fixtures/no-logger';
|
import getLogger from '../../../test/fixtures/no-logger';
|
||||||
import {
|
import {
|
||||||
CLIENT_METRICS,
|
CLIENT_METRICS_ADDED,
|
||||||
FEATURE_ARCHIVED,
|
FEATURE_ARCHIVED,
|
||||||
FEATURE_CREATED,
|
FEATURE_CREATED,
|
||||||
FEATURE_REVIVED,
|
FEATURE_REVIVED,
|
||||||
@ -121,7 +121,7 @@ test('should return lifecycle stages', async () => {
|
|||||||
eventStore.emit(FEATURE_CREATED, { featureName: 'my_feature_a' });
|
eventStore.emit(FEATURE_CREATED, { featureName: 'my_feature_a' });
|
||||||
await reachedStage('my_feature_a', 'initial');
|
await reachedStage('my_feature_a', 'initial');
|
||||||
await expectFeatureStage('my_feature_a', 'initial');
|
await expectFeatureStage('my_feature_a', 'initial');
|
||||||
eventBus.emit(CLIENT_METRICS, [
|
eventBus.emit(CLIENT_METRICS_ADDED, [
|
||||||
{
|
{
|
||||||
featureName: 'my_feature_a',
|
featureName: 'my_feature_a',
|
||||||
environment: 'default',
|
environment: 'default',
|
||||||
@ -133,7 +133,7 @@ test('should return lifecycle stages', async () => {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// missing feature
|
// missing feature
|
||||||
eventBus.emit(CLIENT_METRICS, [
|
eventBus.emit(CLIENT_METRICS_ADDED, [
|
||||||
{
|
{
|
||||||
environment: 'default',
|
environment: 'default',
|
||||||
yes: 0,
|
yes: 0,
|
||||||
@ -141,7 +141,7 @@ test('should return lifecycle stages', async () => {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
// non existent env
|
// non existent env
|
||||||
eventBus.emit(CLIENT_METRICS, [
|
eventBus.emit(CLIENT_METRICS_ADDED, [
|
||||||
{
|
{
|
||||||
featureName: 'my_feature_a',
|
featureName: 'my_feature_a',
|
||||||
environment: 'non-existent',
|
environment: 'non-existent',
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import type { Logger } from '../../../logger';
|
import type { Logger } from '../../../logger';
|
||||||
import type { IFlagResolver, IUnleashConfig } from '../../../types';
|
import {
|
||||||
|
CLIENT_METRICS_ADDED,
|
||||||
|
type IFlagResolver,
|
||||||
|
type IUnleashConfig,
|
||||||
|
} from '../../../types';
|
||||||
import type { IUnleashStores } from '../../../types';
|
import type { IUnleashStores } from '../../../types';
|
||||||
import type { ToggleMetricsSummary } from '../../../types/models/metrics';
|
import type { ToggleMetricsSummary } from '../../../types/models/metrics';
|
||||||
import type {
|
import type {
|
||||||
@ -182,6 +186,7 @@ export default class ClientMetricsServiceV2 {
|
|||||||
const copy = [...this.unsavedMetrics];
|
const copy = [...this.unsavedMetrics];
|
||||||
this.unsavedMetrics = [];
|
this.unsavedMetrics = [];
|
||||||
await this.clientMetricsStoreV2.batchInsertMetrics(copy);
|
await this.clientMetricsStoreV2.batchInsertMetrics(copy);
|
||||||
|
this.config.eventBus.emit(CLIENT_METRICS_ADDED, copy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ export const PROJECT_ENVIRONMENT_REMOVED =
|
|||||||
export const DEFAULT_STRATEGY_UPDATED = 'default-strategy-updated' as const;
|
export const DEFAULT_STRATEGY_UPDATED = 'default-strategy-updated' as const;
|
||||||
|
|
||||||
export const CLIENT_METRICS = 'client-metrics' as const;
|
export const CLIENT_METRICS = 'client-metrics' as const;
|
||||||
|
export const CLIENT_METRICS_ADDED = 'client-metrics-added' as const;
|
||||||
export const CLIENT_REGISTER = 'client-register' as const;
|
export const CLIENT_REGISTER = 'client-register' as const;
|
||||||
|
|
||||||
export const PAT_CREATED = 'pat-created' as const;
|
export const PAT_CREATED = 'pat-created' as const;
|
||||||
|
Loading…
Reference in New Issue
Block a user