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

send error logs to slack #2239

Merged
merged 2 commits into from
Aug 27, 2024
Merged
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
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)
Intizar-T marked this conversation as resolved.
Show resolved Hide resolved
p.CreateGithubIssue(ctx, processedLogs, service.Service)
}
}
if slackMessage.Len() > 0 {
alert.SlackAlert("Logscribe report:\n" + slackMessage.String())
}
Intizar-T marked this conversation as resolved.
Show resolved Hide resolved
})
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")
}
}