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

Add a listener to capture task execution in shardConsumer #417

Merged
merged 4 commits into from
Oct 10, 2018

Conversation

akhani18
Copy link
Contributor

Issue #, if available:

Description of changes:

  • Add a TaskExecutionListener as part of LifecycleConfig that can be used by all ShardConsumers in a Scheduler to issue notifications about beginning and ending of a task execution
  • Provide a default NoOp task execution listener
  • Update ShardConsumer constructor to take an instance TaskExecutionListener
  • Update executeTask method to issue n onTaskBegin and onTaskEnd notification to any listener providing ShardInfo and the current state the shard is in.
  • Update ShardConsumerTest to validate all interactions with taskExecutionListener

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

/**
* Empty constructor for NoOp Shard Prioritization.
*/
public NoOpTaskExecutionListener() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to have the empty constructor. Could you remove the empty lines between the brackets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this(recordsPublisher, executorService, shardInfo, logWarningForTaskAfterMillis, shardConsumerArgument,
ConsumerStates.INITIAL_STATE,
taskExecutionListener, ConsumerStates.INITIAL_STATE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for changing the order for the chained constructor? If not could you add the new parameter to the end of the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mainly, I just wanted to avoid adding a reference type (TaskExecutionListener) after a primitive type (int bufferSize) in the constructor as it didn't look aesthetically pleasing.
But I'm fine with adding this new argument to the end of the list.
Why would you not want to use builder pattern for the constructor here?

@sahilpalvia sahilpalvia added the v2.x Issues related to the 2.x version label Sep 21, 2018
@@ -392,6 +397,7 @@ private synchronized void executeTask(ProcessRecordsInput input) {
}
taskOutcome = resultToOutcome(result);
}
taskExecutionListener.onTaskEnd(currentState, shardInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

  • What happens when task.call() throws exception? Not call onTaskEnd? Is it safe to assume that task is never going to throw exception?
  • Is there a scenario where only onTaskEnd/Begin() is called or called out of order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Documentation on ConsumerTask.java says that any exception during task.call() will be captured in TaskResult, returned by task.call(). I also looked at all *.Task classes to confirm that, so it would be safe to assume that it won't throw exception and onTaskBegin will always be accompanied by onTaskEnd in all known cases.

  • onTaskBegin and onTaskEnd should always be called in the same order.


void onTaskBegin(ConsumerState state, ShardInfo shardInfo);

void onTaskEnd(ConsumerState state, ShardInfo shardInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a third argument, TaskOutcome ? Task Execution related metrics, like time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TaskOutcome - Sure, as suggested by @sahilpalvia I'm going to create a data class and I can include things like ShardInfo, TaskType, TaskOutcome in it. Task execution time can be implicitly calculated on the client side by looking at the delta between onTaskBegin and onTaskEnd.

*/
public interface TaskExecutionListener {

void onTaskBegin(ConsumerState state, ShardInfo shardInfo);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a function header ? explicitly stating that concrete implementation should not make remote service calls and therefore should not block the task execution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added that to the class header because it applies to both methods of the class.

Copy link
Contributor

@shask-amazon shask-amazon left a comment

Choose a reason for hiding this comment

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

General feedback on interface and integration

Copy link
Contributor

@sahilpalvia sahilpalvia left a comment

Choose a reason for hiding this comment

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

Few more changes needed. Thanks for providing this.

@pfifer pfifer added this to the v2.0.4 milestone Oct 9, 2018
Copy link
Contributor

@sahilpalvia sahilpalvia left a comment

Choose a reason for hiding this comment

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

Thanks for providing this.

@sahilpalvia
Copy link
Contributor

Could you updated the branch to avoid merge conflicts.

@pfifer
Copy link
Contributor

pfifer commented Oct 10, 2018

Thanks for providing this.

Can please resolve the conflicts and push and update to the PR?

@akhani18
Copy link
Contributor Author

I fixed the merge conflict here itself in the github UI and looks like the checks have passed. Is that sufficient?

@pfifer pfifer merged commit 2609e1c into awslabs:master Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2.x Issues related to the 2.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants