feat: Add basic periodic metric INFO logger#496
Merged
kodiakhq[bot] merged 2 commits intocloudquery:mainfrom Dec 24, 2022
shimonp21:periodic_metric_logger
Merged
feat: Add basic periodic metric INFO logger#496kodiakhq[bot] merged 2 commits intocloudquery:mainfrom shimonp21:periodic_metric_logger
kodiakhq[bot] merged 2 commits intocloudquery:mainfrom
shimonp21:periodic_metric_logger
Conversation
⏱️ Benchmark results
|
yevgenypats
suggested changes
Dec 17, 2022
Contributor
yevgenypats
left a comment
There was a problem hiding this comment.
Few changes needed to make it work
plugins/source_scheduler_dfs.go
Outdated
| // We start a goroutine that logs the metrics periodically. | ||
| // It needs its own waitgroup | ||
| var logWg sync.WaitGroup | ||
| logWg.Add(1) |
Contributor
There was a problem hiding this comment.
I don't think you need the waitgroup here
Contributor
Author
There was a problem hiding this comment.
- Here is the race I am worried about:
- A sync starts and finishes, and
syncDfsreturns. However, periodic-metric-logger is still running (maybe he's still summing up in TotalResourcesAtomic, so not looking atctxright now. - A new sync starts (maybe we are in
grpc-mode?), andmetrics.InitWithClientsis called. periodicMetricLoggeris still running and summing up stuff from the map, so golang panics withconcurrent reads and writes to map!
See the following code-snippet for a toy reproduction:
https://gist.github.com/shimonp21/dda9ee70434ad5da25f3c3ecf5149b40
This produces a panic:
fatal error: concurrent map read and map write
fatal error: concurrent map read and map write
goroutine 31 [running]:
main.mapReader(0x0?)
/Users/shimonp/projects/etc/main.go:25 +0x4e
created by main.main
/Users/shimonp/projects/etc/main.go:12 +0x6e
goroutine 1 [runnable]:
main.main()
/Users/shimonp/projects/etc/main.go:12 +0x8f
goroutine 17 [runnable]:
main.mapWriter(0xc0000547b8?)
/Users/shimonp/projects/etc/main.go:18 +0x6c
created by main.main
/Users/shimonp/projects/etc/main.go:8 +0x65
- because logCancel is a child-context of
ctx- it will be cancelled if the parent is cancelled. I don't want to put it in adefer, because, as mentioned in point 1 - I think we need to synchronously wait for the priodiclogger to finish.
Agree is a far-fetched race, but AFAIU it can definitly happen, so I'd rather err on the side of "no races in the code".
- Logs very basic stats about the sync every 30 seconds. - Used `ctx` and a new waitgroup - because it's importat to shut it down gracefully (concurrent map read-writes are dangerous in golang). - Used `TotalResourcesAtomic` - see this stackoverflow answer: https://stackoverflow.com/a/46557083
yevgenypats
approved these changes
Dec 24, 2022
Contributor
yevgenypats
left a comment
There was a problem hiding this comment.
Not sure I understood the write-up on the race condition but this looks fine to me now once it moved to the right place.
kodiakhq bot
pushed a commit
that referenced
this pull request
Dec 27, 2022
🤖 I have created a release *beep* *boop* --- ## [1.14.0](v1.13.1...v1.14.0) (2022-12-27) ### Features * Add basic periodic metric INFO logger ([#496](#496)) ([8d1d32e](8d1d32e)) ### Bug Fixes * **destinations:** Stop writing resources when channel is closed ([#460](#460)) ([5590845](5590845)) * Don't hide errors in destination server ([#529](#529)) ([d91f94f](d91f94f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ctxand a new waitgroup - because it's importat to shut it down gracefully (concurrent map read-writes are dangerous in golang).TotalResourcesAtomic- see this stackoverflow answer: https://stackoverflow.com/a/46557083