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

NETOBSERV-334 concurrent map iteration & write fix #226

Merged
merged 2 commits into from
Jun 13, 2022

Conversation

jpinsonneau
Copy link
Collaborator

This fix fatal error: concurrent map iteration and map write when calling stdout and loki stages in parallel

Comment on lines 123 to 131
func (m GenericMap) Copy() map[string]interface{} {
result := map[string]interface{}{}

for k, v := range m {
result[k] = v
}

return result
}
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 do a simple flat copy here for performances purpose but we can implement a deep copy if needed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this function be here or in utils?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@KalmanMeth @jpinsonneau I had the same thought .... maybe the right thing to do is open a new GenericMap.go file

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 can move this 👍

Does a new file generic_map.go in config folder is ok for both of you ? @KalmanMeth @eranra

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -118,3 +118,14 @@ func ParseConfig() error {
logrus.Debugf("params = %v ", Parameters)
return nil
}

// Copy will create a flat copy of GenericMap
func (m GenericMap) Copy() map[string]interface{} {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the input and output be both GenericMap ???

i.e. s/ map[string]interface{} / GenericMap

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sounds good 👍

@@ -231,7 +231,8 @@ func (l *Loki) processRecords() {
log.Debugf("exiting writeLoki because of signal")
return
case record := <-l.in:
err := l.ProcessRecord(record)
// copy record before process to avoid alteration on parallel stages
err := l.ProcessRecord(record.Copy())
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jpinsonneau I suggest moving the copy process to be inside the ProcessRecord function --- the rule should be that we are not allowed to change the inputs --- and we need to maybe check also in other places that we are not doing that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

@eranra When we add fields to enrich the reporting we change the records.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@KalmanMeth ... so should we add copy also there ??? do you want to open a PR for that?

Copy link
Collaborator

@eranra eranra left a comment

Choose a reason for hiding this comment

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

Some suggestions for improvement but from my PoV this can merge as-is. so LGTM

@jpinsonneau jpinsonneau merged commit ddba882 into netobserv:main Jun 13, 2022
@jpinsonneau
Copy link
Collaborator Author

Thank you all for the feedback 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants