Skip to content

Commit 85363b9

Browse files
Merge pull request #1209 from dfinity/jessiemongeon1-patch-40
add: Deploy to ICP Ninja + standardize README
2 parents 407dec9 + 7fff30c commit 85363b9

File tree

1 file changed

+12
-61
lines changed

1 file changed

+12
-61
lines changed

rust/query_stats/README.md

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Query statistics
22

3-
This example shows to work with the query stats feature.
4-
5-
## Architecture
6-
7-
The example consists of a single canister called `query_stats`.
8-
It exports the following candid interface:
3+
This example shows to work with the query stats feature. It consists of a single canister called `query_stats`. It exports the following candid interface:
94

105
```candid
116
service : {
@@ -15,70 +10,26 @@ service : {
1510
1611
```
1712

18-
The `load` function just returns a timestamp.
19-
It just exists such that there is a query endpoint to call.
20-
The `get_query_stats` is the function that queries the status endpoint and returns the collected query statistics.
21-
22-
## Prerequisites
23-
24-
This example requires an installation of:
25-
- [x] Install the [IC SDK](https://internetcomputer.org/docs/current/developer-docs/getting-started/install).
26-
- [x] Clone the example dapp project: `git clone https://github.com/dfinity/examples`
27-
28-
29-
## Step 1: Setup project environment
13+
The `load` function just returns a timestamp. It just exists such that there is a query endpoint to call. The method `get_query_stats` queries the status endpoint and returns the collected query statistics.
3014

31-
Navigate into the folder containing the project's files and start a local instance of the replica with the command:
15+
## Deploying from ICP Ninja
3216

33-
```sh
34-
cd examples/rust/query_stats
35-
dfx start --clean
36-
```
17+
[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/query_stats)
3718

38-
## Step 2: Compile and deploy `query_stats` canister
19+
## Build and deploy from the command-line
3920

40-
```sh
41-
dfx deploy
42-
```
21+
### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install)
4322

44-
## Step 3: Call the canister's load function a few times to generate query traffic
23+
### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/)
4524

46-
```
47-
dfx canister call query_stats load
48-
```
25+
### 3. Navigate into the project's directory.
4926

50-
## Step 4: Observe the following result
27+
### 4. Deploy the project to your local environment:
5128

5229
```
53-
dfx canister call query_stats get_query_stats
30+
dfx start --background --clean && dfx deploy
5431
```
5532

56-
## Step 5: After a while, the values should become populated
57-
58-
```
59-
"Number of calls: 19 - Number of instructions 414_083 - Request payload bytes: 114 - Response payload bytes: 270"
60-
```
61-
62-
Alternatively, you can use the candid interface to make those calls.
63-
64-
### Troubleshooting
65-
66-
On the local `dfx` replica, the aggregation epoch is set to 60 seconds.
67-
So calling the load function a couple of times should result in values showing up a couple minutes later.
68-
69-
On mainnet, the aggregation epoch is 10 minutes, thus it will up to half an hour before the values appear on mainnet.
70-
71-
### Possible next steps
72-
73-
Query statistics are simple counters that increase.
74-
Their raw values are not that useful, you may want to implement some sort of metering system.
75-
76-
One way to go from here is to get the query stats in a regular interval using a timer and compare to the last values, calculating rates.
77-
78-
## Resources
79-
80-
- [ic-cdk](https://docs.rs/ic-cdk/latest/ic_cdk/).
81-
82-
## Security considerations and security best practices
33+
## Security considerations and best practices
8334

84-
If you base your application on this example, we recommend you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/current/references/security/) for developing on the Internet Computer. This example may not implement all the best practices.
35+
If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices.

0 commit comments

Comments
 (0)