Skip to content

Don't collect Prometheus metrics on container-based backends #2605

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
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
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ addopts =
--allow-unix-socket
markers =
shim_version
dockerized
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ async def _collect_jobs_metrics(job_models: list[JobModel], collected_at: dateti


async def _collect_job_metrics(job_model: JobModel) -> Optional[str]:
ssh_private_keys = get_instance_ssh_private_keys(get_or_error(job_model.instance))
jpd = get_job_provisioning_data(job_model)
jrd = get_job_runtime_data(job_model)
if jpd is None:
return None
if not jpd.dockerized:
# Container-based backend, no shim
return None
ssh_private_keys = get_instance_ssh_private_keys(get_or_error(job_model.instance))
jrd = get_job_runtime_data(job_model)
try:
res = await run_async(
_pull_job_metrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@
@pytest.mark.usefixtures("test_db", "image_config_mock")
class TestCollectPrometheusMetrics:
@pytest_asyncio.fixture
async def job(self, session: AsyncSession) -> JobModel:
async def job(self, request: pytest.FixtureRequest, session: AsyncSession) -> JobModel:
dockerized: bool
marker = request.node.get_closest_marker("dockerized")
if marker is None:
dockerized = True
else:
dockerized = marker.args[0]
user = await create_user(session=session, global_role=GlobalRole.USER)
project = await create_project(session=session, owner=user)
await add_project_member(
Expand All @@ -59,7 +65,7 @@ async def job(self, session: AsyncSession) -> JobModel:
session=session,
run=run,
status=JobStatus.RUNNING,
job_provisioning_data=get_job_provisioning_data(),
job_provisioning_data=get_job_provisioning_data(dockerized=dockerized),
instance_assigned=True,
instance=instance,
)
Expand Down Expand Up @@ -142,6 +148,21 @@ async def test_skips_recently_updated(
assert metrics.text == "# prom old response"
assert metrics.collected_at == datetime(2023, 1, 2, 3, 5, 15)

@freeze_time(datetime(2023, 1, 2, 3, 5, 20, tzinfo=timezone.utc))
@pytest.mark.dockerized(False)
async def test_skips_non_dockerized_jobs(
self, session: AsyncSession, job: JobModel, ssh_tunnel_mock: Mock, shim_client_mock: Mock
):
await collect_prometheus_metrics()

ssh_tunnel_mock.assert_not_called()
shim_client_mock.get_task_metrics.assert_not_called()
res = await session.execute(
select(JobPrometheusMetrics).where(JobPrometheusMetrics.job_id == job.id)
)
metrics = res.scalar_one_or_none()
assert metrics is None


@pytest.mark.asyncio
@pytest.mark.parametrize("test_db", ["sqlite", "postgres"], indirect=True)
Expand Down
Loading