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.
Reader changes for dynamic enable/disable of RCA graph components (#325)
* Common changes needed to support dynamic en/disabling of config overrides * Add ability to apply the config overrides * Refactor muting logic for actions and graph nodes * Add unit tests * Remove merge conflict markers in comments * Add licence header to new files * Filter at the decider instead of collator * Delete collator test as it is not used to filter actions * Use the right log levels * Add abstract SuppressibleAction class to handle muted actions * Remove unwanted import * Address PR comments * Address PR comments * Address PR comments
- Loading branch information
Showing
39 changed files
with
846 additions
and
141 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.math.NumberUtils; | ||
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 NumberUtils.isCreatable(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
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
51 changes: 51 additions & 0 deletions
51
...pendistro/elasticsearch/performanceanalyzer/decisionmaker/actions/SuppressibleAction.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,51 @@ | ||
package com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions; | ||
|
||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext; | ||
|
||
/** | ||
* Actions that can be suppressed through a config. | ||
*/ | ||
public abstract class SuppressibleAction implements Action { | ||
|
||
private final AppContext appContext; | ||
|
||
public SuppressibleAction(final AppContext appContext) { | ||
this.appContext = appContext; | ||
} | ||
|
||
/** | ||
* Returns if this action is explicitly muted through configuration | ||
*/ | ||
@Override | ||
public boolean isMuted() { | ||
return appContext.isActionMuted(name()); | ||
} | ||
|
||
/** | ||
* Returns true if the configured action is actionable, false otherwise. | ||
* The method is also declared final to enforce checking for muted-ness of an action before | ||
* declaring it actionable. | ||
* | ||
* <p>Actions that want to define the actionable criterion differently should not inherit from | ||
* {@link SuppressibleAction}, instead provide their own implementation. This way, we get to | ||
* close {@link SuppressibleAction} while still keeping the {@link Action} interface open for | ||
* modification.</p> | ||
* | ||
* <p>Examples of non-actionable actions are invalid actions or actions that are explicitly | ||
* disabled in the conf file. | ||
*/ | ||
@Override | ||
public final boolean isActionable() { | ||
return !isMuted() && canUpdate(); | ||
} | ||
|
||
/** | ||
* Returns true if the configured action is valid, false otherwise. | ||
* | ||
* <p>Examples of invalid actions are resource configurations where limits have been | ||
* reached.</p> | ||
* | ||
* @return true if valid, false otherwise. | ||
*/ | ||
public abstract boolean canUpdate(); | ||
} |
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
Oops, something went wrong.