Skip to content

Commit

Permalink
Merge branch 'master' of github.com:opsway-io/backend
Browse files Browse the repository at this point in the history
  • Loading branch information
TeisNP committed Jan 27, 2024
2 parents 9034786 + f0c44f9 commit 32c9ed8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions cmd/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ func handleTask(ctx context.Context, logger *logrus.Logger, prober http.Service,
failed, passed, err := assertResult(res, m.Assertions)
if err != nil {
l.WithError(err).Error("failed to assert result")

return
}

failedCount := len(*failed)
passedCount := len(*passed)
failedCount := len(failed)
passedCount := len(passed)

l = l.WithFields(logrus.Fields{
"assertions_passed": passedCount,
Expand All @@ -133,15 +135,15 @@ func handleTask(ctx context.Context, logger *logrus.Logger, prober http.Service,
if failedCount > 0 {
l.Info("some assertions failed, triggering incident")

if err = triggerIncident(m, res, failed); err != nil {
if err = triggerIncident(m, res, &failed); err != nil {
l.WithError(err).Error("failed to trigger incident")
}
} else {
l.Info("all assertions passed")
}
}

func assertResult(httpResult *http.Result, assertions []entities.MonitorAssertion) (failed, passed *[]entities.MonitorAssertion, err error) {
func assertResult(httpResult *http.Result, assertions []entities.MonitorAssertion) ([]entities.MonitorAssertion, []entities.MonitorAssertion, error) {
if len(assertions) == 0 {
return nil, nil, nil
}
Expand All @@ -153,14 +155,14 @@ func assertResult(httpResult *http.Result, assertions []entities.MonitorAssertio
return nil, nil, err
}

failed = &[]entities.MonitorAssertion{}
passed = &[]entities.MonitorAssertion{}
failed := []entities.MonitorAssertion{}
passed := []entities.MonitorAssertion{}

for i, ok := range assertResult {
if ok {
*passed = append(*passed, assertions[i])
passed = append(passed, assertions[i])
} else {
*failed = append(*failed, assertions[i])
failed = append(failed, assertions[i])
}
}

Expand Down

0 comments on commit 32c9ed8

Please sign in to comment.