Skip to content

Commit

Permalink
add codeowner squad to humio logs for pods errors (#384)
Browse files Browse the repository at this point in the history
* add codeowner squad to humio logs for pods errors

* no one as squad if squad doesnt exist
  • Loading branch information
MariaCFFrandsen committed Jul 13, 2022
1 parent 3d486d7 commit 9ae30f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/daemon/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const (
artifactIDAnnotationKey = "lunarway.com/artifact-id"
authorAnnotationKey = "lunarway.com/author"
controlledAnnotationKey = "lunarway.com/controlled-by-release-manager"
squadLabelKey = "squad"
)

func observe(annotations map[string]string) {
Expand Down
11 changes: 9 additions & 2 deletions cmd/daemon/kubernetes/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func (p *PodInformer) handle(e interface{}) {
pod.Name)
return
}

log.Infof("Pod: %s is in CrashLoopBackOff", pod.Name)
log.Infof("Pod: %s is in CrashLoopBackOff owned by squad %s", pod.Name, getCodeOwnerSquad)
restartCount := pod.Status.ContainerStatuses[0].RestartCount
if math.Mod(float64(restartCount), p.moduloCrashReportNotif) != 1 {
return
Expand Down Expand Up @@ -99,6 +98,7 @@ func (p *PodInformer) handle(e interface{}) {
Errors: errorContainers,
ArtifactID: pod.Annotations[artifactIDAnnotationKey],
AuthorEmail: pod.Annotations[authorAnnotationKey],
Squad: getCodeOwnerSquad(pod.Annotations),
})
if err != nil {
log.Errorf("Failed to send crash loop backoff event: %v", err)
Expand Down Expand Up @@ -265,3 +265,10 @@ func parseToJSONAray(str string) ([]ContainerLog, error) {
}
return logs, nil
}

func getCodeOwnerSquad(annotations map[string]string) string {
if squad, ok := annotations[squadLabelKey]; ok {
return squad
}
return "no-one"
}
1 change: 1 addition & 0 deletions internal/http/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type PodErrorEvent struct {
AuthorEmail string `json:"authorEmail,omitempty"`
Environment string `json:"environment,omitempty"`
ArtifactID string `json:"artifactId,omitempty"`
Squad string `json:"squad,omitempty"`
}

type JobConditionError struct {
Expand Down

0 comments on commit 9ae30f0

Please sign in to comment.