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

[filebeat][gcs] - Simplified state checkpoint calculation #40937

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Add a configuration option for TCP/UDP network type. {issue}40407[40407] {pull}40623[40623]
- Added debug logging to parquet reader in x-pack/libbeat/reader. {pull}40651[40651]
- Added filebeat debug histograms for s3 object size and events per processed s3 object. {pull}40775[40775]
- Simplified GCS input state checkpoint calculation logic. {issue}40878[40878] {pull}40937[40937]

==== Deprecated

Expand Down
45 changes: 12 additions & 33 deletions x-pack/filebeat/input/gcs/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package gcs
import (
"context"
"fmt"
"slices"
"sort"
"strings"
"sync"

Expand Down Expand Up @@ -181,41 +183,18 @@ func (s *scheduler) fetchObjectPager(ctx context.Context, pageSize int) *iterato
// moveToLastSeenJob, moves to the latest job position past the last seen job
// Jobs are stored in lexicographical order always, hence the latest position can be found either on the basis of job name or timestamp
func (s *scheduler) moveToLastSeenJob(jobs []*job) []*job {
var latestJobs []*job
jobsToReturn := make([]*job, 0)
counter := 0
flag := false
ignore := false

for _, job := range jobs {
switch {
case job.Timestamp().After(s.state.checkpoint().LatestEntryTime):
latestJobs = append(latestJobs, job)
case job.Name() == s.state.checkpoint().ObjectName:
flag = true
case job.Name() > s.state.checkpoint().ObjectName:
flag = true
counter--
case job.Name() <= s.state.checkpoint().ObjectName && (!ignore):
ignore = true
}
counter++
}

if flag && (counter < len(jobs)-1) {
jobsToReturn = jobs[counter+1:]
} else if !flag && !ignore {
jobsToReturn = jobs
}
cp := s.state.checkpoint()
jobs = slices.DeleteFunc(jobs, func(j *job) bool {
return !(j.Timestamp().After(cp.LatestEntryTime) || j.Name() > cp.ObjectName)
})

// in a senario where there are some jobs which have a later time stamp
// in a scenario where there are some jobs which have a greater timestamp
// but lesser lexicographic order and some jobs have greater lexicographic order
// than the current checkpoint object name, then we append the latest jobs
if len(jobsToReturn) != len(jobs) && len(latestJobs) > 0 {
jobsToReturn = append(latestJobs, jobsToReturn...)
}

return jobsToReturn
// than the current checkpoint blob name, we then sort around the pivot checkpoint timestamp
sort.Slice(jobs, func(i, _ int) bool {
return jobs[i].Timestamp().After(cp.LatestEntryTime)
})
return jobs
}

func (s *scheduler) addFailedJobs(ctx context.Context, jobs []*job) []*job {
Expand Down
Loading