feat: Support loading environment variables from a file#178
Conversation
|
|
There was a problem hiding this comment.
Pull request overview
Adds support in canbench for preloading canister environment variables from a user-provided file, enabling benchmarking of canisters that depend on ic_cdk::api::env_var_value(...) without additional instrumentation.
Changes:
- Extends
canbench.ymlparsing to accept anenv_vars.filepath and threads it through benchmark execution. - Creates canisters in PocketIC with
CanisterSettings.environment_variablespopulated from the file. - Adds new test canisters + CLI tests covering success, missing file, and invalid file cases, plus updates crate docs.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/environment_variables/src/main.rs | New test canister that reads env vars at init and asserts expected values in a benchmark. |
| tests/environment_variables/environment_variables.csv | Sample env var data file used by the test canister. |
| tests/environment_variables/canbench.yml | Test config exercising env_vars.file. |
| tests/environment_variables_invalid/src/main.rs | Minimal canister for invalid env var file test. |
| tests/environment_variables_invalid/environment_variables_invalid.csv | Invalid env var file fixture (no comma separator). |
| tests/environment_variables_invalid/canbench.yml | Test config pointing at invalid env var file. |
| tests/environment_variables_file_does_not_exist/src/main.rs | Minimal canister for missing env var file test. |
| tests/environment_variables_file_does_not_exist/canbench.yml | Test config pointing at a non-existent env var file. |
| tests/Cargo.toml | Registers the new test canister binaries. |
| Cargo.lock | Locks new dependency additions. |
| canbench-rs/src/lib.rs | Documents environment-variable file support in the crate-level docs. |
| canbench-bin/tests/tests.rs | Adds integration tests for env var loading / error output. |
| canbench-bin/src/main.rs | Adds env_vars to config parsing and passes the path into run_benchmarks. |
| canbench-bin/src/lib.rs | Implements env var file parsing and applies it via CanisterSettings during canister creation. |
| canbench-bin/Cargo.toml | Adds ic-management-canister-types dependency for EnvironmentVariable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com>
Review dismissed by automation script.
Co-authored-by: mraszyk <31483726+mraszyk@users.noreply.github.com>
|
@mraszyk Feel free to merge when ready. |
Add support to load environment variables from a file.
Some canisters might expect that certain environment variables are set when calling certain endpoints, so with this change we make it easier to have such canisters be benchmarked without the need to disable any environment variable related logic and write benchmarks with minimal code instrumentation as usual.
The idea is very similar to how stable memory can be instantiated from a file, essentially exposing another option in
canbench.ymlto support environment variables in a similar fashion. The format of the file is CSV which feels natural for a list of key, value pairs like environment variables.