Skip to content

Commit

Permalink
fix(metrics): Add more validation to check missing metrics
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Sudan Landge authored and wearyzen committed Dec 27, 2023
1 parent 5c126f7 commit 1afbaca
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions tests/host_tools/fcmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from threading import Thread

import jsonschema
import pytest


def validate_fc_metrics(metrics):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1afbaca

Please sign in to comment.