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

[branch/v9] Spread out UploadCompleter load (#11590) #11698

Merged
merged 2 commits into from
Apr 5, 2022
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
29 changes: 18 additions & 11 deletions lib/events/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apiutils "github.com/gravitational/teleport/api/utils"
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/utils/interval"

"github.com/gravitational/trace"

Expand Down Expand Up @@ -105,11 +106,16 @@ type UploadCompleter struct {
}

func (u *UploadCompleter) run() {
ticker := u.cfg.Clock.NewTicker(u.cfg.CheckPeriod)
defer ticker.Stop()
periodic := interval.New(interval.Config{
Duration: u.cfg.CheckPeriod,
FirstDuration: utils.HalfJitter(u.cfg.CheckPeriod),
Jitter: utils.NewSeventhJitter(),
})
defer periodic.Stop()

for {
select {
case <-ticker.Chan():
case <-periodic.Next():
if err := u.CheckUploads(u.closeCtx); err != nil {
u.log.WithError(err).Warningf("Failed to check uploads.")
}
Expand All @@ -134,6 +140,10 @@ func (u *UploadCompleter) CheckUploads(ctx context.Context) error {
}
parts, err := u.cfg.Uploader.ListParts(ctx, upload)
if err != nil {
if trace.IsNotFound(err) {
u.log.WithError(err).Warnf("Missing parts for upload %v. Moving on to next upload.", upload.ID)
continue
}
return trace.Wrap(err)
}

Expand Down Expand Up @@ -161,7 +171,7 @@ func (u *UploadCompleter) CheckUploads(ctx context.Context) error {
case <-u.cfg.Clock.After(2 * time.Minute):
u.log.Debugf("checking for session end event for session %v", upload.SessionID)
if err := u.ensureSessionEndEvent(ctx, uploadData); err != nil {
u.log.WithError(err).Warningf("failed to ensure session end event")
u.log.WithError(err).Warningf("failed to ensure session end event for session %v", upload.SessionID)
}
}
}()
Expand Down Expand Up @@ -201,8 +211,6 @@ func (u *UploadCompleter) ensureSessionEndEvent(ctx context.Context, uploadData
var sshSessionEnd events.SessionEnd
var desktopSessionEnd events.WindowsDesktopSessionEnd

first := true

// We use the streaming events API to search through the session events, because it works
// for both Desktop and SSH sessions, where as the GetSessionEvents API relies on downloading
// a copy of the session and using the SSH-specific index to iterate through events.
Expand All @@ -217,11 +225,6 @@ loop:
break loop
}

if first {
u.log.Infof("got first event %T", evt)
first = false
}

lastEvent = evt

switch e := evt.(type) {
Expand Down Expand Up @@ -271,6 +274,10 @@ loop:
}
}

if lastEvent == nil {
return trace.Errorf("could not find any events for session %v", uploadData.SessionID)
}

sshSessionEnd.Participants = apiutils.Deduplicate(sshSessionEnd.Participants)
sshSessionEnd.EndTime = lastEvent.GetTime()
desktopSessionEnd.EndTime = lastEvent.GetTime()
Expand Down