diff --git a/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts b/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts index 3cac9e924ecf..ee19793d6ba7 100644 --- a/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts +++ b/src/lib/features/client-feature-toggles/client-feature-toggle.controller.ts @@ -23,6 +23,7 @@ import type { OpenApiService } from '../../services/openapi-service'; import { NONE } from '../../types/permissions'; import { createResponseSchema } from '../../openapi/util/create-response-schema'; import type { ClientFeaturesQuerySchema } from '../../openapi/spec/client-features-query-schema'; +import type EventEmitter from 'events'; import { clientFeatureSchema, type ClientFeatureSchema, @@ -33,6 +34,10 @@ import { } from '../../openapi/spec/client-features-schema'; import type ConfigurationRevisionService from '../feature-toggle/configuration-revision-service'; import type { ClientFeatureToggleService } from './client-feature-toggle-service'; +import { + CLIENT_METRICS_NAMEPREFIX, + CLIENT_METRICS_TAGS, +} from '../../internals'; const version = 2; @@ -62,6 +67,8 @@ export default class FeatureController extends Controller { private flagResolver: IFlagResolver; + private eventBus: EventEmitter; + private featuresAndSegments: ( query: IFeatureToggleQuery, etag: string, @@ -92,6 +99,7 @@ export default class FeatureController extends Controller { this.configurationRevisionService = configurationRevisionService; this.featureToggleService = featureToggleService; this.flagResolver = config.flagResolver; + this.eventBus = config.eventBus; this.logger = config.getLogger('client-api/feature.js'); this.route({ @@ -210,6 +218,14 @@ export default class FeatureController extends Controller { return {}; } + if (namePrefix) { + this.eventBus.emit(CLIENT_METRICS_NAMEPREFIX); + } + + if (tag) { + this.eventBus.emit(CLIENT_METRICS_TAGS); + } + const tagQuery = this.paramToArray(tag); const projectQuery = this.paramToArray(project); const query = await querySchema.validateAsync({ diff --git a/src/lib/metric-events.ts b/src/lib/metric-events.ts index 261e76728d2c..366bc5c4b160 100644 --- a/src/lib/metric-events.ts +++ b/src/lib/metric-events.ts @@ -1,4 +1,5 @@ import type EventEmitter from 'events'; +import { CLIENT_METRICS } from './internals'; const REQUEST_TIME = 'request_time'; const DB_TIME = 'db_time'; @@ -14,6 +15,8 @@ const USER_LOGIN = 'user-login' as const; const EXCEEDS_LIMIT = 'exceeds-limit' as const; const REQUEST_ORIGIN = 'request_origin' as const; const ADDON_EVENTS_HANDLED = 'addon-event-handled' as const; +const CLIENT_METRICS_NAMEPREFIX = 'client-api-nameprefix'; +const CLIENT_METRICS_TAGS = 'client-api-tags'; type MetricEvent = | typeof REQUEST_TIME @@ -28,7 +31,9 @@ type MetricEvent = | typeof STAGE_ENTERED | typeof USER_LOGIN | typeof EXCEEDS_LIMIT - | typeof REQUEST_ORIGIN; + | typeof REQUEST_ORIGIN + | typeof CLIENT_METRICS_NAMEPREFIX + | typeof CLIENT_METRICS_TAGS; type RequestOriginEventPayload = { type: 'UI' | 'API'; @@ -76,6 +81,8 @@ export { EXCEEDS_LIMIT, REQUEST_ORIGIN, ADDON_EVENTS_HANDLED, + CLIENT_METRICS_NAMEPREFIX, + CLIENT_METRICS_TAGS, type MetricEvent, type MetricEventPayload, emitMetricEvent, diff --git a/src/lib/metrics.ts b/src/lib/metrics.ts index 480c60e9cddf..90dcbacfc5c4 100644 --- a/src/lib/metrics.ts +++ b/src/lib/metrics.ts @@ -504,6 +504,16 @@ export function registerPrometheusMetrics( }) .set(config.rateLimiting.callSignalEndpointMaxPerSecond * 60); + const namePrefixUsed = createCounter({ + name: 'nameprefix_count', + help: 'Count of nameprefix usage in client api', + }); + + const tagsUsed = createCounter({ + name: 'tags_count', + help: 'Count of tags usage in client api', + }); + const featureCreatedByMigration = createCounter({ name: 'feature_created_by_migration_count', help: 'Feature createdBy migration count', @@ -734,6 +744,14 @@ export function registerPrometheusMetrics( mapFeaturesForClientDuration.observe(duration); }); + eventBus.on(events.CLIENT_METRICS_NAMEPREFIX, () => { + namePrefixUsed.inc(); + }); + + eventBus.on(events.CLIENT_METRICS_TAGS, () => { + tagsUsed.inc(); + }); + events.onMetricEvent( eventBus, events.REQUEST_ORIGIN,