-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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(crons): Initial removal of status from Monitor object #47910
Changes from 5 commits
47f6136
e4f85d7
2d28f7a
0f747c1
54d581f
540e0c4
f9c9e62
9f8143c
5d07a29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,7 @@ def put(self, request: Request, organization, project, monitor) -> Response: | |
if "slug" in result: | ||
params["slug"] = result["slug"] | ||
if "status" in result: | ||
# TODO(rjo100): resets status if monitor is failed, needs fixing with environments | ||
if result["status"] == MonitorStatus.ACTIVE: | ||
if monitor.status not in (MonitorStatus.OK, MonitorStatus.ERROR): | ||
params["status"] = MonitorStatus.ACTIVE | ||
|
@@ -111,6 +112,8 @@ def put(self, request: Request, organization, project, monitor) -> Response: | |
|
||
if params: | ||
monitor.update(**params) | ||
if params.get("status"): | ||
MonitorEnvironment.objects.filter(monitor=monitor).update(status=params["status"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will fix a sort bug by marking the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure we want this? I would think we would just want to keep the sorting logic so that monitors that are disabled get sorted to the bottom and just ignore the disabled in that case. I would also probably not do this in this cleanup PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the issue is that we only read off the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #48039 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good stuff 👍 |
||
self.create_audit_entry( | ||
request=request, | ||
organization=organization, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,43 +218,6 @@ def get_next_scheduled_checkin(self, last_checkin): | |
) | ||
return next_checkin + timedelta(minutes=int(self.config.get("checkin_margin") or 0)) | ||
|
||
def mark_failed(self, last_checkin=None, reason=MonitorFailure.UNKNOWN): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
if last_checkin is None: | ||
next_checkin_base = timezone.now() | ||
last_checkin = self.last_checkin or timezone.now() | ||
else: | ||
next_checkin_base = last_checkin | ||
|
||
new_status = MonitorStatus.ERROR | ||
if reason == MonitorFailure.MISSED_CHECKIN: | ||
new_status = MonitorStatus.MISSED_CHECKIN | ||
|
||
affected = ( | ||
type(self) | ||
.objects.filter( | ||
Q(last_checkin__lte=last_checkin) | Q(last_checkin__isnull=True), id=self.id | ||
) | ||
.update( | ||
next_checkin=self.get_next_scheduled_checkin(next_checkin_base), | ||
status=new_status, | ||
last_checkin=last_checkin, | ||
) | ||
) | ||
if not affected: | ||
return False | ||
|
||
return True | ||
|
||
def mark_ok(self, checkin: MonitorCheckIn, ts: datetime): | ||
params = { | ||
"last_checkin": ts, | ||
"next_checkin": self.get_next_scheduled_checkin(ts), | ||
} | ||
if checkin.status == CheckInStatus.OK and self.status != MonitorStatus.DISABLED: | ||
params["status"] = MonitorStatus.OK | ||
|
||
Monitor.objects.filter(id=self.id).exclude(last_checkin__gt=ts).update(**params) | ||
|
||
|
||
@region_silo_only_model | ||
class MonitorCheckIn(Model): | ||
|
@@ -417,7 +380,7 @@ def mark_ok(self, checkin: MonitorCheckIn, ts: datetime): | |
"last_checkin": ts, | ||
"next_checkin": self.monitor.get_next_scheduled_checkin(ts), | ||
} | ||
if checkin.status == CheckInStatus.OK and self.status != MonitorStatus.DISABLED: | ||
if checkin.status == CheckInStatus.OK and self.monitor.status != MonitorStatus.DISABLED: | ||
params["status"] = MonitorStatus.OK | ||
|
||
MonitorEnvironment.objects.filter(id=self.id).exclude(last_checkin__gt=ts).update(**params) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,6 @@ def serialize(self, obj, attrs, user): | |
"name": obj.name, | ||
"slug": obj.slug, | ||
"config": config, | ||
"lastCheckIn": obj.last_checkin, | ||
"nextCheckIn": obj.next_checkin, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very nice |
||
"dateCreated": obj.date_added, | ||
"project": attrs["project"], | ||
"environments": attrs["environments"], | ||
|
@@ -102,8 +100,6 @@ class MonitorSerializerResponse(TypedDict): | |
type: str | ||
config: Any | ||
dateCreated: datetime | ||
lastCheckIn: datetime | ||
nextCheckIn: datetime | ||
project: ProjectSerializerResponse | ||
environments: MonitorEnvironmentSerializerResponse | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're going to do a migration here to move all monitors that are in non
ObjectStatus
type status to ACTIVE or DISABLED right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally yes. we reference
PENDING DELETION
a lot tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's OK, pending deletion is part of ObjectStatus right