Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Implement cool off handling for the Publisher #272

Merged

Conversation

sidheart
Copy link
Contributor

Issue #, if available: N/A

Description of changes:
The Publisher shouldn't spam the same action over and over again. It
should wait for a specified period of time before repeating an action.

This commit implements this logic.

Tests: PublisherTest

Code coverage percentage for this patch: See CodeCov Report

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The Publisher shouldn't spam the same action over and over again. It
should wait for a specified period of time before repeating an action.

This commit implements this logic.
@codecov
Copy link

codecov bot commented Jul 14, 2020

Codecov Report

Merging #272 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #272      +/-   ##
============================================
+ Coverage     66.33%   66.35%   +0.02%     
- Complexity     1795     1799       +4     
============================================
  Files           270      270              
  Lines         11990    12002      +12     
  Branches        952      954       +2     
============================================
+ Hits           7953     7964      +11     
+ Misses         3722     3721       -1     
- Partials        315      317       +2     
Impacted Files Coverage Δ Complexity Δ
...cisionmaker/actions/ModifyQueueCapacityAction.java 86.48% <100.00%> (ø) 15.00 <1.00> (ø)
...anceanalyzer/decisionmaker/deciders/Publisher.java 85.18% <100.00%> (+51.85%) 8.00 <3.00> (+6.00)
...asticsearch/performanceanalyzer/net/NetClient.java 67.24% <0.00%> (-8.63%) 10.00% <0.00%> (-1.00%)
...nalyzer/rca/net/handler/PublishRequestHandler.java 67.50% <0.00%> (-5.00%) 5.00% <0.00%> (ø%)
...csearch/performanceanalyzer/rca/RcaController.java 79.37% <0.00%> (-2.50%) 34.00% <0.00%> (-2.00%)
...o/elasticsearch/performanceanalyzer/core/Util.java 70.83% <0.00%> (+8.33%) 5.00% <0.00%> (ø%)
...analyzer/decisionmaker/deciders/EmptyFlowUnit.java 66.66% <0.00%> (+66.66%) 1.00% <0.00%> (+1.00%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 46f8c15...f13f105. Read the comment docs.

@sidheart sidheart requested a review from vigyasharma July 14, 2020 09:16
Copy link
Contributor

@vigyasharma vigyasharma left a comment

Choose a reason for hiding this comment

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

Changes look good, thanks!

@@ -30,7 +30,7 @@
public class ModifyQueueCapacityAction implements Action {

public static final String NAME = "modify_queue_capacity";
public static final int COOL_OFF_PERIOD_IN_SECONDS = 300;
public static final long COOL_OFF_PERIOD_IN_MILLIS = 300 * 1_000;
Copy link
Contributor

Choose a reason for hiding this comment

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

can we set this in rca.conf and make this configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, but out of scope for this commit. The only reason I changed this line is that we're going from s units to ms

}

return new EmptyFlowUnit(System.currentTimeMillis());
return new EmptyFlowUnit(Instant.now().toEpochMilli());
Copy link
Contributor

Choose a reason for hiding this comment

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

any specific reason to replace system with Instant.now() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


private Collator collator;
private boolean isMuted = false;
private Map<String, Long> actionToExecutionTime;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use Action itself as the key ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but we'd have to implement hashCode() and equals() for all Actions. I asked Vigya, and he said it was a safe assumption that Action names are unique, so it should suffice as a key.

if (elapsed >= action.coolOffPeriodInMillis()) {
return true;
} else {
LOG.debug("Action {} still has {} ms left in its cool off period", action.name(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep the logging format consistent within RCA package. Let's add the "Publisher: " at the front of this log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm against this because it's an anti-pattern in the log4j context. If we want to include class info in logging lines we should update our logging pattern to include %c{1.} for example. See https://logging.apache.org/log4j/2.x/manual/layouts.html

Does anyone else have thoughts on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this in for now

LOG.info("Executing action: [{}]", action.name());
action.execute();
if (isCooledOff(action)) { // Only execute actions which have passed their cool off period
LOG.info("Executing action: [{}]", action.name());
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also same as above, I'd like to hear people's thoughts on this

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

@@ -18,33 +18,65 @@
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions.Action;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.NonLeafNode;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.scheduler.FlowUnitOperationArgWrapper;

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@sidheart sidheart requested a review from rguo-aws July 17, 2020 18:02
@sidheart sidheart merged commit dbd8675 into opendistro-for-elasticsearch:master Jul 21, 2020
@sidheart sidheart deleted the publisher-cooloff branch July 21, 2020 17:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants