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

feat: set "Invalid" status on canary CRD status #2374

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pkg/controllers/canary_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,7 @@ func (r *CanaryReconciler) Report() {

canary.Status.LastCheck = &metav1.Time{Time: time.Now()}
canary.Status.ChecksStatus = payload.CheckStatus
if payload.Pass {
canary.Status.Status = &v1.Passed
} else {
canary.Status.Status = &v1.Failed
}
canary.Status.Status = &payload.Status
adityathebe marked this conversation as resolved.
Show resolved Hide resolved

for _, eventMsg := range payload.FailEvents {
r.Events.Event(&canary, corev1.EventTypeWarning, "Failed", eventMsg)
Expand Down
58 changes: 36 additions & 22 deletions pkg/jobs/canary/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/flanksource/canary-checker/pkg/metrics"
"github.com/flanksource/canary-checker/pkg/utils"
"github.com/flanksource/duty/context"
"github.com/flanksource/duty/query"
dutyTypes "github.com/flanksource/duty/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -29,10 +28,9 @@ func UpdateCanaryStatusAndEvent(ctx context.Context, canary v1.Canary, results [

var checkStatus = make(map[string]*v1.CheckStatus)
var duration int64
var messages, errors []string
var messages, errorMsgs []string
var failEvents []string
var msg, errorMsg string
var pass = true
var status v1.CanaryStatusCondition
var lastTransitionedTime *metav1.Time
var highestLatency float64
var uptimeAgg dutyTypes.Uptime
Expand Down Expand Up @@ -60,10 +58,10 @@ func UpdateCanaryStatusAndEvent(ctx context.Context, canary v1.Canary, results [
}

// Transition
q := query.CheckQueryParams{Check: checkID, StatusCount: 1}
if canary.Status.LastTransitionedTime != nil {
q.Start = canary.Status.LastTransitionedTime.Format(time.RFC3339)
}
// q := query.CheckQueryParams{Check: checkID, StatusCount: 1}
// if canary.Status.LastTransitionedTime != nil {
// q.Start = canary.Status.LastTransitionedTime.Format(time.RFC3339)
// }

latestCheckStatus, err := db.LatestCheckStatus(ctx, checkID)
if err != nil || latestCheckStatus == nil {
Expand All @@ -81,31 +79,47 @@ func UpdateCanaryStatusAndEvent(ctx context.Context, canary v1.Canary, results [
lastTransitionedTime = &metav1.Time{Time: transitionTime}
}

// Update status message
if len(messages) == 1 {
msg = messages[0]
} else if len(messages) > 1 {
msg = fmt.Sprintf("%s, (%d more)", messages[0], len(messages)-1)
if result.Message != "" {
messages = append(messages, result.Message)
}
if len(errors) == 1 {
errorMsg = errors[0]
} else if len(errors) > 1 {
errorMsg = fmt.Sprintf("%s, (%d more)", errors[0], len(errors)-1)

if result.Error != "" {
errorMsgs = append(errorMsgs, result.Error)
}

if !result.Pass {
if result.Pass {
status = v1.Passed
} else {
failEvents = append(failEvents, fmt.Sprintf("%s-%s: %s", result.Check.GetType(), result.Check.GetEndpoint(), result.Message))
pass = false
status = v1.Failed
}

if result.Invalid {
status = v1.Invalid
}
}

var errMsg string
if len(errorMsgs) == 1 {
errMsg = errorMsgs[0]
} else if len(errorMsgs) > 1 {
errMsg = fmt.Sprintf("%s, (%d more)", errorMsgs[0], len(errorMsgs)-1)
}

var msg string
if len(messages) == 1 {
msg = messages[0]
} else if len(messages) > 1 {
msg = fmt.Sprintf("%s, (%d more)", messages[0], len(messages)-1)
}

payload := CanaryStatusPayload{
Pass: pass,
Status: status,
CheckStatus: checkStatus,
FailEvents: failEvents,
LastTransitionedTime: lastTransitionedTime,
Message: msg,
ErrorMessage: errorMsg,
ErrorMessage: errMsg,
Uptime: uptimeAgg.String(),
Latency: utils.Age(time.Duration(highestLatency) * time.Millisecond),
NamespacedName: canary.GetNamespacedName(),
Expand All @@ -115,7 +129,7 @@ func UpdateCanaryStatusAndEvent(ctx context.Context, canary v1.Canary, results [
}

type CanaryStatusPayload struct {
Pass bool
Status v1.CanaryStatusCondition
CheckStatus map[string]*v1.CheckStatus
FailEvents []string
LastTransitionedTime *metav1.Time
Expand Down
Loading