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

Conversation

fisjac
Copy link
Contributor

@fisjac fisjac commented Mar 18, 2024

SUMMARY

This PR implements two changes:

  1. Default behavior of log retention was to never commit session changes when log_prune runs. This behavior has been changed to ensure that logs are in fact deleted when log_prune runs.
  2. When a value of "None" was selected from the dropdown options, the backend would return a validation error "log_retention must be greater than 0." The changes attempt to fix this so that a log retention of 0 days results in all logs being deleted.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: ALERTS_REPORTS
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 70.11%. Comparing base (ae29427) to head (1f64964).
Report is 102 commits behind head on master.

Files Patch % Lines
superset/commands/report/log_prune.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #27554      +/-   ##
==========================================
+ Coverage   67.36%   70.11%   +2.74%     
==========================================
  Files        1909     1913       +4     
  Lines       74744    75999    +1255     
  Branches     8329     8396      +67     
==========================================
+ Hits        50352    53285    +2933     
+ Misses      22342    20652    -1690     
- Partials     2050     2062      +12     
Flag Coverage Δ
hive 48.93% <0.00%> (?)
javascript 57.51% <ø> (+0.28%) ⬆️
mysql 77.88% <0.00%> (?)
postgres 78.22% <0.00%> (+0.08%) ⬆️
presto 54.04% <0.00%> (?)
python 83.28% <0.00%> (+5.05%) ⬆️
sqlite 77.68% <0.00%> (+0.10%) ⬆️
unit 57.09% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@john-bodley
Copy link
Member

@fisjac would you mind including a screenshot to aid reviewers in understanding the context of allowing log retention to be "None".

@@ -46,7 +46,7 @@ def run(self) -> None:
)
try:
row_count = ReportScheduleDAO.bulk_delete_logs(
report_schedule, from_date, commit=False
report_schedule, from_date, commit=True
Copy link
Member

Choose a reason for hiding this comment

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

This is somewhat interesting. With commit=False I don't see where this command actually commits. My sense is there should be a db.session.commit() on line 60 to ensure we commit once rather than for every report schedule.

BTW I'm working on a PR which will ensure that we handle the "unit of work" correctly.

Copy link
Member

Choose a reason for hiding this comment

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

@fisjac you marked this as resolved, yet I don't believe the comment was addressed, i.e., the run method should commit once—at line 60 per the previous suggestion—rather than on a per report schedule basis.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@john-bodley I had forgotten to push some changes up. This should be covered in the latest push.

@fisjac fisjac closed this Mar 22, 2024
@fisjac fisjac reopened this Mar 22, 2024
@@ -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.

Comment on lines -1613 to -1629
value={
typeof currentAlert?.log_retention === 'number'
? currentAlert?.log_retention
: ALERT_REPORTS_DEFAULT_RETENTION
}
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'

@geido geido merged commit b7f3e0b into apache:master Apr 23, 2024
29 checks passed
@michael-s-molina michael-s-molina added the v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch label Apr 24, 2024
qleroy pushed a commit to qleroy/superset that referenced this pull request Apr 28, 2024
michael-s-molina pushed a commit that referenced this pull request Apr 29, 2024
jzhao62 pushed a commit to jzhao62/superset that referenced this pull request May 16, 2024
@mistercrunch mistercrunch added 🍒 4.0.1 🍒 4.0.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 24, 2024
irublev pushed a commit to HighviewPower/superset that referenced this pull request Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XS v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🍒 4.0.1 🍒 4.0.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants