Struct TenantRegistry
pub struct TenantRegistry {
tenants: RwLock<RawRwLock, HashMap<u64, Arc<TenantInfo>>>,
audit_sink: Option<Arc<dyn AuditSink>>,
}Expand description
Registry of active tenants with per-tenant quotas and per-engagement cost accounting.
Fields§
§tenants: RwLock<RawRwLock, HashMap<u64, Arc<TenantInfo>>>§audit_sink: Option<Arc<dyn AuditSink>>Implementations§
§impl TenantRegistry
impl TenantRegistry
pub fn new() -> TenantRegistry
pub fn new() -> TenantRegistry
Create an empty registry with no audit sink.
pub fn with_audit_sink(sink: Arc<dyn AuditSink>) -> TenantRegistry
pub fn with_audit_sink(sink: Arc<dyn AuditSink>) -> TenantRegistry
Create a registry that forwards audit events (cross-tenant attempts, quota violations) to the given sink.
pub fn set_audit_sink(&mut self, sink: Arc<dyn AuditSink>)
pub fn set_audit_sink(&mut self, sink: Arc<dyn AuditSink>)
Replace the audit sink on an existing registry.
pub fn register(
&self,
tenant_id: u64,
quota: TenantQuota,
) -> Result<(), RingKernelError>
pub fn register( &self, tenant_id: u64, quota: TenantQuota, ) -> Result<(), RingKernelError>
Register a new tenant with the given quota.
pub fn deregister(&self, tenant_id: u64) -> bool
pub fn deregister(&self, tenant_id: u64) -> bool
Deregister a tenant, dropping all quota and cost state.
pub fn is_registered(&self, tenant_id: u64) -> bool
pub fn is_registered(&self, tenant_id: u64) -> bool
Returns true if the tenant is registered.
pub fn get(&self, tenant_id: u64) -> Option<Arc<TenantInfo>>
pub fn get(&self, tenant_id: u64) -> Option<Arc<TenantInfo>>
Get a snapshot of tenant info (fast Arc clone, no lock held).
pub fn tenant_count(&self) -> usize
pub fn tenant_count(&self) -> usize
Number of registered tenants.
pub fn tenant_ids(&self) -> Vec<u64>
pub fn tenant_ids(&self) -> Vec<u64>
All registered tenant IDs.
pub fn check_quota(
&self,
tenant_id: u64,
audit_tag: AuditTag,
) -> Result<(), RingKernelError>
pub fn check_quota( &self, tenant_id: u64, audit_tag: AuditTag, ) -> Result<(), RingKernelError>
Check whether a send from tenant_id with audit_tag is within quota.
pub fn record_message(&self, tenant_id: u64)
pub fn record_message(&self, tenant_id: u64)
Record a message send for rate-limit accounting.
pub fn track_usage(
&self,
tenant_id: u64,
audit_tag: AuditTag,
gpu_seconds: Duration,
)
pub fn track_usage( &self, tenant_id: u64, audit_tag: AuditTag, gpu_seconds: Duration, )
Record billable GPU-seconds against a (tenant_id, audit_tag) pair.
pub fn get_engagement_cost(&self, audit_tag: AuditTag) -> Duration
pub fn get_engagement_cost(&self, audit_tag: AuditTag) -> Duration
Get total billable duration for a specific engagement across all registered tenants that have reported cost for it.
pub fn get_engagement_cost_for(
&self,
tenant_id: u64,
audit_tag: AuditTag,
) -> Duration
pub fn get_engagement_cost_for( &self, tenant_id: u64, audit_tag: AuditTag, ) -> Duration
Get billable duration for a specific (tenant_id, engagement_id) pair.
pub fn is_cross_tenant(&self, from: u64, to: u64) -> bool
pub fn is_cross_tenant(&self, from: u64, to: u64) -> bool
Returns true if a send would be cross-tenant.
pub fn audit_cross_tenant(
&self,
from_tenant: u64,
to_tenant: u64,
source_kernel: &str,
destination_kernel: &str,
audit_tag: AuditTag,
)
pub fn audit_cross_tenant( &self, from_tenant: u64, to_tenant: u64, source_kernel: &str, destination_kernel: &str, audit_tag: AuditTag, )
Emit an audit event for a cross-tenant K2K send attempt (rejected).
pub fn acquire_kernel_slot(&self, tenant_id: u64) -> Result<(), RingKernelError>
pub fn acquire_kernel_slot(&self, tenant_id: u64) -> Result<(), RingKernelError>
Increment the registered-kernel counter for this tenant, enforcing
TenantQuota::max_concurrent_kernels.
pub fn release_kernel_slot(&self, tenant_id: u64)
pub fn release_kernel_slot(&self, tenant_id: u64)
Release a kernel slot (call on kernel termination / deregister).
Trait Implementations§
§impl Debug for TenantRegistry
impl Debug for TenantRegistry
§impl Default for TenantRegistry
impl Default for TenantRegistry
§fn default() -> TenantRegistry
fn default() -> TenantRegistry
Auto Trait Implementations§
impl !Freeze for TenantRegistry
impl !RefUnwindSafe for TenantRegistry
impl Send for TenantRegistry
impl Sync for TenantRegistry
impl Unpin for TenantRegistry
impl !UnwindSafe for TenantRegistry
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
§fn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more