Loading…
Loading…
Explains how the runtime's License Enforcement Probe periodically reads and caches the license state from the database for fast, per-request checks.
The EnforcementProbe is a component within the data-plane runtime responsible for monitoring the platform's license enforcement status. It provides an efficient, low-latency mechanism for the runtime to check the current enforcement state on a per-request basis.
This component solves the problem of needing to enforce licensing rules in the high-throughput data plane without incurring the performance cost of verifying a license JWT on every request. It achieves this by separating concerns:
admin-api component performs the computationally intensive task of parsing and verifying the license. It then resolves the license terms into a simple, authoritative enforcement state.admin-api persists this state to a central database table (s2r_system_setting).EnforcementProbe in each runtime instance reads this pre-calculated state from the database, caches it in memory, and makes it available to other runtime components, such as a request-path filter.This design ensures that the runtime acts only on the resolved state and does not need to contain any license verification logic itself.
The EnforcementProbe maintains an in-memory, atomically updated cache of the current EnforcementState. This cache is consulted by a request filter on every incoming request, avoiding any database overhead during request processing. The cache is populated and kept up-to-date through a scheduled refresh mechanism.
flowchart TD
subgraph Admin API
A[License JWT Verification] --> B{Enforcement State Machine};
B --> C[Write to DB];
end
subgraph Database
D[s2r_system_setting table];
end
subgraph Runtime
subgraph EnforcementProbe
E[Scheduled Refresh] --> F{Read from DB};
F --> G[Update In-Memory Cache];
end
H[Request Filter] --> I[Read from Cache];
I --> J{Enforce Policy};
end
C -- "Writes 'specaria.enforcement_state'" --> D;
F -- "Reads 'specaria.enforcement_state'" --> D;
G -- "Provides state via currentState()" --> I;The operational lifecycle is as follows:
EnforcementState.NORMAL.ApplicationStartedEvent), the probe executes its first refresh. This ensures that the cache is populated with the true state from the database before the runtime serves its first request.refresh() method is called:
specaria.enforcement_state key from the s2r_system_setting table.__platform__ tenant context to guarantee it retrieves the global, system-wide setting.EnforcementState.NORMAL. The runtime never hardens its enforcement level due to a missing upstream value.S2R-LIC-RUN enforcement state transition...) detailing the change. It also fetches the specaria.enforcement_mode value for inclusion in this log message.currentState() method to get the current cached EnforcementState. This is a fast, in-memory read that is safe to call on every request.The probe's refresh schedule is controlled by the following configuration properties. The values must be specified in ISO-8601 duration format.
| Parameter | Type | Default | Description |
|---|---|---|---|
s2r.runtime.enforcement-probe.refresh-interval | String | PT60S | The interval between periodic refreshes of the cached license state. |
s2r.runtime.enforcement-probe.refresh-initial-delay | String | PT60S | The delay before the first scheduled refresh runs after application startup. |
The probe's operation is critically dependent on reading state from the s2r_system_setting table. This table acts as a communication channel between the admin-api and the runtime.
IMPORTANT
The database keys are a frozen contract between the admin-api and the runtime. Do not rename them.
specaria.enforcement_state: The primary key holding the authoritative enforcement state (e.g., NORMAL).specaria.enforcement_mode: An auxiliary key holding a descriptive string about the current state, used for logging purposes.The probe uses the following SQL query to read the effective value for a given key, scoped to the platform tenant.
select setting_value #>> '{}' as v
from s2r_system_setting
where setting_key = ? and is_effective = true
and tenant_id = '__platform__' or (tenant_id is null and not exists (select 1 from s2r_system_setting s2 where s2.setting_key = s2r_system_setting.setting_key and s2.tenant_id = '__platform__')) order by tenant_id is null asc, updated_at desc limit 1
The EnforcementProbe component exposes a programmatic API for internal use within the runtime.
currentState()Returns the currently cached license enforcement state. This is a fast, non-blocking, in-memory operation and is the primary method for checking the license status on the request path.
EnforcementState - The cached enforcement state.currentMode()Returns the raw string value of the specaria.enforcement_mode setting as of the last successful refresh. This is intended for logging and diagnostics.
String - The last known mode string, or null if a refresh has never completed or the setting was absent.refresh()Manually triggers a refresh of the enforcement state from the database. This method is public for testing and targeted diagnostic purposes.
EnforcementState - The new state after the refresh attempt. If the database read fails, this will be the same as the previously cached state.WARN message is logged: S2R-LIC-RUN enforcement setting read failed for <key>: <error>.specaria.enforcement_state row is not present in the s2r_system_setting table, or its value is blank.EnforcementState.NORMAL. This is a fail-open design choice to prevent the system from becoming overly restrictive if the admin-api has not yet written the state or has written an invalid one.NORMAL to a more restrictive state).INFO message is logged: S2R-LIC-RUN enforcement state transition <PREVIOUS>-><NEXT> (mode=<mode>).EnforcementState to the database for this probe to consume.OfflineGraceProbe) that reads the specaria.last_platform_contact_at setting to determine platform connectivity status.