Skip to content

Commit

Permalink
chore: emit PROXY_REPOSITORY_CREATED event when creating new repo (#6251
Browse files Browse the repository at this point in the history
)

## 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)
  • Loading branch information
daveleek committed Feb 15, 2024
1 parent c2b1fd2 commit cb53df6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/lib/metric-events.ts
Expand Up @@ -3,11 +3,13 @@ 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,
DB_TIME,
SCHEDULER_JOB_TIME,
FEATURES_CREATED_BY_PROCESSED,
EVENTS_CREATED_BY_PROCESSED,
PROXY_REPOSITORY_CREATED,
};
8 changes: 8 additions & 0 deletions src/lib/metrics.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/lib/services/proxy-service.ts
Expand Up @@ -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<IUnleashStores, 'projectStore' | 'eventStore'>;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -189,9 +191,7 @@ export class ProxyService {
return this.cachedFrontendSettings;
}

async getFrontendSettings(
useCache: boolean = true,
): Promise<FrontendSettings> {
async getFrontendSettings(useCache = true): Promise<FrontendSettings> {
if (useCache && this.cachedFrontendSettings) {
return this.cachedFrontendSettings;
}
Expand Down

0 comments on commit cb53df6

Please sign in to comment.