-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding more logging around the rejected task executions at the Schedu…
…ler and RxJava layer (#559) * Add diagnostic events for logging visibility * Refactor logging diagnostics into main Scheduler loop * Refactor log timing and level and change privacies * Revert ExecutorStateEvent to accept ExecutorService input type * Minor style and messaging fixes * Fix failing unit test * Refactor diagnostic events to use factory for testing * Fix constructor overloading for testing * Refactor DiagnosticEventHandler to no args constructor
- Loading branch information
1 parent
6159b86
commit fa72cf1
Showing
9 changed files
with
524 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
amazon-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEvent.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
/** | ||
* An interface to implement various types of stateful events that can be used for diagnostics throughout the KCL. | ||
*/ | ||
interface DiagnosticEvent { | ||
/** | ||
* DiagnosticEvent is part of a visitor pattern and it accepts DiagnosticEventHandler visitors. | ||
* | ||
* @param visitor A handler that that controls the behavior of the DiagnosticEvent when invoked. | ||
*/ | ||
void accept(DiagnosticEventHandler visitor); | ||
|
||
/** | ||
* The string to output to logs when a DiagnosticEvent occurs. | ||
*/ | ||
String message(); | ||
} |
35 changes: 35 additions & 0 deletions
35
...esis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventFactory.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
import lombok.NoArgsConstructor; | ||
import software.amazon.kinesis.leases.LeaseCoordinator; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
|
||
/** | ||
* Creates {@link DiagnosticEvent}s for logging and visibility | ||
*/ | ||
@NoArgsConstructor | ||
class DiagnosticEventFactory { | ||
ExecutorStateEvent executorStateEvent(ExecutorService executorService, LeaseCoordinator leaseCoordinator) { | ||
return new ExecutorStateEvent(executorService, leaseCoordinator); | ||
} | ||
|
||
RejectedTaskEvent rejectedTaskEvent(ExecutorStateEvent executorStateEvent, Throwable t) { | ||
return new RejectedTaskEvent(executorStateEvent, t); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...esis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventHandler.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
/** | ||
* An interface to implement behaviors associated with a {@link DiagnosticEvent}. Uses the visitor pattern to visit | ||
* the DiagnosticEvent when the behavior is desired. A default implementation that performs simple logging is found in | ||
* {@link DiagnosticEventLogger}. | ||
*/ | ||
interface DiagnosticEventHandler { | ||
/** | ||
* @param event Log or otherwise react to periodic pulses on the thread pool executor state. | ||
*/ | ||
void visit(ExecutorStateEvent event); | ||
|
||
/** | ||
* @param event Log or otherwise react to rejected tasks in the RxJavaPlugin layer. | ||
*/ | ||
void visit(RejectedTaskEvent event); | ||
} |
55 changes: 55 additions & 0 deletions
55
...nesis-client/src/main/java/software/amazon/kinesis/coordinator/DiagnosticEventLogger.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import software.amazon.kinesis.annotations.KinesisClientInternalApi; | ||
|
||
/** | ||
* Internal implementation of {@link DiagnosticEventHandler} used by {@link Scheduler} to log executor state both | ||
* 1) in normal conditions periodically, and 2) in reaction to rejected task exceptions. | ||
*/ | ||
@NoArgsConstructor | ||
@Slf4j | ||
@KinesisClientInternalApi | ||
class DiagnosticEventLogger implements DiagnosticEventHandler { | ||
private static final long EXECUTOR_LOG_INTERVAL_MILLIS = 30000L; | ||
private long nextExecutorLogTime = System.currentTimeMillis() + EXECUTOR_LOG_INTERVAL_MILLIS; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* Only log at info level every 30s to avoid over-logging, else log at debug level | ||
*/ | ||
@Override | ||
public void visit(ExecutorStateEvent event) { | ||
if (System.currentTimeMillis() >= nextExecutorLogTime) { | ||
log.info(event.message()); | ||
nextExecutorLogTime = System.currentTimeMillis() + EXECUTOR_LOG_INTERVAL_MILLIS; | ||
} else { | ||
log.debug(event.message()); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void visit(RejectedTaskEvent event) { | ||
log.error(event.message(), event.getThrowable()); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/ExecutorStateEvent.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.extern.slf4j.Slf4j; | ||
import software.amazon.kinesis.annotations.KinesisClientInternalApi; | ||
import software.amazon.kinesis.leases.LeaseCoordinator; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
@Getter | ||
@ToString(exclude = "isThreadPoolExecutor") | ||
@Slf4j | ||
@KinesisClientInternalApi | ||
class ExecutorStateEvent implements DiagnosticEvent { | ||
private static final String MESSAGE = "Current thread pool executor state: "; | ||
|
||
private boolean isThreadPoolExecutor; | ||
private String executorName; | ||
private int currentQueueSize; | ||
private int activeThreads; | ||
private int coreThreads; | ||
private int leasesOwned; | ||
private int largestPoolSize; | ||
private int maximumPoolSize; | ||
|
||
ExecutorStateEvent(ExecutorService executor, LeaseCoordinator leaseCoordinator) { | ||
if (executor instanceof ThreadPoolExecutor) { | ||
this.isThreadPoolExecutor = true; | ||
|
||
ThreadPoolExecutor ex = (ThreadPoolExecutor) executor; | ||
this.executorName = ex.getClass().getSimpleName(); | ||
this.currentQueueSize = ex.getQueue().size(); | ||
this.activeThreads = ex.getActiveCount(); | ||
this.coreThreads = ex.getCorePoolSize(); | ||
this.largestPoolSize = ex.getLargestPoolSize(); | ||
this.maximumPoolSize = ex.getMaximumPoolSize(); | ||
} | ||
|
||
this.leasesOwned = leaseCoordinator.getAssignments().size(); | ||
} | ||
|
||
@Override | ||
public void accept(DiagnosticEventHandler visitor) { | ||
// logging is only meaningful for a ThreadPoolExecutor executor service (default config) | ||
if (isThreadPoolExecutor) { | ||
visitor.visit(this); | ||
} | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return MESSAGE + this.toString(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...n-kinesis-client/src/main/java/software/amazon/kinesis/coordinator/RejectedTaskEvent.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. | ||
* Licensed under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package software.amazon.kinesis.coordinator; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.extern.slf4j.Slf4j; | ||
import software.amazon.kinesis.annotations.KinesisClientInternalApi; | ||
|
||
@Getter | ||
@ToString | ||
@Slf4j | ||
@KinesisClientInternalApi | ||
class RejectedTaskEvent implements DiagnosticEvent { | ||
private static final String MESSAGE = "Review your thread configuration to prevent task rejections. " + | ||
"Until next release, KCL will not be resilient to task rejections. "; | ||
|
||
private ExecutorStateEvent executorStateEvent; | ||
private Throwable throwable; | ||
|
||
RejectedTaskEvent(ExecutorStateEvent executorStateEvent, Throwable throwable) { | ||
this.executorStateEvent = executorStateEvent; | ||
this.throwable = throwable; | ||
} | ||
|
||
@Override | ||
public void accept(DiagnosticEventHandler visitor) { | ||
visitor.visit(this); | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return MESSAGE + executorStateEvent.message(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.