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 wrong end_time #946

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Fix wrong end_time #946

wants to merge 5 commits into from

Conversation

hmpf
Copy link
Contributor

@hmpf hmpf commented Nov 15, 2024

Hopefylly closes #935

Also, attempt to clean up/document event types, and event type validation in the API.

/.. also, attempt to clean up/document event types, and event type
validation in the API.
Copy link

sonarcloud bot commented Nov 15, 2024

@@ -439,17 +462,36 @@ def tags(self):
def incident_relations(self):
return IncidentRelation.objects.filter(Q(incident1=self) | Q(incident2=self))

def all_opening_events(self):
open_events = (Event.Type.INCIDENT_START, Event.Type.REOPEN)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
open_events = (Event.Type.INCIDENT_START, Event.Type.REOPEN)
open_events = Event.OPENING_TYPES

return self.events.filter(type__in=open_events).order_by("timestamp")

def all_reopen_events(self):
return self.events.filter(typen=Event.Type.REOPEN).order_by("timestamp")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return self.events.filter(typen=Event.Type.REOPEN).order_by("timestamp")
return self.events.filter(type=Event.Type.REOPEN).order_by("timestamp")

return self.events.filter(typen=Event.Type.REOPEN).order_by("timestamp")

def all_closing_events(self):
close_events = (Event.Type.CLOSE, Event.Type.INCIDENT_END)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
close_events = (Event.Type.CLOSE, Event.Type.INCIDENT_END)
close_events = Event.CLOSING_TYPES

Comment on lines +527 to +532
if self.stateless_event:
# Weird, stateless event without stateless end_time, fix
self.end_time = None
self.save()
LOG.warn("Mismatch between self %s end_time and event type: set stateless", self.pk)
return True
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like a normalization issue? Two ways of indicating that an event is stateless?

def event_already_exists(self, event_type):
return self.events.filter(type=event_type).exists()

def repair_end_time(self) -> Optional[bool]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sure that you have prefetched all events here, because otherwise thie function may cause a bunch of round trips to the db

Comment on lines +540 to +541
last_close_event = close_events.last()
if not reopen_event or reopen_event.timestamp < last_close_event.timestamp:
Copy link
Collaborator

Choose a reason for hiding this comment

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

can last_close_event be None? Perhaps if there is a reopen_event there also always should be a close event. But you know, "should"...

Comment on lines +505 to +506
incident.repair_end_time()
abort_due_to_too_many_events(incident, event_type)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is where we would end up in our case. There already is an END event, but the incident is reported open, so we fire another END event. The incident is repaired, so the end_time is correctly set (closing the incident), but we still get a 400 error back like we did something wrong. We're being gaslighted here: "I didn't make a mistake and just fixed it, you made a mistake!" 😂

perhaps look a the return value of the repair?

Comment on lines +507 to +510
if event_type in Event.CLOSING_TYPES and not incident.open:
self._abort_due_to_type_validation_error("The incident is already closed.")
if event_type == Event.Type.REOPEN and incident.open:
self._abort_due_to_type_validation_error("The incident is already open.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are there situations here where we want to repair the incident here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incidents may get stuck open
2 participants