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

(Logscribe) send duplicate or logs with issues to slack #2256

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from 1 commit
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
21 changes: 16 additions & 5 deletions node/pkg/logscribe/logprocessor/logprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ func (p *LogProcessor) fetchCurrentIssues(ctx context.Context) ([]string, error)
return issues, nil
}

func (p *LogProcessor) CreateGithubIssue(ctx context.Context, processedLogs []LogInsertModelWithCount, service string) {
func (p *LogProcessor) CreateGithubIssue(ctx context.Context, processedLogs []LogInsertModelWithCount, service string) []LogInsertModelWithCount {
if p.githubOwner == "test" {
return
return nil
}

currentIssues, err := p.fetchCurrentIssues(ctx)
Expand All @@ -201,28 +201,33 @@ func (p *LogProcessor) CreateGithubIssue(ctx context.Context, processedLogs []Lo

issueCount := 0
processedLogHashes := [][]interface{}{}
nonprocessedLogs := []LogInsertModelWithCount{}
Intizar-T marked this conversation as resolved.
Show resolved Hide resolved
for _, entry := range processedLogs {
hash := hashLog(entry.LogInsertModel)
res, err := db.QueryRow[Count](ctx, logAlreadyProcessedQuery, map[string]any{
"hash": hash,
})
if err != nil {
log.Error().Err(err).Msg("Failed to check if log already processed")
nonprocessedLogs = append(nonprocessedLogs, entry)
continue
}
if res.Count > 0 {
log.Debug().Msg("Log already processed, skipping creation of github issue")
nonprocessedLogs = append(nonprocessedLogs, entry)
continue
}
if slices.Contains(currentIssues, entry.Message) {
log.Debug().Msgf("Issue already exists, skipping: %s", entry.Message)
nonprocessedLogs = append(nonprocessedLogs, entry)
continue
}

entryJson, err := json.MarshalIndent(entry, "", " ")
if err != nil {
log.Error().Err(err).Msg("Failed to marshal log")
return
nonprocessedLogs = append(nonprocessedLogs, entry)
continue
}
formattedBody := "```go\n" + string(entryJson) + "\n```"
issueRequest := &github.IssueRequest{
Expand All @@ -247,6 +252,8 @@ func (p *LogProcessor) CreateGithubIssue(ctx context.Context, processedLogs []Lo
if err == nil {
processedLogHashes = append(processedLogHashes, []interface{}{hash})
issueCount++
} else {
nonprocessedLogs = append(nonprocessedLogs, entry)
}
}

Expand All @@ -258,6 +265,8 @@ func (p *LogProcessor) CreateGithubIssue(ctx context.Context, processedLogs []Lo
}

log.Info().Msgf("Created %d github issues", issueCount)

return nonprocessedLogs
}

func (p *LogProcessor) BulkCopyLogs(ctx context.Context, logsChannel <-chan *[]LogInsertModel) {
Expand Down Expand Up @@ -304,8 +313,10 @@ func (p *LogProcessor) StartProcessingCronJob(ctx context.Context) error {
for _, service := range services {
processedLogs := ProcessLogs(ctx, service.Service)
if len(processedLogs) > 0 {
addLogsToSlackMessage(&slackMessage, processedLogs)
p.CreateGithubIssue(ctx, processedLogs, service.Service)
duplicateOrLogsWithIssues := p.CreateGithubIssue(ctx, processedLogs, service.Service)
if len(duplicateOrLogsWithIssues) > 0 {
addLogsToSlackMessage(&slackMessage, duplicateOrLogsWithIssues)
}
}
}
if slackMessage.Len() > 0 {
Expand Down