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

DB: warn and truncate on overly-long task event messages. #300

Merged
merged 1 commit into from
Mar 18, 2024
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
18 changes: 17 additions & 1 deletion coriolis/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,18 @@ def _get_progress_update(context, task_id, index):
def add_task_progress_update(
context, task_id, message, initial_step=0, total_steps=0):
task_progress_update = models.TaskProgressUpdate()
task_progress_update.id = str(uuid.uuid4())
task_event_id = str(uuid.uuid4())
task_progress_update.id = task_event_id
task_progress_update.task_id = task_id
task_progress_update.current_step = initial_step
task_progress_update.total_steps = total_steps
max_msg_len = models.MAX_EVENT_MESSAGE_LENGHT
if len(message) > max_msg_len:
LOG.warn(
f"Progress message for task '{task_id}' with ID '{task_event_id}'"
f"is too long. Truncating before insertion. "
f"Original message was: '{message}'")
message = f"{message[:max_msg_len-len('...')]}..."
task_progress_update.message = message

task_progress_update.index = 0
Expand All @@ -899,6 +907,14 @@ def update_task_progress_update(
if new_total_steps is not None:
task_progress_update.total_steps = new_total_steps
if new_message is not None:
max_msg_len = models.MAX_EVENT_MESSAGE_LENGHT
if len(new_message) > max_msg_len:
task_event_id = task_progress_update.id
LOG.warn(
f"Progress message for task '{task_id}' with ID "
f"'{task_event_id}' is too long. Truncating before insertion."
f" Original message was: '{new_message}'")
new_message = f"{new_message[:max_msg_len-len('...')]}..."
task_progress_update.message = new_message


Expand Down
6 changes: 5 additions & 1 deletion coriolis/db/sqlalchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

BASE = declarative.declarative_base()

MAX_EVENT_MESSAGE_LENGHT = 1024


class TaskEvent(BASE, models.TimestampMixin, models.SoftDeleteMixin,
models.ModelBase):

__tablename__ = 'task_event'

id = sqlalchemy.Column(sqlalchemy.String(36),
Expand All @@ -27,7 +30,8 @@ class TaskEvent(BASE, models.TimestampMixin, models.SoftDeleteMixin,
nullable=False)
level = sqlalchemy.Column(sqlalchemy.String(20), nullable=False)
index = sqlalchemy.Column(sqlalchemy.Integer, nullable=False)
message = sqlalchemy.Column(sqlalchemy.String(1024), nullable=False)
message = sqlalchemy.Column(
sqlalchemy.String(MAX_EVENT_MESSAGE_LENGHT), nullable=False)

def to_dict(self):
result = {
Expand Down
Loading