From cb53df61769eaeb2fe39f9850c2d17b72f0de7b8 Mon Sep 17 00:00:00 2001 From: David Leek Date: Thu, 15 Feb 2024 14:58:48 +0100 Subject: [PATCH] chore: emit PROXY_REPOSITORY_CREATED event when creating new repo (#6251) ## About the changes - Emits a new event on the eventBus when Proxy-service creates a new repository for a frontend token - Adds a prometheus metrics counter for created proxy-repositories ![image](https://github.com/Unleash/unleash/assets/707867/85a84fa7-4f03-4dc1-b0ba-3ffd2477045b) --- src/lib/metric-events.ts | 2 ++ src/lib/metrics.ts | 8 ++++++++ src/lib/services/proxy-service.ts | 8 ++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib/metric-events.ts b/src/lib/metric-events.ts index ced4e822a0..f74a163e2e 100644 --- a/src/lib/metric-events.ts +++ b/src/lib/metric-events.ts @@ -3,6 +3,7 @@ const DB_TIME = 'db_time'; const SCHEDULER_JOB_TIME = 'scheduler_job_time'; const FEATURES_CREATED_BY_PROCESSED = 'features_created_by_processed'; const EVENTS_CREATED_BY_PROCESSED = 'events_created_by_processed'; +const PROXY_REPOSITORY_CREATED = 'proxy_repository_created'; export { REQUEST_TIME, @@ -10,4 +11,5 @@ export { SCHEDULER_JOB_TIME, FEATURES_CREATED_BY_PROCESSED, EVENTS_CREATED_BY_PROCESSED, + PROXY_REPOSITORY_CREATED, }; diff --git a/src/lib/metrics.ts b/src/lib/metrics.ts index dcc5c3c85c..7a448ed5a8 100644 --- a/src/lib/metrics.ts +++ b/src/lib/metrics.ts @@ -227,6 +227,10 @@ export default class MetricsMonitor { name: 'event_created_by_migration_count', help: 'Event createdBy migration count', }); + const proxyRepositoriesCreated = createCounter({ + name: 'proxy_repositories_created', + help: 'Proxy repositories created', + }); async function collectStaticCounters() { try { @@ -386,6 +390,10 @@ export default class MetricsMonitor { dbDuration.labels({ store, action }).observe(time); }); + eventBus.on(events.PROXY_REPOSITORY_CREATED, () => { + proxyRepositoriesCreated.inc(); + }); + eventStore.on(FEATURE_CREATED, ({ featureName, project }) => { featureToggleUpdateTotal.increment({ toggle: featureName, diff --git a/src/lib/services/proxy-service.ts b/src/lib/services/proxy-service.ts index 9a05b944d7..5fea01a3a8 100644 --- a/src/lib/services/proxy-service.ts +++ b/src/lib/services/proxy-service.ts @@ -16,10 +16,11 @@ import { } from '../types/settings/frontend-settings'; import { validateOrigins } from '../util'; import { BadDataError, InvalidTokenError } from '../error'; +import { PROXY_REPOSITORY_CREATED } from '../metric-events'; type Config = Pick< IUnleashConfig, - 'getLogger' | 'frontendApi' | 'frontendApiOrigins' + 'getLogger' | 'frontendApi' | 'frontendApiOrigins' | 'eventBus' >; type Stores = Pick; @@ -109,6 +110,7 @@ export class ProxyService { if (!client) { client = this.createClientForProxyToken(token); this.clients.set(token.secret, client); + this.config.eventBus.emit(PROXY_REPOSITORY_CREATED); } return client; @@ -189,9 +191,7 @@ export class ProxyService { return this.cachedFrontendSettings; } - async getFrontendSettings( - useCache: boolean = true, - ): Promise { + async getFrontendSettings(useCache = true): Promise { if (useCache && this.cachedFrontendSettings) { return this.cachedFrontendSettings; }