Skip to content

Commit 0f468e0

Browse files
changed type of costs column to float64
added testing of usage metrics and costs
1 parent a6b3ae7 commit 0f468e0

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

openeo/extra/job_management.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def start_job(
207207
"cpu": _ColumnProperties(dtype="str"),
208208
"memory": _ColumnProperties(dtype="str"),
209209
"duration": _ColumnProperties(dtype="str"),
210-
"costs": _ColumnProperties(dtype="str"),
210+
"costs": _ColumnProperties(dtype="float64"),
211211
}
212212

213213
def __init__(

openeo/rest/_testing.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,22 @@ def _handle_get_job(self, request, context):
225225
self.batch_jobs[job_id]["status"] = self._get_job_status(
226226
job_id=job_id, current_status=self.batch_jobs[job_id]["status"]
227227
)
228-
return {
228+
result = {
229229
# TODO: add some more required fields like "process" and "created"?
230230
"id": job_id,
231231
"status": self.batch_jobs[job_id]["status"],
232232
}
233+
if self.batch_jobs[job_id]["status"] == "finished": # HACK some realistic values for a small job
234+
result["costs"] = 4
235+
result["usage"] = {
236+
"cpu": {"unit": "cpu-seconds", "value": 30.0},
237+
"duration": {"unit": "seconds", "value": 55},
238+
"input_pixel": {"unit": "mega-pixel", "value": 6.0},
239+
"max_executor_memory": {"unit": "gb", "value": 0.5},
240+
"memory": {"unit": "mb-seconds", "value": 150000.0},
241+
"network_received": {"unit": "b", "value": 200000},
242+
}
243+
return result
233244

234245
def _handle_get_job_results(self, request, context):
235246
"""Handler of `GET /job/{job_id}/results` (list batch job results)."""

tests/extra/test_job_management.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ def test_basic(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock):
174174
("job-2022", "finished", "foo"),
175175
]
176176

177+
assert not pd.read_csv(job_db_path)[["cpu", "memory", "duration", "costs"]].isnull().any().any()
178+
177179
# Check downloaded results and metadata.
178180
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {
179181
Path(f"job_{job_id}") / filename
@@ -204,6 +206,7 @@ def test_db_class(self, tmp_path, job_manager, job_manager_root_dir, sleep_mock,
204206
assert len(result) == 5
205207
assert set(result.status) == {"finished"}
206208
assert set(result.backend_name) == {"foo", "bar"}
209+
assert not result[["cpu", "memory", "duration", "costs"]].isnull().any().any()
207210

208211
@pytest.mark.parametrize(
209212
["filename", "expected_db_class"],
@@ -262,6 +265,8 @@ def test_basic_threading(self, tmp_path, job_manager, job_manager_root_dir, slee
262265
("job-2022", "finished", "foo"),
263266
]
264267

268+
assert not pd.read_csv(job_db_path)[["cpu", "memory", "duration", "costs"]].isnull().any().any()
269+
265270
# Check downloaded results and metadata.
266271
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {
267272
Path(f"job_{job_id}") / filename
@@ -334,13 +339,15 @@ def start_worker_thread():
334339
)
335340

336341
# Also check that we got sensible end results in the job db.
337-
assert [(r.id, r.status, r.backend_name) for r in pd.read_csv(job_db_path).itertuples()] == [
342+
result = pd.read_csv(job_db_path)
343+
assert [(r.id, r.status, r.backend_name) for r in result.itertuples()] == [
338344
("job-2018", "finished", "foo"),
339345
("job-2019", "finished", "foo"),
340346
("job-2020", "finished", "bar"),
341347
("job-2021", "finished", "bar"),
342348
("job-2022", "error", "foo"),
343349
]
350+
assert not result[result["status"] == "finished"][["cpu", "memory", "duration", "costs"]].isnull().any().any()
344351

345352
# Check downloaded results and metadata.
346353
assert set(p.relative_to(job_manager_root_dir) for p in job_manager_root_dir.glob("**/*.*")) == {

0 commit comments

Comments
 (0)