Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub now: u64,
    pub alerts: AlertThresholds,
    pub expiry_window: u64,
}
Expand description

Operator-tunable thresholds for the whole dashboard.

Fields§

§now: u64§alerts: AlertThresholds§expiry_window: u64

Implementations§

Source§

impl Config

Source

pub fn at(now: u64) -> Self

Examples found in repository?
examples/snapshot.rs (line 37)
2fn main() {
3    let obs = Observations {
4        homes: vec![
5            HomeObs { id: "home-ny-1".into(), region: "us-east".into(), online: true },
6            HomeObs { id: "home-ny-2".into(), region: "us-east".into(), online: true },
7            HomeObs { id: "home-sf-1".into(), region: "us-west".into(), online: false },
8        ],
9        shards: vec![
10            ShardObs { id: "profiles-0".into(), collection: "profiles".into(), reachable_replicas: 3, target_replicas: 3, durable_floor: 1, size_bytes: 4 << 30 },
11            ShardObs { id: "photos-7".into(), collection: "photos".into(), reachable_replicas: 2, target_replicas: 3, durable_floor: 1, size_bytes: 60 << 30 },
12            ShardObs { id: "ledger-2".into(), collection: "ledger".into(), reachable_replicas: 1, target_replicas: 3, durable_floor: 1, size_bytes: 1 << 30 },
13        ],
14        strong: vec![
15            StrongObs { collection: "usernames".into(), members_online: 3, members_total: 3 },
16            StrongObs { collection: "seats".into(), members_online: 1, members_total: 3 },
17        ],
18        lags: vec![ LagObs { collection: "photos".into(), lag_ops: 340, region: Some("us-west".into()) } ],
19        capabilities: vec![
20            CapabilityObs { bearer: "did:mata:alice".into(), scope: "profiles".into(), ops: "rw".into(), expiry: Some(1_700_003_600), budget_micro_mata: None, revoked: false },
21            CapabilityObs { bearer: "did:agent:assistant".into(), scope: "profiles".into(), ops: "rc".into(), expiry: Some(1_702_592_000), budget_micro_mata: Some(1_000_000), revoked: false },
22        ],
23        audit: vec![
24            AuditObs { actor: "did:agent:assistant".into(), action: "retrieve".into(), at: 1_700_000_000, allowed: true },
25            AuditObs { actor: "did:agent:assistant".into(), action: "write".into(), at: 1_700_000_050, allowed: false },
26        ],
27        settled: vec![
28            SettledObs { host_did: "home-ny-1".into(), settles_to_did: "alice".into(), resource: Resource::Storage, micro_mata: 4_200_000 },
29            SettledObs { host_did: "home-ny-2".into(), settles_to_did: "alice".into(), resource: Resource::Compute, micro_mata: 380_000 },
30            SettledObs { host_did: "home-ny-1".into(), settles_to_did: "bob".into(), resource: Resource::Transit, micro_mata: 95_000 },
31        ],
32        budgets: vec![
33            AgentBudgetObs { agent: "did:agent:assistant".into(), remaining: 40_000, limit: 1_000_000 },
34        ],
35        unsettled_claims: 12,
36    };
37    print!("{}", Dashboard::assemble(&obs, &Config::at(1_700_000_100)).render_text());
38}
More examples
Hide additional examples
examples/ir_console.rs (line 90)
10fn main() {
11    let homes = (0..50)
12        .map(|i| HomeObs {
13            id: format!("home-{i:03}"),
14            region: ["us-east", "us-west", "eu"][i % 3].into(),
15            online: i % 7 != 0,
16        })
17        .collect();
18    let shards = (0..300u32)
19        .map(|i| ShardObs {
20            id: format!("shard-{i:04}"),
21            collection: ["profiles", "photos", "ledger", "notes"][i as usize % 4].into(),
22            reachable_replicas: i % 4,
23            target_replicas: 3,
24            durable_floor: 1,
25            size_bytes: (i as u64 + 1) << 24,
26        })
27        .collect();
28    let strong = (0..10u32)
29        .map(|i| StrongObs {
30            collection: format!("strong-{i}"),
31            members_online: i % 4,
32            members_total: 3,
33        })
34        .collect();
35    let lags = (0..20u64)
36        .map(|i| LagObs {
37            collection: format!("col-{i}"),
38            lag_ops: i * 37,
39            region: Some("us-west".into()),
40        })
41        .collect();
42    let capabilities = (0..50u64)
43        .map(|i| CapabilityObs {
44            bearer: format!("did:agent:a{}", i % 12),
45            scope: "profiles".into(),
46            ops: "rw".into(),
47            expiry: Some(1_700_000_000 + i * 600),
48            budget_micro_mata: Some(1_000_000),
49            revoked: i % 9 == 0,
50        })
51        .collect();
52    let audit = (0..3000u64)
53        .map(|i| AuditObs {
54            actor: format!("did:agent:a{}", i % 12),
55            action: "write".into(),
56            at: 1_700_000_000 + i,
57            allowed: i % 5 != 0,
58        })
59        .collect();
60    let settled = (0..2000u64)
61        .map(|i| SettledObs {
62            host_did: format!("home-{:03}", i % 50),
63            settles_to_did: format!("customer-{}", i % 25),
64            resource: [Resource::Storage, Resource::Compute, Resource::Transit][i as usize % 3],
65            micro_mata: 1_000 + i,
66        })
67        .collect();
68    let budgets = (0..30u64)
69        .map(|i| AgentBudgetObs {
70            agent: format!("did:agent:a{i}"),
71            remaining: i * 10_000,
72            limit: 1_000_000,
73        })
74        .collect();
75    let obs = Observations {
76        homes,
77        shards,
78        strong,
79        lags,
80        capabilities,
81        audit,
82        settled,
83        budgets,
84        unsettled_claims: 12,
85    };
86
87    let mut rendered = 0usize;
88    let mut critical = 0usize;
89    for _ in 0..20 {
90        let dash = Dashboard::assemble(&obs, &Config::at(1_700_000_100));
91        critical += dash.critical_count();
92        rendered += dash.render_text().len();
93    }
94
95    let mut settlement = LocalSettlement::new(RateCard {
96        storage_per_gib_month: 5_000_000,
97        compute_per_megafuel: 1_000_000,
98        compute_per_invocation: 1_000,
99        transit_per_gib: 1_000_000,
100    });
101    let mut total = 0u64;
102    for i in 0..2000u64 {
103        let claim = UsageClaim::new(
104            format!("home-{:03}", i % 50),
105            format!("customer-{}", i % 25),
106            Usage::compute(1_000_000 + i, 1),
107            i,
108            i + 60,
109        );
110        total += settlement.settle(&claim).unwrap().micro_mata;
111    }
112    println!(
113        "rendered {rendered} critical {critical} settled {total} receipts {}",
114        settlement.receipts().len()
115    );
116}

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Config

Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.