From 5be0b37cb1978456c594a731a47762d3a2fc036a Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Mon, 2 Jun 2025 12:40:10 +0200 Subject: [PATCH] fix: add event listeners for release plan updates in metrics (#10070) Milestone changes should be visible in metrics, in the same way as strategy changes are. --- src/lib/metrics.ts | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/lib/metrics.ts b/src/lib/metrics.ts index 1cd49ae53a..42567c668d 100644 --- a/src/lib/metrics.ts +++ b/src/lib/metrics.ts @@ -23,6 +23,9 @@ import { PROJECT_ARCHIVED, PROJECT_REVIVED, PROJECT_DELETED, + RELEASE_PLAN_ADDED, + RELEASE_PLAN_REMOVED, + RELEASE_PLAN_MILESTONE_STARTED, } from './events/index.js'; import type { IUnleashConfig } from './types/option.js'; import type { IUnleashStores } from './types/stores.js'; @@ -1005,6 +1008,58 @@ export function registerPrometheusMetrics( action: 'revived', }); }); + + eventStore.on( + RELEASE_PLAN_ADDED, + async ({ featureName, project, environment }) => { + const environmentType = await resolveEnvironmentType( + environment, + cachedEnvironments, + ); + featureFlagUpdateTotal.increment({ + toggle: featureName, + project, + environment, + environmentType, + action: 'updated', + }); + }, + ); + + eventStore.on( + RELEASE_PLAN_REMOVED, + async ({ featureName, project, environment }) => { + const environmentType = await resolveEnvironmentType( + environment, + cachedEnvironments, + ); + featureFlagUpdateTotal.increment({ + toggle: featureName, + project, + environment, + environmentType, + action: 'updated', + }); + }, + ); + + eventStore.on( + RELEASE_PLAN_MILESTONE_STARTED, + async ({ featureName, project, environment }) => { + const environmentType = await resolveEnvironmentType( + environment, + cachedEnvironments, + ); + featureFlagUpdateTotal.increment({ + toggle: featureName, + project, + environment, + environmentType, + action: 'updated', + }); + }, + ); + eventStore.on(PROJECT_CREATED, () => { projectActionsCounter.increment({ action: PROJECT_CREATED }); });