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

Added support for timeout millis, refactored unit tests to createObje… #449

Merged

Conversation

graytaylor0
Copy link
Member

Description

  • Support added for timeoutMillis. Processing/Matching for each individual Record will time out if it takes longer than the configured timeout. timeoutMillis set to 0 will result in no timeout.
  • Refactored unit tests to use the createObjectUnderTest structure. Unit tests now utilize a package private constructor that takes an instance of a GrokCompiler and an ExecutorService. This made the unit tests cleaner and easier to write because MockedStatic was no longer required

Issues Resolved

Closes #345

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • 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.

recordsOut.add(record);
} catch (ExecutionException e) {
LOG.error("An exception occurred while matching on record [{}]", record.getData(), e);
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this came from IntelliJ's auto-complete. We should never be calling printStackTrace(). The line above will print it to the logger just fine.

} else {
mergeCaptures(recordMap, grokkedCaptures);
final Runnable matchTimeoutRunnable = () -> matchAndMerge(recordMap);
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to put the lambda directly in runWithTimeout to remove this extra variable. And it is somewhat more common to see lambdas passed into methods.

dlvenable
dlvenable previously approved these changes Oct 20, 2021
}

@Override
public boolean isReadyForShutdown() {
try {
if (executorService.awaitTermination(grokPrepperConfig.getTimeoutMillis(), TimeUnit.MILLISECONDS)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we couple the grok prepper timeout with the executorService shutdown? How long does this shutdown typically take? Do we want users to be able to control this timeout?

Copy link
Member Author

@graytaylor0 graytaylor0 Oct 20, 2021

Choose a reason for hiding this comment

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

This is a valid point, especially given that the timeoutMillis can be 0, which would mess up this implementation. What value makes the most sense here? 100 ms? 1 second?

Copy link
Member Author

Choose a reason for hiding this comment

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

A couple hundred ms seems fine to me at this time.


private void runWithTimeout(final Runnable runnable) throws TimeoutException, ExecutionException, InterruptedException {
Future<?> task = executorService.submit(runnable);
task.get(grokPrepperConfig.getTimeoutMillis(), TimeUnit.MILLISECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should update the READMe with this configuration options now that we are using it.

@@ -45,9 +45,13 @@ TODO: provide examples for using each configuration

* `target_key` (Optional): A `String` that will wrap all captures for a Record in an additional outer key value. Default value is `null`


* `timeout_millis` (Optional): An `int` that specifies the maximum amount of time, in milliseconds, that matching will be performed on an individual Record before it times out and moves on to the next Record.
Setting a `timeout_millis = 0` will make it so that matching a Record never times out. Default value is `30,000`
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be simplified: "Setting a timeout_millis = 0 will disable this feature. Default value is 30,000"

@graytaylor0 graytaylor0 merged commit 4228f54 into opensearch-project:main Oct 20, 2021
jianghancn pushed a commit to jianghancn/data-prepper that referenced this pull request Oct 27, 2021
opensearch-project#449)

* Added support for timeout millis, refactored unit tests to createObjectUnderTest structure

Signed-off-by: Taylor Gray <[email protected]>

* remove redundant e.printStackTrace() and pass lambda directly to runWithTimeout

Signed-off-by: Taylor Gray <[email protected]>

* Update README to include timeoutmillis, removed timeoutMillis from awaitTermination

Signed-off-by: Taylor Gray <[email protected]>
@graytaylor0 graytaylor0 deleted the GrokPrepperTimeoutMillis branch November 1, 2021 21:45
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.

Grok Prepper Match Timeout
3 participants