From 9e11734c5a7d5b854ea47689f66bce3081643cd6 Mon Sep 17 00:00:00 2001 From: Sudan Landge Date: Thu, 21 Dec 2023 20:21:09 +0000 Subject: [PATCH 1/2] doc(metrics): Make metrics related info easily accessible Present a list of metrics emitted by Firecracker. To make it easier to understand the metrics, provide links to the definition of each metrics. Signed-off-by: Sudan Landge --- docs/metrics.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/docs/metrics.md b/docs/metrics.md index 4a797ef6ee2..dbed6a590b1 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -77,3 +77,56 @@ Otherwise, if the path points to a normal file, you can simply do: ```shell script cat metrics.file ``` + +## Metrics emitted by Firecracker + +The metrics emitted by Firecracker are in JSON format. +Below are the keys present in each metrics json object emitted by Firecracker: + +``` +"api_server" +"balloon" +"block" +"deprecated_api" +"entropy" +"get_api_requests" +"i8042" +"latencies_us" +"logger" +"mmds" +"net" +"patch_api_requests" +"put_api_requests" +"rtc" +"seccomp" +"signals" +"uart" +"vcpu" +"vhost_user_block" +"vmm" +"vsock" +``` + +Below table explains where Firecracker metrics are defined : + +| Metrics key | Device | Additional comments | +|-------|-------|-------| +| balloon | [BalloonDeviceMetrics](../src/vmm/src/devices/virtio/balloon/metrics.rs) | Respresent metrics for the Balloon device.| +| block | [BlockDeviceMetrics](../src/vmm/src/devices/virtio/virtio_block/metrics.rs) | Respresent aggregate metrics for Virtio Block device.| +| block_{block_drive_id} | [BlockDeviceMetrics](../src/vmm/src/devices/virtio/virtio_block/metrics.rs) | Respresent Virtio Block device metrics for the endpoint `"/drives/{drive_id}"` e.g. `"block_rootfs":` represent metrics for the endpoint `"/drives/rootfs"`| +| i8042 | [I8042DeviceMetrics](../src/vmm/src/devices/legacy/i8042.rs) | Respresent Metrics specific to the i8042 device.| +| net | [NetDeviceMetrics](../src/vmm/src/devices/virtio/net/metrics.rs) | Respresent aggregate metrics for Virtio Net device.| +| net_{iface_id} | [NetDeviceMetrics](../src/vmm/src/devices/virtio/net/metrics.rs) | Respresent Virtio Net device metrics for the endpoint `"/network-interfaces/{iface_id}"` e.g. `net_eth0` represent metrics for the endpoint `"/network-interfaces/eth0"`| +| rtc | [RTCDeviceMetrics](../src/vmm/src/devices/legacy/serial.rs) | Respresent Metrics specific to the RTC device. `Note`: this is emitted only on `aarch64`.| +| uart | [SerialDeviceMetrics](../src/vmm/src/devices/legacy/serial.rs) | Respresent Metrics specific to the serial device.| +| vhost_user_{dev}_{dev_id} | [VhostUserDeviceMetrics](../src/vmm/src/devices/virtio/vhost_user_metrics.rs) | Respresent Vhost-user device metrics for the device `dev` and device id `dev_id`. e.g. `"vhost_user_block_rootfs":` represent metrics for vhost-user block device having the endpoint `"/drives/rootfs"`| +| vsock | [VsockDeviceMetrics](../src/vmm/src/devices/virtio/vsock/metrics.rs) | Respresent Metrics specific to the vsock device.| +| entropy | [EntropyDeviceMetrics](../src/vmm/src/devices/virtio/rng/metrics.rs) | Respresent Metrics specific to the entropy device.| +| "api_server"
"deprecated_api"
"get_api_requests"
"latencies_us"
"logger"
"mmds"
"patch_api_requests"
"put_api_requests"
"seccomp"
"signals"
"vcpu"
"vmm" | [metrics.rs](../src/vmm/src/logger/metrics.rs) | Rest of the metrics are defined in the same file metrics.rs.| + +Note: +Firecracker emits all the above metrics regardless of the presense of +that component i.e. even if `vsock` device is not attached to the +Microvm, Firecracker will still emit the Vsock metrics with key as +`vsock` and value of all metrics defined in `VsockDeviceMetrics` as +`0`. From 2913dac5ed0d23a62070de40d902fbd24b68007f Mon Sep 17 00:00:00 2001 From: Sudan Landge Date: Fri, 22 Dec 2023 11:48:51 +0000 Subject: [PATCH 2/2] fix(metrics): Add more validation to check missing metrics validate_missing_metrics is actually just validating the jsonschema library and not any Firecracker property itself which is fine since it is kind of a reassurance that it is working as we expect it to. However, atm it only checks if jsonschema throws an exception on the missing metrics and it should in fact also check if there was an exception raised at all. If for some reason jsonschema doesn't raise an exception then the test passes and the purpose of this function is defeated. So, raise exception if jsonschema doesn't raise one. Signed-off-by: Sudan Landge --- tests/host_tools/fcmetrics.py | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/tests/host_tools/fcmetrics.py b/tests/host_tools/fcmetrics.py index 8a5ea4d8a47..44471d0b680 100644 --- a/tests/host_tools/fcmetrics.py +++ b/tests/host_tools/fcmetrics.py @@ -14,6 +14,7 @@ from threading import Thread import jsonschema +import pytest def validate_fc_metrics(metrics): @@ -283,38 +284,28 @@ def validate_missing_metrics(metrics): # remove some metrics and confirm that fields and not just top level metrics # are validated. temp_pop_metrics = metrics["api_server"].pop("process_startup_time_us") - try: + with pytest.raises( + jsonschema.ValidationError, + match="'process_startup_time_us' is a required property", + ): jsonschema.validate(instance=metrics, schema=firecracker_metrics_schema) - except jsonschema.exceptions.ValidationError as error: - if ( - error.message.strip() - == "'process_startup_time_us' is a required property" - ): - pass - else: - raise error metrics["api_server"]["process_startup_time_us"] = temp_pop_metrics if platform.machine() == "aarch64": temp_pop_metrics = metrics["rtc"].pop("error_count") - try: + with pytest.raises( + jsonschema.ValidationError, match="'error_count' is a required property" + ): jsonschema.validate(instance=metrics, schema=firecracker_metrics_schema) - except jsonschema.exceptions.ValidationError as error: - if error.message.strip() == "'error_count' is a required property": - pass - else: - raise error metrics["rtc"]["error_count"] = temp_pop_metrics for vhost_user_dev in vhost_user_devices: temp_pop_metrics = metrics[vhost_user_dev].pop("activate_time_us") - try: + with pytest.raises( + jsonschema.ValidationError, + match="'activate_time_us' is a required property", + ): jsonschema.validate(instance=metrics, schema=firecracker_metrics_schema) - except jsonschema.exceptions.ValidationError as error: - if error.message.strip() == "'activate_time_us' is a required property": - pass - else: - raise error metrics[vhost_user_dev]["activate_time_us"] = temp_pop_metrics validate_missing_metrics(metrics)