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

fix(AlertsReports): making log retention "None" option valid #27554

Merged
merged 2 commits into from
Apr 23, 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
6 changes: 1 addition & 5 deletions superset-frontend/src/features/alerts/AlertReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1622,11 +1622,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
ariaLabel={t('Log retention')}
placeholder={t('Log retention')}
onChange={onLogRetentionChange}
value={
typeof currentAlert?.log_retention === 'number'
? currentAlert?.log_retention
: ALERT_REPORTS_DEFAULT_RETENTION
}
Comment on lines -1625 to -1629
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's double check if this can actually go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default log_retention value is specified as a number, and the dropdown options include only integers.

Additionally, there backend validation schema only allows integers. There shouldn't be a situation which calls for typeof !== 'number'

value={currentAlert?.log_retention}
options={RETENTION_OPTIONS}
sortComparator={propertyComparator('value')}
/>
Expand Down
1 change: 1 addition & 0 deletions superset/commands/report/log_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def run(self) -> None:
row_count = ReportScheduleDAO.bulk_delete_logs(
report_schedule, from_date, commit=False
)
db.session.commit()
logger.info(
"Deleted %s logs for report schedule id: %s",
str(row_count),
Expand Down
2 changes: 1 addition & 1 deletion superset/reports/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class ReportSchedulePutSchema(Schema):
log_retention = fields.Integer(
metadata={"description": log_retention_description, "example": 90},
required=False,
validate=[Range(min=1, error=_("Value must be greater than 0"))],
validate=[Range(min=0, error=_("Value must be 0 or greater"))],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does a log retention of 0 mean and how does this differ from None?

Copy link
Contributor Author

@fisjac fisjac Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current behavior is such that the "None" option is a display for the value 0, but 0 isn't accepted on the backend.

The schema is expecting for log_retention to be an integer value indicating the # of days the logs will be retained. I've preserved the initial logic that the None value is stored as 0, but enabled 0 to be an acceptable value.

The log_retention is then passed to the log_prune function which removes any logs with a date less than the current date - log retention (0) days.

)
grace_period = fields.Integer(
metadata={"description": grace_period_description, "example": 60 * 60 * 4},
Expand Down
Loading