Skip to content

Replace hyperlight-specific metrics with metrics crate #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
712 changes: 707 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ clippy target=default-target: (check target)
test target=default-target features="": (test-inprocess target) (test-seccomp target features)
cargo test {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }}
cargo test test_metrics {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored
cargo test test_gather_metrics {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -- --ignored

test-inprocess target=default-target:
{{ if target == "debug" { "cargo test --features='inprocess'; cargo test test_metrics --features='inprocess' -- --ignored; cargo test test_gather_metrics --features='inprocess' -- --ignored" } else {"echo 'inprocess tests are not run for release builds'" } }}
Expand All @@ -83,4 +82,4 @@ bench target=default-target features="":
bench-download os hypervisor tag="":
gh release download {{ tag }} -D ./src/hyperlight_wasm/target/ -p benchmarks_{{ os }}_{{ hypervisor }}.tar.gz
mkdir {{ mkdir-arg }} ./src/hyperlight_wasm/target/criterion
tar -zxvf ./src/hyperlight_wasm/target/benchmarks_{{ os }}_{{ hypervisor }}.tar.gz -C ./src/hyperlight_wasm/target/criterion/ --strip-components=1
tar -zxvf ./src/hyperlight_wasm/target/benchmarks_{{ os }}_{{ hypervisor }}.tar.gz -C ./src/hyperlight_wasm/target/criterion/ --strip-components=1
45 changes: 17 additions & 28 deletions docs/observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,31 @@

hyperlight-wasm provides the following observability features:

* [Metrics](#metrics) metrics are provided using Prometheus.
* [Metrics](#metrics) metrics are provided using `metrics` crate.

## Metrics

Hyperlight-wasm provides metrics using Prometheus. The metrics are registered using either the [default_registry](https://docs.rs/prometheus/latest/prometheus/fn.default_registry.html) or a registry instance provided by the host application.

To provide a registry to hyperlight_wasm, use the `set_metrics_registry` function and pass a reference to a registry with `static` lifetime:
The following metrics are provided and are enabled by default:

```rust
use hyperlight_wasm::set_metrics_registry;
use prometheus::Registry;
use lazy_static::lazy_static;
* `active_proto_wasm_sandboxes` - A gauge indicating the number of currently active proto wasm sandboxes
* `active_wasm_sandboxes` - A gauge indicating the number of currently active wasm sandboxes
* `active_loaded_wasm_sandboxes` - A gauge indicating the number of currently loaded wasm sandboxes
* `proto_wasm_sandboxes_total` - A counter indicating the total number of proto wasm sandboxes created during the lifetime of the process
* `wasm_sandboxes_total` - A counter indicating the total number of wasm sandboxes created during the lifetime of the process
* `loaded_wasm_sandboxes_total` - A counter indicating the total number of loaded wasm sandboxes created during the lifetime of the process
* `sandbox_loads_total` - A counter indicating how many times a wasm sandbox has been loaded into a loaded wasm sandbox during the lifetime of the process
* `sandbox_unloads_total` - A counter indicating how many times a loaded wasm sandbox has been unloaded into a wasm sandbox during the lifetime of the process

lazy_static! {
static ref REGISTRY: Registry = Registry::new();
}

set_metrics_registry(&REGISTRY);
```
In addition, regular Hyperlight provides the following metrics:

The following metrics are provided and are enabled by default:
* `guest_errors_total` - A counter indicating how many times a guest error has occurred
* `guest_cancellations_total` - The number of times guest execution has timed out

If cargo feature `function_call_metrics` is enabled:

* `hyperlight_guest_error_count` - a vector of counters that tracks the number of guest errors by code and message.
* `hyperlight_number_of_cancelled_guest_execution` - a counter that tracks the number of guest executions that have been cancelled because the execution time exceeded the time allowed.
* `current_number_of_wasm_sandboxes` - a gauge that tracks the current number of wasm sandboxes in this process.
* `current_number_of_loaded_wasm_sandboxes` - a gauge that tracks the current number of loaded wasm sandboxes in this process.
* `number_of_unloads_of_loaded_wasm_sandboxes` - a counter that tracks the number of times that unload_module has been called on a LoadedWasmSandbox.
* `number_of_loads_of_wasm_sandboxes` - a counter that tracks the number of times that load_module has been called on a WasmSandbox.
* `current_number_of_proto_wasm_sandboxes` - a gauge that tracks the current number of proto wasm sandboxes in this process.
* `total_number_of_wasm_sandboxes` - a counter that tracks the total number of wasm sandboxes that have been created by this process.
* `total_number_of_loaded_wasm_sandboxes` - a counter that tracks the total number of loaded wasm sandboxes that have been created by this process.
* `total_number_of_proto_wasm_sandboxes` - a counter that tracks the total number of proto wasm sandboxes that have been created by this process.

The following metrics are provided and are enabled by default using the feature `function_call_metrics` but can be disabled:

* `hyperlight_guest_function_call_duration_microseconds` - a vector of histograms that tracks the execution time of guest functions in microseconds by function name. The histogram also tracks the number of calls to each function.
* `hyperlight_host_function_calls_duration_microseconds` - a vector of histograms that tracks the execution time of host functions in microseconds by function name. The histogram also tracks the number of calls to each function.
* `guest_call_duration_seconds` - Histogram for the execution time of guest function calls
* `host_call_duration_seconds` - Histogram for the execution time of host function calls

There is an example of how to gather metrics in the [examples/metrics](../src/hyperlight_wasm/examples/metrics) directory.
10 changes: 4 additions & 6 deletions src/hyperlight_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,23 @@ test = true
hyperlight-host = { workspace = true }
libc = { version = "0.2.172" }
once_cell = "1.21.3"
strum = "0.27"
tracing = "0.1.27"
log = "0.4.27"
cfg-if = { version = "1" }
metrics = "0.24.2"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.61", features = [
"Win32_System_Threading",
] }
windows = { version = "0.61", features = ["Win32_System_Threading"] }
page_size = "0.6.0"

[dev-dependencies]
examples_common = { path = "../examples_common" }
criterion = { version = "0.5.1", features = ["html_reports"] }
lazy_static = "1.4.0"
prometheus = "0.13.3"
crossbeam-queue = "0.3"
blake3 = "1.8"
toml = "0.8.19"
metrics-util = "0.19.1"
metrics-exporter-prometheus = "0.17"

[build-dependencies]
chrono = "0.4"
Expand Down
Loading
Loading