-
Notifications
You must be signed in to change notification settings - Fork 7
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 thinSnaps #1105
Fix thinSnaps #1105
Conversation
Pull Request Test Coverage Report for Build 7420
💛 - Coveralls |
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.
Reviewable status:
complete! 1 of 1 approvals obtained
// Guarantee that FinalSnapshot matches the last raw snapshot. | ||
if diff := deep.Equal(row.A.FinalSnapshot, row.Raw.Snapshots[len(row.Raw.Snapshots)-1]); diff != nil { | ||
t.Errorf("TestTCPParser.ParseAndInsert() FinalSnapshot and last snapshot differ: %s", strings.Join(diff, "\n")) | ||
} |
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.
Ah, nice, I think this is a very good way to test this. I had one additional thought:
Maybe we should check that the number of thinned snapshots is correct (per row, not in summary as before)?
If it helps, the expected number of thinned snapshots is: 2 + math.floor((len(row.Raw.Snapshots) - 2) / 10)
, i.e. the first and last element are always included, and every tenth other element.
N.B.: I am not 100% sure how thinSnaps behaves when raw.Snapshots is only 1 element long. Will this element be duplicated? It should not happen, but I am not 100% sure.
func thinSnaps(orig []snapshot.Snapshot) []snapshot.Snapshot { | ||
n := len(orig) | ||
if n == 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.
Regarding this comment: I am not 100% sure how thinSnaps behaves when the list has only one element.
Theoretically, the for loop should not do anything, as for i=0
and n=1
the condition i < n-1
is false, but maybe it's worth checking?
To be super safe, one could change the initial check I am commenting here to if n<=2
. I.e. the first and last element are always included (or the single element, if there is only one); and only if we have more than two elements, we apply the thinning logic.
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've added an explicit test for the thinSnaps
function with edge case conditions. I like your first implementation (handling the last element unconditionally for all lengths). The tests should give us much more confidence that this behavior is correct.
The same test cases (correctly) fail for the original (buggy) implementation of thinSnaps
.
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @NotSpecial)
parser/tcpinfo_test.go
line 176 at r1 (raw file):
Previously, NotSpecial (Alexander Dietmüller) wrote…
Ah, nice, I think this is a very good way to test this. I had one additional thought:
Maybe we should check that the number of thinned snapshots is correct (per row, not in summary as before)?
If it helps, the expected number of thinned snapshots is:
2 + math.floor((len(row.Raw.Snapshots) - 2) / 10)
, i.e. the first and last element are always included, and every tenth other element.N.B.: I am not 100% sure how thinSnaps behaves when raw.Snapshots is only 1 element long. Will this element be duplicated? It should not happen, but I am not 100% sure.
I like this idea. Unfortunately, this information (true snapshot length) is not available to the unit test currently. Though this feels like an oversight for data usage also. I can imagine the A
record could include some additional summary information like TotalSnaps
or SnapCount
or SnapshotLength
or similar to indicate that the len(raw.Snapshots)
is not expected to be equal to the total snapshots due to the thinning... Today there is nothing to indicate this explicitly. But, this changes the scope of this change from a bug fix to a schema change...
Would you accept an open issue for more metadata to be added in the future?
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.
Looking good to me, the explicit test is useful!
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.
Thank you!
Reviewable status:
complete! 1 of 1 approvals obtained (waiting on @NotSpecial)
parser/tcpinfo_test.go
line 176 at r1 (raw file):
Previously, stephen-soltesz (Stephen Soltesz) wrote…
I like this idea. Unfortunately, this information (true snapshot length) is not available to the unit test currently. Though this feels like an oversight for data usage also. I can imagine the
A
record could include some additional summary information likeTotalSnaps
orSnapCount
orSnapshotLength
or similar to indicate that thelen(raw.Snapshots)
is not expected to be equal to the total snapshots due to the thinning... Today there is nothing to indicate this explicitly. But, this changes the scope of this change from a bug fix to a schema change...Would you accept an open issue for more metadata to be added in the future?
Created #1106
The parser updated with this fix was deployed to staging around 2022-10-18 20:20:00 - parse times after that have FinalSnapshot and last Snapshots with matching timestamps (
After deployment to production the historical reprocessing will take about 16 days to cover all dates. Daily data will be update daily. |
This change completes fixes the bug reported by @NotSpecial - #1104 with an update to the unit test to check that every
FinalSnapshot
matches the last snapshot of the raw, thinned snapshots.This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)