Skip to content
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

wip: switch to invoking yardstick validate from within grype-db python #371

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions config/grype-db-manager/include.d/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ db:
gate:
# float between 0 and 1, the maximum allowable difference below the OSS F1 score before the gate fails (default 0,
# meaning the test F1 score must be equal to or greater than the OSS F1 score to pass the gate)
f1-score-threshold: 0.15
max_f1_regression: 0.15

# float between 0 and 100, the maximum % of unlabeled matches for a scan result before the gate fails (default 10%,
# meaning the test scan must have less than 10% unlabeled matches to pass the gate)
# TODO: this should be at 25.0 after we sunset v1 and v2 schemas
unlabeled-matches-threshold: 50.0
# TODO: this should be at 25 after we sunset v1 and v2 schemas
max_unlabeled_percent: 50

# integer, the maximum allowable introduced FNs by the test scan (but found by the OSS scan) before the gate fails
# (default 0, meaning the test scan must have the same or fewer FNs than the OSS scan to pass the gate)
introduced-fns-threshold: 10
max_new_false_negatives: 10
max_year: 2021

# these are the set of images we will capture grype scans for using an existing published DB and a newly build DB.
# The assumption is that they should perform similarly or the new DB should perform better. We do allow for the new
Expand Down
3 changes: 2 additions & 1 deletion manager/src/grype_db_manager/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import yaml
from dataclass_wizard import asdict, fromdict
from yamlinclude import YamlIncludeConstructor
from yardstick.validate import GateConfig

from grype_db_manager import db, s3utils

Expand Down Expand Up @@ -50,7 +51,7 @@ class ValidateDB:
images: list[str] = field(default_factory=list)
grype: Grype = field(default_factory=Grype)
default_max_year: int = 2021
gate: db.validation.GateConfig = field(default_factory=db.validation.GateConfig)
gate: GateConfig = field(default_factory=GateConfig)

def __post_init__(self):
# flatten elements in images (in case yaml anchors are used)
Expand Down
13 changes: 10 additions & 3 deletions manager/src/grype_db_manager/cli/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,22 @@ def validate_db(
},
)

gates = db.validate(
db.capture_results(
cfg=yardstick_cfg,
result_set=result_set,
db_uuid=db_uuid,
verbosity=verbosity,
result_set=result_set,
recapture=recapture,
root_dir=cfg.data.root,
)

gates = yardstick.validate.validate_result_set(
gate_config=cfg.validate.db.gate,
result_set=result_set,
images=[],
always_run_label_comparison=False,
verbosity=verbosity,
)

failure = not all(gate.passed() for gate in gates)
if failure:
click.echo(f"{Format.BOLD}{Format.FAIL}Validation failed{Format.RESET}")
Expand Down
3 changes: 2 additions & 1 deletion manager/src/grype_db_manager/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from . import listing, metadata, schema
from .listing import Listing
from .metadata import Metadata
from .validation import validate
from .validation import capture_results, validate

__all__ = [
"Listing",
Expand All @@ -10,4 +10,5 @@
"metadata",
"validate",
"schema",
"capture_results",
]
11 changes: 6 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ zstandard = ">=0.21.0, <1"
colorlog = "^6.7.0"
mergedeep = "^1.3.4"
pyyaml = ">=5.0.1, <7"
yardstick = {git = "https://github.com/anchore/yardstick", rev = "8ef84656c6618292110c47fbb8805d78fc7b235d"}
#yardstick = {path = "../yardstick", develop = true}
yardstick = {git = "https://github.com/anchore/yardstick", rev = "feat-validate-subcommand"}
# yardstick = {path = "../yardstick", develop = true}
colr = "^0.9.1"
pyyaml-include = "^1.3.1"
python-magic = "^0.4.27"
Expand Down
Loading