Skip to content

Commit

Permalink
send error logs to slack (#2239)
Browse files Browse the repository at this point in the history
* send error logs to slack

* make slackMessage a stringBuilder
  • Loading branch information
Intizar-T authored Aug 27, 2024
1 parent 2e61098 commit 3486519
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions node/pkg/logscribe/logprocessor/logprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

"bisonai.com/miko/node/pkg/alert"
"bisonai.com/miko/node/pkg/db"
errorsentinel "bisonai.com/miko/node/pkg/error"
"bisonai.com/miko/node/pkg/secrets"
Expand Down Expand Up @@ -299,12 +300,17 @@ func (p *LogProcessor) StartProcessingCronJob(ctx context.Context) error {
log.Error().Err(err).Msg("Failed to get services")
return
}
var slackMessage strings.Builder
for _, service := range services {
processedLogs := ProcessLogs(ctx, service.Service)
if len(processedLogs) > 0 {
addLogsToSlackMessage(&slackMessage, processedLogs)
p.CreateGithubIssue(ctx, processedLogs, service.Service)
}
}
if slackMessage.Len() > 0 {
alert.SlackAlert("Logscribe report:\n" + slackMessage.String())
}
})
if err != nil {
log.Error().Err(err).Msg("Failed to start processing cron job")
Expand All @@ -315,3 +321,14 @@ func (p *LogProcessor) StartProcessingCronJob(ctx context.Context) error {
p.cron.Start()
return nil
}

func addLogsToSlackMessage(slackMessage *strings.Builder, processedLogs []LogInsertModelWithCount) {
for _, entry := range processedLogs {
entryJson, err := json.MarshalIndent(entry, "", " ")
if err != nil {
log.Warn().Err(err).Msg("Failed to marshal log")
continue
}
slackMessage.WriteString(string(entryJson) + "\n")
}
}

0 comments on commit 3486519

Please sign in to comment.