Skip to content

Commit

Permalink
[agent-smioth] Improve report of infringements with long commands
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Aug 27, 2021
1 parent 8aab84e commit eaf13c3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
22 changes: 17 additions & 5 deletions components/ee/agent-smith/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ func startMemoryWatchdog(maxSysMemMib uint64) {

func notifySlack(webhook string, hostURL string, ws agent.InfringingWorkspace, penalties []agent.PenaltyKind) error {
var (
region = os.Getenv("GITPOD_REGION")
lblDetails = "Details"
lblActions = "Actions"
lblPenalties = "Penalties"
region = os.Getenv("GITPOD_REGION")
lblDetails = "Details"
lblActions = "Actions"
lblPenalties = "Penalties"
lblInfringements = "Long Infringements details"
)

attachments := []slack.Attachment{
Expand Down Expand Up @@ -170,8 +171,19 @@ func notifySlack(webhook string, hostURL string, ws agent.InfringingWorkspace, p
},
)

infringements := make([]*slack.Field, len(ws.Infringements))
for _, v := range ws.Infringements {
infringements = append(infringements, &slack.Field{
Title: string(v.Kind), Value: v.Description,
})
}

attachments = append(attachments,
slack.Attachment{Title: &lblInfringements, Fields: infringements},
)

payload := slack.Payload{
Text: fmt.Sprintf("Agent Smith: %s", ws.DescibeInfringements()),
Text: fmt.Sprintf("Agent Smith: %s", ws.DescribeInfringements(150)),
IconEmoji: ":-(",
Attachments: attachments,
}
Expand Down
10 changes: 8 additions & 2 deletions components/ee/agent-smith/pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,18 @@ func (ws InfringingWorkspace) VID() string {
}

// DescibeInfringements returns a string representation of all infringements of this workspace
func (ws InfringingWorkspace) DescibeInfringements() string {
func (ws InfringingWorkspace) DescribeInfringements(charCount int) string {
res := make([]string, len(ws.Infringements))
for i, v := range ws.Infringements {
res[i] = fmt.Sprintf("%s: %s", v.Kind, v.Description)
}
return strings.Join(res, "\n")

infringements := strings.Join(res, "\n")
if len(infringements) > charCount {
infringements = infringements[:charCount]
}

return infringements
}

// Infringement reports a users particular wrongdoing
Expand Down

0 comments on commit eaf13c3

Please sign in to comment.