SIGN IN SIGN UP

feat(server): add a gauge tracking feature flag rollout across workspaces (#24685)

## What

Adds `twenty_feature_flag_enabled_workspaces`, an OpenTelemetry
observable gauge (exported to Prometheus) labelled by `flag_key`,
reporting how many workspaces have each feature flag enabled.

This gives a metric-based view of a per-workspace feature flag rollout
(e.g. the ORM v2 read path) so progress can be tracked on a dashboard
instead of ad-hoc DB queries against `core."featureFlag"`.

## How

- New `FeatureFlagMetricsService` (`OnModuleInit`) follows the existing
`DatabaseGaugeService` pattern: it registers a
`createMultiObservableGauge` whose callback runs `SELECT key, COUNT(*)
... WHERE value = true GROUP BY key` against the core datasource and
emits one observation per flag with `{ flag_key }` as the attribute.
- Wired into `FeatureFlagModule` (imports `MetricsModule`, provides the
new service).
- The query result is cached (`cacheValue: true`, 60s TTL in
`MetricsService`), so each pod runs at most one small count query per
minute. Cardinality is one series per feature flag (low).

## Notes

- Every server pod reports the same DB-derived count, so dashboards
should aggregate across replicas with `max by (flag_key)`.
- The companion Grafana dashboard lives in twenty-infra (`Twenty /
Feature Flag Release`).
- No spec added, matching the existing gauge/metric services
(`DatabaseGaugeService`, `EventLoopMetricsService`), which have none.

## Test plan

- [ ] Typecheck / lint pass (CI).
- [ ] After deploy, confirm
`twenty_feature_flag_enabled_workspaces{flag_key="IS_ORM_V2_READ_PATH_ENABLED"}`
appears in Prometheus and matches the row count in `core."featureFlag"`.


<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/24685?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
C
Charles Bochet committed
7e1dc6fcba0b880421805c699fc42e92eff7bcf9
Parent: c1fcccc
Committed by GitHub <noreply@github.com> on 8/24/2026, 12:10:23 PM