feat(backend): added app crash detector to heuristics service

This commit is contained in:
Alexander Zavorotynskiy 2023-09-05 16:57:34 +02:00
parent 481db19dbe
commit 7bffd2f321
4 changed files with 88 additions and 1 deletions

View file

@ -34,6 +34,7 @@ func main() {
&web.MemoryIssueDetector{},
&web.NetworkIssueDetector{},
&web.PerformanceAggregator{},
web.NewAppCrashDetector(),
}
}

View file

@ -66,7 +66,8 @@ func (s *saverImpl) handleMessage(msg Message) error {
case *Metadata:
return s.sessions.UpdateMetadata(m.SessionID(), m.Key, m.Value)
case *IssueEvent:
if err = s.pg.InsertIssueEvent(session, m); err != nil {
err = s.pg.InsertIssueEvent(session, m)
if err != nil {
return err
}
return s.sessions.UpdateIssuesStats(session.SessionID, 0, postgres.GetIssueScore(m))

View file

@ -77,6 +77,10 @@ func (conn *Conn) InsertIssueEvent(sess *sessions.Session, e *messages.IssueEven
payload = nil
}
if e.Type == "app_crash" {
log.Printf("app crash event: %+v", e)
}
if err := conn.bulks.Get("webIssues").Append(sess.ProjectID, issueID, e.Type, e.ContextString); err != nil {
log.Printf("insert web issue err: %s", err)
}

View file

@ -0,0 +1,81 @@
package web
import (
"log"
"openreplay/backend/pkg/messages"
)
const CrashWindow = 2 * 1000
const CrashThreshold = 70
type AppCrashDetector struct {
dropTimestamp uint64
dropMessageID uint64
lastIssueTimestamp uint64
}
func NewAppCrashDetector() *AppCrashDetector {
return &AppCrashDetector{}
}
func (h *AppCrashDetector) reset() {
h.dropTimestamp = 0
h.lastIssueTimestamp = 0
}
func (h *AppCrashDetector) updateLastIssueTimestamp(msgTimestamp uint64) {
if msgTimestamp > h.lastIssueTimestamp {
h.lastIssueTimestamp = msgTimestamp
}
}
func (h *AppCrashDetector) build() messages.Message {
if h.dropTimestamp == 0 || h.lastIssueTimestamp == 0 {
// Nothing to build
return nil
}
// Calculate timestamp difference
var diff uint64
if h.lastIssueTimestamp > h.dropTimestamp {
diff = h.lastIssueTimestamp - h.dropTimestamp
} else {
diff = h.dropTimestamp - h.lastIssueTimestamp
}
// Check possible app crash
if diff < CrashWindow {
msg := &messages.IssueEvent{
MessageID: h.dropMessageID,
Timestamp: h.dropTimestamp,
Type: "app_crash",
}
log.Printf("created app crash event: %+v", msg)
h.reset()
return msg
}
return nil
}
func (h *AppCrashDetector) Handle(message messages.Message, timestamp uint64) messages.Message {
switch msg := message.(type) {
case *messages.UnbindNodes:
if msg.TotalRemovedPercent < CrashThreshold {
// Not enough nodes removed
return nil
}
h.dropTimestamp = timestamp
h.dropMessageID = msg.MsgID()
case *messages.JSException:
h.updateLastIssueTimestamp(msg.Timestamp)
case *messages.NetworkRequest:
if msg.Status >= 400 {
h.updateLastIssueTimestamp(msg.Timestamp)
}
}
return h.build()
}
func (h *AppCrashDetector) Build() messages.Message {
return h.build()
}