mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
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)
This commit is contained in:
parent
c2b1fd20e5
commit
cb53df6176
@ -3,6 +3,7 @@ const DB_TIME = 'db_time';
|
|||||||
const SCHEDULER_JOB_TIME = 'scheduler_job_time';
|
const SCHEDULER_JOB_TIME = 'scheduler_job_time';
|
||||||
const FEATURES_CREATED_BY_PROCESSED = 'features_created_by_processed';
|
const FEATURES_CREATED_BY_PROCESSED = 'features_created_by_processed';
|
||||||
const EVENTS_CREATED_BY_PROCESSED = 'events_created_by_processed';
|
const EVENTS_CREATED_BY_PROCESSED = 'events_created_by_processed';
|
||||||
|
const PROXY_REPOSITORY_CREATED = 'proxy_repository_created';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
REQUEST_TIME,
|
REQUEST_TIME,
|
||||||
@ -10,4 +11,5 @@ export {
|
|||||||
SCHEDULER_JOB_TIME,
|
SCHEDULER_JOB_TIME,
|
||||||
FEATURES_CREATED_BY_PROCESSED,
|
FEATURES_CREATED_BY_PROCESSED,
|
||||||
EVENTS_CREATED_BY_PROCESSED,
|
EVENTS_CREATED_BY_PROCESSED,
|
||||||
|
PROXY_REPOSITORY_CREATED,
|
||||||
};
|
};
|
||||||
|
@ -227,6 +227,10 @@ export default class MetricsMonitor {
|
|||||||
name: 'event_created_by_migration_count',
|
name: 'event_created_by_migration_count',
|
||||||
help: 'Event createdBy migration count',
|
help: 'Event createdBy migration count',
|
||||||
});
|
});
|
||||||
|
const proxyRepositoriesCreated = createCounter({
|
||||||
|
name: 'proxy_repositories_created',
|
||||||
|
help: 'Proxy repositories created',
|
||||||
|
});
|
||||||
|
|
||||||
async function collectStaticCounters() {
|
async function collectStaticCounters() {
|
||||||
try {
|
try {
|
||||||
@ -386,6 +390,10 @@ export default class MetricsMonitor {
|
|||||||
dbDuration.labels({ store, action }).observe(time);
|
dbDuration.labels({ store, action }).observe(time);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
eventBus.on(events.PROXY_REPOSITORY_CREATED, () => {
|
||||||
|
proxyRepositoriesCreated.inc();
|
||||||
|
});
|
||||||
|
|
||||||
eventStore.on(FEATURE_CREATED, ({ featureName, project }) => {
|
eventStore.on(FEATURE_CREATED, ({ featureName, project }) => {
|
||||||
featureToggleUpdateTotal.increment({
|
featureToggleUpdateTotal.increment({
|
||||||
toggle: featureName,
|
toggle: featureName,
|
||||||
|
@ -16,10 +16,11 @@ import {
|
|||||||
} from '../types/settings/frontend-settings';
|
} from '../types/settings/frontend-settings';
|
||||||
import { validateOrigins } from '../util';
|
import { validateOrigins } from '../util';
|
||||||
import { BadDataError, InvalidTokenError } from '../error';
|
import { BadDataError, InvalidTokenError } from '../error';
|
||||||
|
import { PROXY_REPOSITORY_CREATED } from '../metric-events';
|
||||||
|
|
||||||
type Config = Pick<
|
type Config = Pick<
|
||||||
IUnleashConfig,
|
IUnleashConfig,
|
||||||
'getLogger' | 'frontendApi' | 'frontendApiOrigins'
|
'getLogger' | 'frontendApi' | 'frontendApiOrigins' | 'eventBus'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
type Stores = Pick<IUnleashStores, 'projectStore' | 'eventStore'>;
|
type Stores = Pick<IUnleashStores, 'projectStore' | 'eventStore'>;
|
||||||
@ -109,6 +110,7 @@ export class ProxyService {
|
|||||||
if (!client) {
|
if (!client) {
|
||||||
client = this.createClientForProxyToken(token);
|
client = this.createClientForProxyToken(token);
|
||||||
this.clients.set(token.secret, client);
|
this.clients.set(token.secret, client);
|
||||||
|
this.config.eventBus.emit(PROXY_REPOSITORY_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
@ -189,9 +191,7 @@ export class ProxyService {
|
|||||||
return this.cachedFrontendSettings;
|
return this.cachedFrontendSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFrontendSettings(
|
async getFrontendSettings(useCache = true): Promise<FrontendSettings> {
|
||||||
useCache: boolean = true,
|
|
||||||
): Promise<FrontendSettings> {
|
|
||||||
if (useCache && this.cachedFrontendSettings) {
|
if (useCache && this.cachedFrontendSettings) {
|
||||||
return this.cachedFrontendSettings;
|
return this.cachedFrontendSettings;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user