UNCLASSIFIED

Commit 8b2b761e authored by Kenneth Maguire's avatar Kenneth Maguire
Browse files

Merge branch 'minor-metrics-update' into 'development'

Minor metrics update

See merge request !62
parents 64ec5cd1 d976fdf7
Pipeline #757226 passed with stages
in 2 minutes and 20 seconds
......@@ -20,7 +20,7 @@ black:
- master
script:
- export PATH="${PATH}:$HOME/.local/bin"
- pip install --user git+git://github.com/psf/black
- pip install --user black
- black --check --diff --color -t py39 ./
pylama:
......
......@@ -10,16 +10,18 @@ from trigger.generate import metrics # noqa E402
class MockProject:
def __init__(self, name):
self.name = name
def __init__(self, path_with_namespace, id, web_url):
self.path_with_namespace = path_with_namespace
self.id = id
self.web_url = web_url
class MockIBCP:
def __init__(self, name):
self.project = MockProject(name)
def __init__(self, name, id, web_url):
self.project = MockProject(name, id, web_url)
def pipeline_attributes(self):
return {"attributes": {"name": self.project.name}}
return {"attributes": {"name": self.project.path_with_namespace}}
def pipeline_job_attributes(self):
return [
......@@ -29,7 +31,7 @@ class MockIBCP:
]
def dict(self):
return {"name": self.project.name}
return {"name": self.project.path_with_namespace}
@pytest.fixture
......@@ -42,8 +44,12 @@ def mock_b64_encoded_metrics_keys():
@pytest.fixture
def mock_projects():
mock_project_names = ["test1", "test2", "test3"]
return [MockIBCP(proj_name) for proj_name in mock_project_names]
mock_project_params = [
("dsop/example/test1", "1", "https://test1"),
("dsop/example/test2", "2", "https://test2"),
("dsop/example/test3", "3", "https://test3"),
]
return [MockIBCP(obj[0], obj[1], obj[2]) for obj in mock_project_params]
@pytest.fixture
......@@ -92,9 +98,18 @@ def test_project_metrics(mock_projects):
mock_pl_keys = ["name"]
mock_job_keys = ["name"]
proj_metrics = metrics._project_metrics(mock_projects, mock_pl_keys, mock_job_keys)
assert list(proj_metrics.keys()) == ["test1", "test2", "test3"]
assert list(proj_metrics["test1"].keys()) == ["pipeline_metrics", "job_metrics"]
assert list(proj_metrics["test1"]["job_metrics"].keys()) == [
assert list(proj_metrics.keys()) == [
"dsop/example/test1",
"dsop/example/test2",
"dsop/example/test3",
]
assert list(proj_metrics["dsop/example/test1"].keys()) == [
"id",
"web_url",
"pipeline_metrics",
"job_metrics",
]
assert list(proj_metrics["dsop/example/test1"]["job_metrics"].keys()) == [
"check-cves",
"csv-output",
"anchore-scan",
......
......@@ -170,12 +170,12 @@ class IBContainerProject:
def __str__(self):
if self.pipeline is None:
return f"project: {self.project.name}, pipeline: {self.pipeline}"
return f"project: {self.project.path_with_namespace}, pipeline: {self.pipeline}"
else:
return f"project: {self.project.name}, pipeline: {self.pipeline.id}"
return f"project: {self.project.path_with_namespace}, pipeline: {self.pipeline.id}"
def __repr__(self):
if self.pipeline is None:
return f"(project: {self.project.name}, pipeline: {self.pipeline})"
return f"(project: {self.project.path_with_namespace}, pipeline: {self.pipeline})"
else:
return f"(project: {self.project.name}, pipeline: {self.pipeline.id})"
return f"(project: {self.project.path_with_namespace}, pipeline: {self.pipeline.id})"
......@@ -33,14 +33,16 @@ def _project_metrics(projects, pl_metrics_keys, job_metrics_keys):
# pipeline and job metrics
# need to check if pipeline is mock
for pl in projects:
project_metrics[pl.project.name] = {}
project_metrics[pl.project.name]["pipeline_metrics"] = {
ns_path = pl.project.path_with_namespace
project_metrics[ns_path] = {}
project_metrics[ns_path]["id"] = pl.project.id
project_metrics[ns_path]["web_url"] = pl.project.web_url
project_metrics[ns_path]["pipeline_metrics"] = {
k: v for k, v in pl.pipeline_attributes().items() if k in pl_metrics_keys
}
project_metrics[pl.project.name]["job_metrics"] = {}
project_metrics[ns_path]["job_metrics"] = {}
for job in pl.pipeline_job_attributes():
project_metrics[pl.project.name]["job_metrics"][job["name"]] = {
project_metrics[ns_path]["job_metrics"][job["name"]] = {
k: v for k, v in job["attributes"].items() if k in job_metrics_keys
}
log.debug(project_metrics)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment