Skip to content

Commit

Permalink
feat: push canister metrics to cycle monitoring infrastructure (#191)
Browse files Browse the repository at this point in the history
* build: bump serde

* build: add rust toolchain yaml to declaritively specify rust toolchain to use

* refactor: clean up all warnings from Clippy

* refactor: move know principals to configuration field

* chore: intermediate save

* docs: move docs to their own folder

* chore: intermediate save. test repo

* feat: implement pinging an external endpoint to export canister metrics

* chore: canister deploy with quill
  • Loading branch information
saikatdas0790 authored Aug 17, 2023
1 parent 212da69 commit 0243a62
Show file tree
Hide file tree
Showing 87 changed files with 747 additions and 699 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ ic-cdk-timers = "0.2.0"
ic-stable-structures = "0.5.6"
ic-test-state-machine-client = "2.2.1"
rmp-serde = "1.1.1"
serde = "1.0.171"
serde = "1.0.173"
shared_utils = { path = "./src/lib/shared_utils" }
test_utils = { path = "./src/lib/test_utils" }
8 changes: 4 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ dfx-env.overrideAttrs (old: {
nativeBuildInputs = with pkgs; old.nativeBuildInputs ++
[ rustup pkg-config openssl protobuf cmake cachix killall jq coreutils bc python3Full ];

shellHook = ''
rustup toolchain install stable
rustup target add wasm32-unknown-unknown
'';
# shellHook = ''
# rustup toolchain install stable
# rustup target add wasm32-unknown-unknown
# '';
})
27 changes: 0 additions & 27 deletions hot_or_not.md → notes/commands.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
# Architecture

```mermaid
flowchart
UserClient[User Client Device]
UserIndex[(User Index)]
IndividualUserCanister[(Individual User <br>Canister)]
ContentIndex[(Content Index)]
GlobalConfiguration[(Global Configuration)]
DataBackup[(Data Backup)]
UserIndex -- 1 --> IndividualUserCanister
IndividualUserCanister -- n --> UserIndex
IndividualUserCanister -- sync new <br> posts --> ContentIndex
IndividualUserCanister -- backup before <br> upgrades --> DataBackup
UserClient -- get provisioned <br> individual canister --> UserIndex
UserClient -- get content --> ContentIndex
UserClient -- talk to own <br> and others' canisters --> IndividualUserCanister
```

# Commonly used dfx commands

## Try upgrading a canister to the latest wasm manually
Expand All @@ -44,9 +23,3 @@
`dfx canister --network=ic call aanaa-xaaaa-aaaah-aaeiq-cai burn "(record { canister_id= principal \"$(dfx identity get-wallet --network ic)\"; amount= (1000000000000:nat64)})"`

Burn XTC to cycles operation burns 2B cycles

## Next Items

- Remove any controller except itself
- Add additional known canisters for sns root and governance and ensure that canister upgrade parameters retain existing entries and only upsert new entries
- Add multiple upgrades at a time
45 changes: 45 additions & 0 deletions notes/hot_or_not.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Current Architecture

```mermaid
flowchart
UserClient[User Client Device]
UserIndex[(User Index)]
IndividualUserCanister[(Individual User <br>Canister)]
ContentIndex[(Content Index)]
GlobalConfiguration[(Global Configuration)]
DataBackup[(Data Backup)]
UserIndex -- 1 --> IndividualUserCanister
IndividualUserCanister -- n --> UserIndex
IndividualUserCanister -- sync new <br> posts --> ContentIndex
IndividualUserCanister -- backup before <br> upgrades --> DataBackup
UserClient -- get provisioned <br> individual canister --> UserIndex
UserClient -- get content --> ContentIndex
UserClient -- talk to own <br> and others' canisters --> IndividualUserCanister
```

## Upcoming Architecture

```mermaid
flowchart
PlatformOrchestrator[Platform Orchestrator]
CanisterRegistry[(Canister Registry)]
UserClient[User Client Device]
UserIndex[(User Index)]
IndividualUserCanister[(Individual User <br>Canister)]
ContentIndex[(Content Index)]
subgraph OrchestratorSubnet[Orchestrator Subnet]
PlatformOrchestrator <-- 1 --> CanisterRegistry
end
subgraph UserSubnet[User Subnet]
PlatformOrchestrator --> UserIndex
UserIndex -- 1 --> IndividualUserCanister
IndividualUserCanister -- n --> UserIndex
IndividualUserCanister <-- sync new <br> posts --> ContentIndex
UserClient -- get provisioned <br> individual canister --> UserIndex
UserClient -- get content --> IndividualUserCanister
UserClient -- talk to own <br> and others' canisters --> IndividualUserCanister
end
```
11 changes: 11 additions & 0 deletions notes/talking_points.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Canister side

- Short term - Adopt the ic-stable-structures to leverage stable memory for data storage. Should tentatively reduce our costs in half essentially cutting upgrade cost to near zero
- Short term - Implement a active canister reclamation solution that reclaims fleet canisters from idle users who've abandoned their accounts and reuses them for new signups. Archive existing users data to a archival solution and restore to a new canister on future activation. Should also significantly reduce costs, letting us reclaim 40-70% of our approximate fleet on a regular basis.
- Long term - Invest in running nodes and become node providers essentially being able to pay for cycles with IC earned, in a way hosting our app on our own hardware, IC providing the software stack
- Long term - Stake significant portions of the SNS DAO treasury into neurons and using the maturity from those neurons to pay for cycles.

# REDUCED CYCLE COSTS

- Sustained use discounts
- Subnet rentals with lower cycle costs per the entire subnet
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
profile = "default"
targets = [ "wasm32-unknown-unknown" ]
89 changes: 0 additions & 89 deletions scripts/canisters/local_sns_deploy/upgrade_all_canisters.sh

This file was deleted.

2 changes: 1 addition & 1 deletion sns
Submodule sns updated from a49bff to c1490e
4 changes: 2 additions & 2 deletions src/canister/configuration/src/api/canister_lifecycle/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn init_impl(init_args: ConfigurationInitArgs, data: &mut CanisterData) {
.iter()
.for_each(|(principal_belongs_to, principal_id)| {
data.known_principal_ids
.insert(principal_belongs_to.clone(), principal_id.clone());
.insert(principal_belongs_to.clone(), *principal_id);
});

data.signups_enabled = init_args.signups_enabled.unwrap_or(data.signups_enabled);
Expand Down Expand Up @@ -101,6 +101,6 @@ mod test {
.unwrap(),
&get_mock_canister_id_user_index()
);
assert_eq!(data.signups_enabled, true);
assert!(data.signups_enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ mod test {

#[test]
fn test_are_signups_enabled_impl() {
let mut canister_data = CanisterData::default();
let mut canister_data = CanisterData {
signups_enabled: true,
..Default::default()
};

canister_data.signups_enabled = true;
assert_eq!(are_signups_enabled_impl(&canister_data), true);
assert!(are_signups_enabled_impl(&canister_data));

canister_data.signups_enabled = false;
assert_eq!(are_signups_enabled_impl(&canister_data), false);
assert!(!are_signups_enabled_impl(&canister_data));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ mod test {
// super admin should be allowed to toggle
let result = toggle_signups_enabled_impl(admin_caller, &mut canister_data);
assert!(result.is_ok());
assert_eq!(canister_data.signups_enabled, true);
assert!(canister_data.signups_enabled);
let result = toggle_signups_enabled_impl(admin_caller, &mut canister_data);
assert!(result.is_ok());
assert_eq!(canister_data.signups_enabled, false);
assert!(!canister_data.signups_enabled);

// non super admin should not be allowed to toggle
let non_admin_caller = get_mock_user_alice_principal_id();
let result = toggle_signups_enabled_impl(non_admin_caller, &mut canister_data);
assert!(result.is_err());
assert_eq!(canister_data.signups_enabled, false);
assert!(!canister_data.signups_enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::CANISTER_DATA;
fn get_current_list_of_all_well_known_principal_values() -> Vec<(KnownPrincipalType, Principal)> {
CANISTER_DATA.with(|canister_data_ref_cell| {
let known_principal_ids = &canister_data_ref_cell.borrow().known_principal_ids;
get_current_list_of_all_well_known_principal_values_impl(&known_principal_ids)
get_current_list_of_all_well_known_principal_values_impl(known_principal_ids)
})
}

Expand All @@ -17,7 +17,7 @@ fn get_current_list_of_all_well_known_principal_values_impl(
) -> Vec<(KnownPrincipalType, Principal)> {
known_principal_ids
.iter()
.map(|(known_principal_type, principal)| (known_principal_type.clone(), principal.clone()))
.map(|(known_principal_type, principal)| (known_principal_type.clone(), *principal))
.collect()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn get_well_known_principal_value_impl(
canister_data
.known_principal_ids
.get(principal_type)
.map(|principal| principal.clone())
.copied()
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/canister/data_backup/src/api/canister_lifecycle/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn init_impl(init_args: DataBackupInitArgs, data: &mut HeapData) {
.iter()
.for_each(|(principal_belongs_to, principal_id)| {
data.known_principal_ids
.insert(principal_belongs_to.clone(), principal_id.clone());
.insert(principal_belongs_to.clone(), *principal_id);
});

init_args
Expand All @@ -27,7 +27,7 @@ fn init_impl(init_args: DataBackupInitArgs, data: &mut HeapData) {
.iter()
.for_each(|(principal, access_roles)| {
data.access_control_list
.insert(principal.clone(), access_roles.clone());
.insert(*principal, access_roles.clone());
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn receive_all_user_posts_from_individual_user_canister_impl(
existing_entry
.canister_data
.all_created_posts
.insert(post.id.clone(), post.clone());
.insert(post.id, post.clone());
});

canister_data.user_principal_id_to_all_user_data_map.insert(
Expand Down
Loading

0 comments on commit 0243a62

Please sign in to comment.