This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch master into new_mainline
Changes for 1 package (OpenDistroPerformanceAnalyzerEngine), pushed in snapshot... https://code.amazon.com/snapshots/partsrut/2020-08-08T02-49-04 Changes for OpenDistroPerformanceAnalyzerEngine package: 0194f9f Fix failing reaction wheel tests bfdb93d Merge remote-tracking branch 'upstream/master' e03a120 Use StringUtils instead of NumberUtils to check timestamp string (#360) 79841f2 Expose queue rejection time period setting in rca.conf (#356) f9dfda5 Implement isMuted method in DummyAction (#355) 7ede0b9 Reader changes for dynamic enable/disable of RCA graph components (#325) ee58207 Fix bug in publisher to support cool off period on a per node basis (#351) cr https://code.amazon.com/reviews/CR-31344155
- Loading branch information
Showing
51 changed files
with
1,442 additions
and
199 deletions.
There are no files selected for viewing
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
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
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
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
130 changes: 130 additions & 0 deletions
130
...opendistro/elasticsearch/performanceanalyzer/config/overrides/ConfigOverridesApplier.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,130 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 com.amazon.opendistro.elasticsearch.performanceanalyzer.config.overrides; | ||
|
||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterDetailsEventProcessor; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* Class the manages applying the various overrides for RCAs, deciders, and action nodes as | ||
* written by the NodeDetails collector and read by the {@link ClusterDetailsEventProcessor} | ||
*/ | ||
public class ConfigOverridesApplier { | ||
|
||
private static final Logger LOG = LogManager.getLogger(ConfigOverridesApplier.class); | ||
private long lastAppliedTimestamp; | ||
|
||
public void applyOverride(final String overridesJson, final String lastUpdatedTimestampString) { | ||
if (!valid(overridesJson, lastUpdatedTimestampString)) { | ||
LOG.warn("Received invalid overrides or timestamp. Overrides json: {}, last updated " | ||
+ "timestamp: {}", overridesJson, lastAppliedTimestamp); | ||
return; | ||
} | ||
|
||
try { | ||
long lastUpdatedTimestamp = Long.parseLong(lastUpdatedTimestampString); | ||
LOG.debug("Last updated(writer): {}, Last applied(reader): {}", lastUpdatedTimestamp, | ||
lastAppliedTimestamp); | ||
if (lastUpdatedTimestamp > lastAppliedTimestamp) { | ||
apply(ConfigOverridesHelper.deserialize(overridesJson)); | ||
} else { | ||
LOG.debug("Not applying override. Last updated timestamp {} is behind last applied " | ||
+ "timestamp {}", lastUpdatedTimestamp, lastAppliedTimestamp); | ||
} | ||
} catch (IOException ioe) { | ||
LOG.error("Unable to deserialize overrides JSON:" + overridesJson, ioe); | ||
} catch (NumberFormatException nfe) { | ||
LOG.error("Unable to parse the lastUpdatedTimestamp {} string as a number.", | ||
lastUpdatedTimestampString, nfe); | ||
} | ||
} | ||
|
||
private void apply(final ConfigOverrides overrides) { | ||
if (PerformanceAnalyzerApp.getRcaController() != null && PerformanceAnalyzerApp.getRcaController().isRcaEnabled()) { | ||
LOG.info("Applying overrides: {}", overrides.getEnable().getRcas()); | ||
RcaConf rcaConf = PerformanceAnalyzerApp.getRcaController().getRcaConf(); | ||
if (rcaConf != null) { | ||
Set<String> currentMutedRcaSet = new HashSet<>(rcaConf.getMutedRcaList()); | ||
Set<String> currentMutedDeciderSet = new HashSet<>(rcaConf.getMutedDeciderList()); | ||
Set<String> currentMutedActionSet = new HashSet<>(rcaConf.getMutedActionList()); | ||
// check and remove any nodes that are in the disabled list that were enabled just now. | ||
if (overrides.getEnable() != null) { | ||
if (overrides.getEnable().getRcas() != null) { | ||
currentMutedRcaSet.removeAll(overrides.getEnable().getRcas()); | ||
} | ||
if (overrides.getEnable().getDeciders() != null) { | ||
currentMutedDeciderSet.removeAll(overrides.getEnable().getDeciders()); | ||
} | ||
if (overrides.getEnable().getActions() != null) { | ||
currentMutedActionSet.removeAll(overrides.getEnable().getActions()); | ||
} | ||
} | ||
|
||
// union the remaining already disabled nodes with the new set of disabled nodes. | ||
if (overrides.getDisable() != null) { | ||
if (overrides.getDisable().getRcas() != null) { | ||
currentMutedRcaSet.addAll(overrides.getDisable().getRcas()); | ||
} | ||
if (overrides.getDisable().getDeciders() != null) { | ||
currentMutedDeciderSet.addAll(overrides.getDisable().getDeciders()); | ||
} | ||
if (overrides.getDisable().getActions() != null) { | ||
currentMutedActionSet.addAll(overrides.getDisable().getActions()); | ||
} | ||
} | ||
|
||
LOG.info("New set of muted rcas: {}", currentMutedRcaSet); | ||
LOG.info("New set of muted deciders: {}", currentMutedDeciderSet); | ||
LOG.info("New set of muted actions: {}", currentMutedActionSet); | ||
boolean updateSuccess = rcaConf.updateAllRcaConfFiles(currentMutedRcaSet, | ||
currentMutedDeciderSet, currentMutedActionSet); | ||
if (updateSuccess) { | ||
this.lastAppliedTimestamp = System.currentTimeMillis(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private boolean valid(final String overridesJson, final String timestamp) { | ||
if (overridesJson == null || timestamp == null) { | ||
return false; | ||
} | ||
|
||
if (overridesJson.isEmpty() || timestamp.isEmpty()) { | ||
return false; | ||
} | ||
|
||
return StringUtils.isNumeric(timestamp); | ||
} | ||
|
||
@VisibleForTesting | ||
public long getLastAppliedTimestamp() { | ||
return lastAppliedTimestamp; | ||
} | ||
|
||
@VisibleForTesting | ||
public void setLastAppliedTimestamp(final long lastAppliedTimestamp) { | ||
this.lastAppliedTimestamp = lastAppliedTimestamp; | ||
} | ||
} |
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
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
127 changes: 127 additions & 0 deletions
127
...n/opendistro/elasticsearch/performanceanalyzer/decisionmaker/actions/CoolOffDetector.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,127 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions; | ||
|
||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.NodeKey; | ||
import com.google.common.annotations.VisibleForTesting; | ||
import java.time.Clock; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.commons.lang3.builder.HashCodeBuilder; | ||
|
||
/** | ||
* Detect whether an action has passed its cool off period or not. Due to the heterogeneous nature of | ||
* Decision Maker framework, this CoolOffDetector needs to keep track of the latest execution timestamp | ||
* of the most recent actions on each node. An action is identified as "Cooled Off" only if the cool off | ||
* period of the action has elapsed on all impacted nodes of this action | ||
*/ | ||
public class CoolOffDetector { | ||
private Map<NodeActionKey, Long> actionToExecutionTime; | ||
private long initTime; | ||
private Clock clock; | ||
|
||
public CoolOffDetector() { | ||
this.actionToExecutionTime = new HashMap<>(); | ||
this.clock = Clock.systemUTC(); | ||
this.initTime = clock.millis(); | ||
} | ||
|
||
/** | ||
* Returns true if a given {@link Action}'s last execution time was >= {@link Action#coolOffPeriodInMillis()} ago | ||
* | ||
* <p>If this Publisher has never executed the action, the last execution time is defined as the time when the | ||
* CoolOffDetector object was constructed. | ||
* @param action The {@link Action} to test | ||
* @return true if action is cooled off on all impacted nodes of this action | ||
*/ | ||
public boolean isCooledOff(Action action) { | ||
for (NodeKey esNode : action.impactedNodes()) { | ||
boolean cooledOff = checkCooledOff(action.name(), esNode, action.coolOffPeriodInMillis()); | ||
if (!cooledOff) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* record the timestamp when this action is published | ||
* @param action action to be recorded | ||
*/ | ||
public void recordAction(Action action) { | ||
long currentTimestamp = clock.millis(); | ||
for (NodeKey esNode : action.impactedNodes()) { | ||
NodeActionKey nodeActionKey = new NodeActionKey(action.name(), esNode); | ||
actionToExecutionTime.put(nodeActionKey, currentTimestamp); | ||
} | ||
} | ||
|
||
private boolean checkCooledOff(String actionName, NodeKey esNode, long coolOffPeriod) { | ||
long currentTimestamp = clock.millis(); | ||
NodeActionKey nodeActionKey = new NodeActionKey(actionName, esNode); | ||
long lastExecution = actionToExecutionTime.getOrDefault(nodeActionKey, initTime); | ||
long elapsed = currentTimestamp - lastExecution; | ||
return elapsed >= coolOffPeriod; | ||
} | ||
|
||
@VisibleForTesting | ||
public void setClock(Clock clock) { | ||
this.clock = clock; | ||
} | ||
|
||
@VisibleForTesting | ||
public void setInitTime(long initTime) { | ||
this.initTime = initTime; | ||
} | ||
|
||
/** | ||
* define a hash key class for cool off map. | ||
*/ | ||
private static class NodeActionKey { | ||
private final NodeKey nodeKey; | ||
private final String actionName; | ||
|
||
public NodeActionKey(final String actionName, final NodeKey nodeKey) { | ||
this.nodeKey = nodeKey; | ||
this.actionName = actionName; | ||
} | ||
|
||
public NodeKey getNodeKey() { | ||
return this.nodeKey; | ||
} | ||
|
||
public String getActionName() { | ||
return this.actionName; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof CoolOffDetector.NodeActionKey) { | ||
CoolOffDetector.NodeActionKey key = (CoolOffDetector.NodeActionKey)obj; | ||
return nodeKey.equals(key.getNodeKey()) && actionName.equals(key.getActionName()); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return new HashCodeBuilder(17, 37) | ||
.append(nodeKey.hashCode()) | ||
.append(actionName.hashCode()) | ||
.toHashCode(); | ||
} | ||
} | ||
} |
Oops, something went wrong.