pub struct UsageCounter {Show 14 fields
pub id: Uuid,
pub org_id: Uuid,
pub period_start: NaiveDate,
pub requests: i64,
pub egress_bytes: i64,
pub storage_bytes: i64,
pub ai_tokens_used: i64,
pub runner_seconds_used: i64,
pub tunnel_bytes_used: i64,
pub snapshot_bytes_stored: i64,
pub log_bytes_ingested: i64,
pub capture_bytes_stored: i64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Usage counter for monthly tracking
Fields§
§id: Uuid§org_id: Uuid§period_start: NaiveDate§requests: i64§egress_bytes: i64§storage_bytes: i64§ai_tokens_used: i64§runner_seconds_used: i64Wall-clock test/chaos/scenario runner time consumed this period. Migration 20250101000059 adds this column with default 0.
tunnel_bytes_used: i64Tunnel relay bytes (in + out) consumed this period. Migration 20250101000061 adds this column with default 0.
snapshot_bytes_stored: i64Total snapshot blob storage in use across the org. Unlike the other meters this is a current value (gauge) not a monthly sum (counter) — snapshots are billed against an instantaneous quota, not throughput. Migration 20250101000063 adds this column with default 0.
log_bytes_ingested: i64Observability log/trace ingest volume this period. Migration 20250101000065 adds this column with default 0.
capture_bytes_stored: i64Total recorder capture blob storage in use across the org. Gauge, not counter — same shape as snapshot_bytes_stored. Migration 20250101000068 adds this column with default 0.
created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl UsageCounter
impl UsageCounter
Sourcepub async fn get_or_create_current(
pool: &Pool<Postgres>,
org_id: Uuid,
) -> Result<UsageCounter, Error>
pub async fn get_or_create_current( pool: &Pool<Postgres>, org_id: Uuid, ) -> Result<UsageCounter, Error>
Get or create usage counter for current month
Sourcepub async fn increment_requests(
pool: &Pool<Postgres>,
org_id: Uuid,
count: i64,
) -> Result<(), Error>
pub async fn increment_requests( pool: &Pool<Postgres>, org_id: Uuid, count: i64, ) -> Result<(), Error>
Increment request count
Sourcepub async fn increment_egress(
pool: &Pool<Postgres>,
org_id: Uuid,
bytes: i64,
) -> Result<(), Error>
pub async fn increment_egress( pool: &Pool<Postgres>, org_id: Uuid, bytes: i64, ) -> Result<(), Error>
Increment egress bytes
Sourcepub async fn update_storage(
pool: &Pool<Postgres>,
org_id: Uuid,
bytes: i64,
) -> Result<(), Error>
pub async fn update_storage( pool: &Pool<Postgres>, org_id: Uuid, bytes: i64, ) -> Result<(), Error>
Update storage bytes (absolute value, not increment)
Sourcepub async fn increment_ai_tokens(
pool: &Pool<Postgres>,
org_id: Uuid,
tokens: i64,
) -> Result<(), Error>
pub async fn increment_ai_tokens( pool: &Pool<Postgres>, org_id: Uuid, tokens: i64, ) -> Result<(), Error>
Increment AI tokens used
Sourcepub async fn increment_runner_seconds(
pool: &Pool<Postgres>,
org_id: Uuid,
seconds: i64,
) -> Result<(), Error>
pub async fn increment_runner_seconds( pool: &Pool<Postgres>, org_id: Uuid, seconds: i64, ) -> Result<(), Error>
Increment runner-seconds used. Charged for every wall-clock second
a cloud worker spends on a test/chaos/scenario/etc. run. Plan limits
live in organizations.limits_json under runner_seconds_per_month.
Sourcepub async fn increment_tunnel_bytes(
pool: &Pool<Postgres>,
org_id: Uuid,
bytes: i64,
) -> Result<(), Error>
pub async fn increment_tunnel_bytes( pool: &Pool<Postgres>, org_id: Uuid, bytes: i64, ) -> Result<(), Error>
Increment tunnel relay bytes (in + out summed). Reported by the
relay binary via internal mTLS routes. Plan limits live in
organizations.limits_json under tunnel_bytes_per_month.
Sourcepub async fn set_snapshot_bytes(
pool: &Pool<Postgres>,
org_id: Uuid,
bytes: i64,
) -> Result<(), Error>
pub async fn set_snapshot_bytes( pool: &Pool<Postgres>, org_id: Uuid, bytes: i64, ) -> Result<(), Error>
Set snapshot blob storage used by the org. Unlike the other meters
this is a gauge — snapshot bytes go up when a capture finishes
and down when one is deleted/expired, so callers compute the new
total and write it. Plan limits live in organizations.limits_json
under snapshot_bytes_quota.
Sourcepub async fn increment_log_bytes(
pool: &Pool<Postgres>,
org_id: Uuid,
bytes: i64,
) -> Result<(), Error>
pub async fn increment_log_bytes( pool: &Pool<Postgres>, org_id: Uuid, bytes: i64, ) -> Result<(), Error>
Increment observability log/trace ingest bytes. Reported by the
log shipper / OTLP collector via internal routes. Plan limits
live in organizations.limits_json under log_bytes_per_month.
Sourcepub async fn get_for_period(
pool: &Pool<Postgres>,
org_id: Uuid,
period_start: NaiveDate,
) -> Result<Option<UsageCounter>, Error>
pub async fn get_for_period( pool: &Pool<Postgres>, org_id: Uuid, period_start: NaiveDate, ) -> Result<Option<UsageCounter>, Error>
Get usage for a specific period
Sourcepub async fn get_all_for_org(
pool: &Pool<Postgres>,
org_id: Uuid,
) -> Result<Vec<UsageCounter>, Error>
pub async fn get_all_for_org( pool: &Pool<Postgres>, org_id: Uuid, ) -> Result<Vec<UsageCounter>, Error>
Get all usage counters for an org
Trait Implementations§
Source§impl Clone for UsageCounter
impl Clone for UsageCounter
Source§fn clone(&self) -> UsageCounter
fn clone(&self) -> UsageCounter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for UsageCounter
impl Debug for UsageCounter
Source§impl<'de> Deserialize<'de> for UsageCounter
impl<'de> Deserialize<'de> for UsageCounter
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UsageCounter, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UsageCounter, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<'a, R> FromRow<'a, R> for UsageCounterwhere
R: Row,
&'a str: ColumnIndex<R>,
Uuid: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
NaiveDate: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i64: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
DateTime<Utc>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
impl<'a, R> FromRow<'a, R> for UsageCounterwhere
R: Row,
&'a str: ColumnIndex<R>,
Uuid: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
NaiveDate: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
i64: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
DateTime<Utc>: Decode<'a, <R as Row>::Database> + Type<<R as Row>::Database>,
Source§impl Serialize for UsageCounter
impl Serialize for UsageCounter
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for UsageCounter
impl RefUnwindSafe for UsageCounter
impl Send for UsageCounter
impl Sync for UsageCounter
impl Unpin for UsageCounter
impl UnsafeUnpin for UsageCounter
impl UnwindSafe for UsageCounter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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