1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Static configuration for the native `MeteringService`: entity/topic names,
//! window + rollup defaults, list caps, and the resolve-once rollup env knobs
//! (never a per-request env read).
use OnceLock;
use Duration;
pub const USAGE_EVENT_MSG: &str = "udb.core.metering.entity.v1.UsageEvent";
pub const QUOTA_RULE_MSG: &str = "udb.core.metering.entity.v1.QuotaRule";
pub const TOPIC_QUOTA_CHANGED: &str = "udb.metering.quota.changed.v1";
pub const TOPIC_USAGE_ROLLUP: &str = "udb.metering.rollup.v1";
/// Default rolling window when a caller/rule does not specify one (24h).
pub const DEFAULT_WINDOW_SECONDS: i64 = 86_400;
/// Billing/export rollup bucket width. Closed hourly windows are emitted by
/// default so a restarted leader can replay a bounded recent range.
pub const DEFAULT_ROLLUP_WINDOW_SECONDS: i64 = 3_600;
const DEFAULT_ROLLUP_LOOKBACK_SECONDS: i64 = 86_400;
const DEFAULT_ROLLUP_INTERVAL_SECS: u64 = 300;
const ROLLUP_WINDOW_ENV: &str = "UDB_METERING_ROLLUP_WINDOW_SECS";
const ROLLUP_LOOKBACK_ENV: &str = "UDB_METERING_ROLLUP_LOOKBACK_SECS";
const ROLLUP_INTERVAL_ENV: &str = "UDB_METERING_ROLLUP_INTERVAL_SECS";
pub const METERING_ROLLUP_BATCH: i64 = 200;
/// Default unit for an event with no explicit unit.
pub const DEFAULT_UNIT: &str = "request";
/// Unit emitted by the automatic fair-admission hook. The quantity is the same
/// bounded operation cost that `ChannelManager` accounts in metrics.
pub const ADMISSION_METERING_UNIT: &str = "admission_cost";
/// List defaults/caps so one tenant cannot scan an unbounded quota table.
pub const DEFAULT_LIST_LIMIT: u32 = 100;
pub const MAX_LIST_LIMIT: u32 = 1_000;
pub
pub
pub