MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / check

Method check

nodedb/src/control/security/tenant.rs:138–173  ·  view source on GitHub ↗

Check if a request from the tenant is within quota.

(&self, tenant_id: TenantId)

Source from the content-addressed store, hash-verified

136
137 /// Check if a request from the tenant is within quota.
138 pub fn check(&self, tenant_id: TenantId) -> QuotaCheck {
139 let quota = self.quota(tenant_id);
140 let usage = self.usage.get(&tenant_id);
141
142 let usage = match usage {
143 Some(u) => u,
144 None => return QuotaCheck::Allowed, // No usage yet.
145 };
146
147 if usage.memory_bytes > quota.max_memory_bytes {
148 return QuotaCheck::MemoryExceeded {
149 used: usage.memory_bytes,
150 limit: quota.max_memory_bytes,
151 };
152 }
153 if usage.storage_bytes > quota.max_storage_bytes {
154 return QuotaCheck::StorageExceeded {
155 used: usage.storage_bytes,
156 limit: quota.max_storage_bytes,
157 };
158 }
159 if usage.active_requests >= quota.max_concurrent_requests {
160 return QuotaCheck::ConcurrencyExceeded {
161 active: usage.active_requests,
162 limit: quota.max_concurrent_requests,
163 };
164 }
165 if usage.requests_this_second >= quota.max_qps {
166 return QuotaCheck::RateLimited {
167 qps: usage.requests_this_second,
168 limit: quota.max_qps,
169 };
170 }
171
172 QuotaCheck::Allowed
173 }
174
175 /// Record a new request from a tenant.
176 pub fn request_start(&mut self, tenant_id: TenantId) {

Callers 5

explain_permissionFunction · 0.45
check_tenant_quotaMethod · 0.45
check_permissionMethod · 0.45
check_rate_limitFunction · 0.45

Calls 2

quotaMethod · 0.80
getMethod · 0.45