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

MIGRATIONS-1294: Improve remaining space checks for Capture Proxy #286

Merged
merged 3 commits into from
Aug 25, 2023

Conversation

lewijacn
Copy link
Collaborator

Description

This change primarily ensures that every observation we attempt to add to a TrafficStream performs a space check of the CodedOuputStream initially to ensure that there is ample space to store the observation and a closing index, or otherwise flush the stream so that space is available.

Beyond this, there is also some cleaning up of EndOfSegmentIndication size calculations as this will now be handled by the observation size check. As well as general naming and structuring to make things a bit cleaner and easier to follow.

Issues Resolved

https://opensearch.atlassian.net/browse/MIGRATIONS-1294

Testing

Unit testing and manual docker testing

Check List

  • New functionality includes testing
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@codecov
Copy link

codecov bot commented Aug 24, 2023

Codecov Report

Merging #286 (e341e04) into main (4165dc4) will increase coverage by 0.22%.
Report is 6 commits behind head on main.
The diff coverage is 86.66%.

@@             Coverage Diff              @@
##               main     #286      +/-   ##
============================================
+ Coverage     61.93%   62.16%   +0.22%     
- Complexity      617      620       +3     
============================================
  Files            82       82              
  Lines          3129     3137       +8     
  Branches        292      292              
============================================
+ Hits           1938     1950      +12     
+ Misses         1014     1011       -3     
+ Partials        177      176       -1     
Flag Coverage Δ
unittests 62.16% <86.66%> (+0.22%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...ture/StreamChannelConnectionCaptureSerializer.java 82.32% <82.60%> (+3.12%) ⬆️
...ions/trafficcapture/CodedOutputStreamSizeUtil.java 81.25% <100.00%> (+1.25%) ⬆️
.../opensearch/migrations/replay/TrafficReplayer.java 6.75% <100.00%> (-0.42%) ⬇️

Copy link
Collaborator

@gregschohn gregschohn left a comment

Choose a reason for hiding this comment

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

Approved with comments

* This function determines the number of bytes needed to store a TrafficObservation and a closing index for a
* TrafficStream, from the provided input.
*/
public static int bytesNeededForObservationAndClosingIndex(int observationContentSize, int flushes) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It took me a couple minutes to understand why you cared about (the number of) "flushes". Can you rename this to something like numberOfTrafficStreamsSoFar or something similar. When I think of flush, I don't necessarily think of it as having an observable side effect like what you're looking for.

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 adjusted

@@ -32,7 +32,7 @@
* into the defined Protobuf format {@link org.opensearch.migrations.trafficcapture.protos.TrafficStream}, and then write
* this formatted data to the provided CodedOutputStream.
*
* Commented throughout the class are example markers such as (i.e. 1: "1234ABCD") which line up with the textual
* Commented throughout the class are example markers such as (e.g. 1: "1234ABCD") which line up with the textual
Copy link
Collaborator

Choose a reason for hiding this comment

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

lol - you're right. thanks for correcting the abbreviations :)

Comment on lines 128 to 129
if (getOrCreateCodedOutputStream().spaceLeft() < CodedOutputStreamSizeUtil.bytesNeededForObservationAndClosingIndex(
observationContentSize, numFlushesSoFar + 1)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please reformat this? This is the hardest to read line break I've seen in a long while. Maybe break after '<' and/or put the brace on the next line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah this came out a bit ugly, should be a good bit clearer to read now

@@ -155,14 +156,41 @@ public void testBasicDataConsistencyWhenChunking() throws IOException, Execution
Assertions.assertEquals(packetData, reconstructedData);
}

@Test
public void testCloseAfterWriteWillFlushWhenSpaceNeeded() throws IOException, ExecutionException, InterruptedException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: "testCloseObservation..." would be clearer. Sounds like you might have meant to close a stream

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adjusted

@lewijacn lewijacn merged commit f1584f7 into opensearch-project:main Aug 25, 2023
3 checks passed
@lewijacn lewijacn deleted the proxy-space-checks branch March 29, 2024 17:16
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.

2 participants