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

Fix loki log output exiting before push is finished #3194

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions log/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ func (h *lokiHook) Listen(ctx context.Context) {
pushCh = make(chan chan int64)
)

pushDone := make(chan struct{})
defer func() { <-pushDone }()
Comment on lines +153 to +154
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did use a sync.WaitGroup in thePoC, but decided there is no need to import the sync package and this code is even shorter so 🤷

defer ticker.Stop()
defer close(pushCh)

go func() {
defer close(pushDone)
oldLogs := make([]tmpMsg, 0, h.limit*2)
for ch := range pushCh {
msgsToPush, msgs = msgs, msgsToPush
Expand Down