Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add WaitUntilEmpty to LogSender#12159

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spikecurtis merged 1 commit intomainfromspike/10534-wait-until-empty
Feb 20, 2024

Conversation

spikecurtis
Copy link
Contributor

@spikecurtisspikecurtis commentedFeb 15, 2024
edited
Loading

We'll need this to be able to tell when all outstanding logs have been sent, as part of graceful shutdown.

@spikecurtisGraphite App
Copy link
ContributorAuthor

spikecurtis commentedFeb 15, 2024
edited
Loading

@spikecurtisspikecurtis marked this pull request as ready for reviewFebruary 15, 2024 12:53
case <-nevermind:
return
}
}()
Copy link
Member

@mafredrimafredriFeb 15, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why are we duplicating logic fromSendLoop here? Since this method doesn't attempt to send, it's quite pointless unless the signaling is happening from a runningSendLoop anyway.

Edit: Ah, nevermind, just realized this is only here to handle the user provided context.

I think this could be greatly simplified:

func (l*LogSender)WaitUntilEmpty(ctx context.Context)error {select {case<-ctx.Done():returnctx.Err()case<-l.allSent:returnnil}}

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The problem with anallSent channel is how to arrange when it should read. Closing the channel won't work, because you can't "unclose" it if more data gets queued.

Writing to the channel won't work if there are more than one caller to WaitUntilEmpty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

True, it would work better/simpler if the send loop was channel-based as well. In that case, one approach could be this:

func (l*LogSender)WaitUntilEmpty(ctx context.Context)error {wait:=make(chanstruct{})l.waitUntilEmpty<-waitselect {case<-ctx.Done():returnctx.Err()case<-wait:returnnil}}// SendLoopvarwaiters []chanstruct{}for {select {case<-tick:case<-l.waitUntilEmpty:waiters=append(waiters,wait)}// ...iflen(l.queues)==0 {for_,wait:=rangewaiters {close(wait)}waiters=nil}

But it's not quite as nice when retrofitted into the mutex style loop.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The problem there is that it requiresSendLoop to actually be running in order forWaitUntilEmpty() to return, which it might not be but we are still empty.

Channels are great for communicating between goroutines. Here what we really, actually want is to know when acondition is satisfied, regardless of other running goroutines, and for thatsync.Cond is your friend.

Copy link
Member

@mafredrimafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I had a suggestion for changingWaitUntilEmpty, but I'll leave it up to you whether or not to implement. Works as-is, too, although I feel mutexes are starting to make this service overly complex (vs using channel based communication).

Comment on lines +508 to +517
if len(l.queues) == 0 {
return nil
}
return ctx.Err()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
iflen(l.queues)==0 {
returnnil
}
returnctx.Err()
returnctx.Err()

We don't actually need this check, this way we give priority to the context cancellation, even if we happen to be done at the same time (this can be preferable in some cases).

@spikecurtisspikecurtisforce-pushed thespike/10534-log-sender-agentsdk branch from2a2203e to900e32aCompareFebruary 16, 2024 10:12
@spikecurtisspikecurtisforce-pushed thespike/10534-wait-until-empty branch fromf39d152 to2f52a67CompareFebruary 16, 2024 10:12
Base automatically changed fromspike/10534-log-sender-agentsdk tomainFebruary 20, 2024 06:44
@spikecurtisspikecurtisforce-pushed thespike/10534-wait-until-empty branch from2f52a67 todfe07f9CompareFebruary 20, 2024 07:04
@spikecurtisspikecurtis merged commitab4cb66 intomainFeb 20, 2024
@spikecurtisspikecurtis deleted the spike/10534-wait-until-empty branchFebruary 20, 2024 07:11
@spikecurtisGraphite App
Copy link
ContributorAuthor

Merge activity

@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 20, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@spikecurtisspikecurtis

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@spikecurtis@mafredri

[8]ページ先頭

©2009-2025 Movatter.jp