-
Notifications
You must be signed in to change notification settings - Fork 35
Avoid race conditions when handling data #570
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
08c637f
apmproxy: do not continue without APMData
florianl 3dd9980
apmproxy: set channel only once
florianl 9fd0886
accumulator: add test for call to AddAgentData without data
florianl b383cda
fixup: fix linter
florianl e9cde49
fixup: add AgentInfo to debug message
florianl 4fb0bc5
fixup: use capital letter in debug message
florianl 18191d7
receiver: avoid allocation if rawBytes is empty
florianl 7330f87
fixup: check len() first before calling function
florianl bd59d4a
fixup: update comment
florianl 1763b69
fixup: replace sync.Once with nil check
florianl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this, no data is not an error for the batch and I don't like returning no data errors. Now that we have already handled no data case in
ForwardAPMData
, can we remove this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is your suggestion to return for the
len(apmData.Data) == 0
case inAddAgentData()
?Just because there is a check in
ForwardAPMData()
does not prevent other users ofAddAgentData()
running into this issue.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that for the batch having an empty data is not an error. The batch can just not add data in this case. If we want to protect against edge cases we should do it at the source (like how we do in
ForwardAPMData
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we want to be more specific in handling the behaviour, we could introduce another method in the batch to check the metadata status, something like
bool HasMetadata()
and incorporate it where we require such a check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still consider the use case
len(apmData.Data) == 0
inAddAgentData()
dangerous even if the only caller atm ™️ is using a check. What makes this package and its API safe to use, if something else callsAddAgentData()
?Even if no data is considered a non error case, what should it be considered instead and how should it be treated? With the current behavior it seems to run into issues.
If
AddAgentData()
implements such a check, what should be returned in a case wherelen(apmData.Data) != 0
. Is in this case data loss the expected result?len(apmData.Data) == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agent data here refers to data from the APM agents and intake-v2 is the only supported protocol. What other cases do you have in mind here?
If data from the agent is not nil then it MUST have the metadata as the first line.
apmData.Data
is including the metadata so this is also not possible. We could have only metadata in the body and that is okay.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lahsivjar So essentially in your view,
ErrNoData
and associated logic is redundant as "no data" can take place during normal operation, and if we want to check for this case, we should do it before callingAddAgentData
. Is that correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, yes! I don't have a strong opinion here so feel free to ignore it.