Skip to content

Commit ee6277a

Browse files
github-actions[bot]matheushent
andauthoredMar 7, 2025··
fix(agent): prevent int64 overflow from values fecthed from InfluxDB. (#740) (#741)
This commit modifies the `fetch_influx_data` function to return 0 in the measurement value and the original value is bigger than 2^63 - 1. This prevents an error in the API where the value is bigger than int64, causing the metrics to not be stored in the database. (cherry picked from commit a921df5) Co-authored-by: Matheus Tosta <[email protected]>
1 parent 469fbfe commit ee6277a

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
 

‎changes/agent/740.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adjusted the `fetch_influx_data` function to return a measurement value 0 when the original value overflows the maximum int64 value.

‎jobbergate-agent/jobbergate_agent/jobbergate/update.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async def fetch_influx_data(
124124
job=point["job"],
125125
step=point["step"],
126126
task=point["task"],
127-
value=point["value"],
127+
value=point["value"] if point["value"] < 2**63 - 1 else 0, # prevent int64 overflow
128128
measurement=measurement,
129129
)
130130
for point in result.get_points()

‎jobbergate-agent/tests/jobbergate/test_update.py

+51
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,57 @@ async def test_fetch_influx_data__success_with_all_set(mocked_influxdb_client: m
434434
mocked_influxdb_client.query.assert_called_once_with(query, bind_params=params, epoch="s")
435435

436436

437+
@pytest.mark.asyncio
438+
@mock.patch("jobbergate_agent.jobbergate.update.influxdb_client")
439+
async def test_fetch_influx_data__data_point_overflow(mocked_influxdb_client: mock.MagicMock):
440+
"""
441+
Test that the ``fetch_influx_data()`` function prevents a overflow
442+
when the data point value cannot be stored in disk as an int64.
443+
"""
444+
time = random.randint(0, 1000) # noqa: F811
445+
host = "test-host"
446+
step = random.randint(0, 1000)
447+
task = random.randint(0, 1000)
448+
job = random.randint(0, 1000)
449+
measurement_value = 2**63 - 1 + random.uniform(1, 1000)
450+
measurement = random.choice(get_args(INFLUXDB_MEASUREMENT))
451+
452+
mocked_influxdb_client.query.return_value.get_points.return_value = [
453+
dict(
454+
time=time,
455+
host=host,
456+
job=job,
457+
step=step,
458+
task=task,
459+
value=measurement_value,
460+
)
461+
]
462+
463+
query = dedent(f"""
464+
SELECT * FROM {measurement} WHERE time > $time AND host = $host AND step = $step AND task = $task AND job = $job
465+
""")
466+
params = dict(time=time, host=host, step=str(step), task=str(task), job=str(job))
467+
468+
result = await fetch_influx_data(
469+
time=time,
470+
host=host,
471+
step=step,
472+
task=task,
473+
job=job,
474+
measurement=measurement,
475+
)
476+
477+
assert len(result) == 1
478+
assert result[0]["time"] == time
479+
assert result[0]["host"] == host
480+
assert result[0]["job"] == job
481+
assert result[0]["step"] == step
482+
assert result[0]["task"] == task
483+
assert result[0]["value"] == 0
484+
assert result[0]["measurement"] == measurement
485+
mocked_influxdb_client.query.assert_called_once_with(query, bind_params=params, epoch="s")
486+
487+
437488
@pytest.mark.asyncio
438489
@mock.patch("jobbergate_agent.jobbergate.update.influxdb_client")
439490
async def test_fetch_influx_data__success_with_all_None(mocked_influxdb_client: mock.MagicMock):

0 commit comments

Comments
 (0)
Please sign in to comment.