Skip to content

UNOMI-958: Extend tenant usage API and add event retention purge#811

Merged
sergehuber merged 4 commits into
masterfrom
UNOMI-958-usage-rest
Jul 9, 2026
Merged

UNOMI-958: Extend tenant usage API and add event retention purge#811
sergehuber merged 4 commits into
masterfrom
UNOMI-958-usage-rest

Conversation

@sergehuber

@sergehuber sergehuber commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Plain-language summary

Multi-tenant operators could not see how much each customer was using Unomi (profiles, events, scopes, storage, and similar). Upstream billing and plan tools need a supported way to read that usage and, for retention policies, to delete old events per tenant without talking to the search cluster directly.

This change adds a read-only usage API and a tenant-scoped event purge API on the tenant REST endpoints. It also removes old quota code that suggested Unomi enforced limits when it did not. Tenant admins can manage their own tenant; platform admins can manage any tenant.

What changed

  • Extend GET /cxs/tenants/{tenantId}/usage with monthly event counts, scope totals, per-scope segment/rule breakdown, active API key count, and periodStart / periodEnd.
  • Support period=current-month (default), YYYY-MM, and legacy 24h (same as current month).
  • Add POST /cxs/tenants/{tenantId}/purge/events?retentionDays=N for tenant-scoped event retention (minimum 7 days).
  • Add TenantScopeUsage, TenantEventPurgeResult, and expand TenantUsageService / TenantUsageServiceImpl.
  • Remove unreleased ResourceQuota and replace TenantMonitoringService / TenantQuotaService.
  • Record in-memory REST request counts per tenant after successful auth (observability only).
  • Harden tenant REST security: @RequiresTenant on tenant-scoped routes, class/method role resolution in SecurityFilter.
  • Fix KarafSecurityService.clearCurrentSubject() to clear the request subject correctly.
  • Update multitenancy manual; add service, REST, and integration test coverage for usage and purge endpoints.

Test plan

  • mvn -pl services -Dmaven.build.cache.enabled=false test -Dtest=TenantUsageServiceImplTest (19 tests)
  • mvn -pl rest -Dmaven.build.cache.enabled=false test -Dtest=TenantEndpointTest (7 tests)
  • mvn -pl rest test -Dtest=SecurityFilterTest
  • mvn -pl services-common test -Dtest=KarafSecurityServiceTest
  • mvn -pl api,services,rest,services-common,itests -am test-compile
  • CI integration tests (TenantIT usage and purge coverage)

References

UNOMI-958

Operators and upstream control planes need read-only usage metrics per tenant.
Unomi measures usage; plan limits stay outside the CDP. This adds GET /tenants/{id}/usage,
replaces internal monitoring/quota services, and hardens tenant-scoped REST security.
Expand the per-tenant usage snapshot for upstream reconcile jobs (monthly
events, scope counts, per-scope breakdown) and add a tenant-scoped event
purge endpoint. Add service, REST, and integration test coverage.
@sergehuber sergehuber changed the title UNOMI-958: Expose per-tenant usage over REST UNOMI-958: Extend tenant usage API and add event retention purge Jul 8, 2026
… RBAC

RuntimeExceptionMapper now preserves WebApplicationException status/message
instead of collapsing every thrown WebApplicationException to a 500, fixing
validation error responses on TenantEndpoint and TaskEndpoint.

Removed a broken TenantIT test that sent tenant private-key credentials to
a JAAS-only auth path, which produced repeated failed JAAS logins with
knock-on effects on later tests in the shared container.

TaskEndpoint now accepts TENANT_ADMINISTRATOR in addition to ADMINISTRATOR,
matching the pattern already used by TenantEndpoint's usage/purge endpoints;
scheduled tasks are tenant-scoped at the persistence layer so this doesn't
weaken isolation.

Also fixes two tenant-scoping gaps in the in-memory persistence test double
(queryCount, calculateStorageSize) and adds regression coverage for tenant
usage isolation and the exception mapper fix.
@sergehuber sergehuber merged commit b8fb5f7 into master Jul 9, 2026
7 checks passed
@sergehuber sergehuber deleted the UNOMI-958-usage-rest branch July 9, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant