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

Decision policy for consolidating actions #440

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.deciders;

import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions.Action;
import java.util.List;

/**
* A DecisionPolicy evaluates a subset of observation summaries for
* a Decider, and returns a list of recommended Actions. They abstract out a subset
* of the decision making process for a decider.
*
* <p> </p>Decision policies are invoked by deciders and never scheduled directly by the RCA framework.
*/
public interface DecisionPolicy {

List<Action> evaluate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.deciders.Decider;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.deciders.Decision;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.deciders.jvm.old_gen.OldGenDecisionPolicy;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotClusterSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HighHeapUsageClusterRca;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.NodeKey;
import java.util.List;

/**
Expand All @@ -36,15 +30,13 @@
public class HeapHealthDecider extends Decider {

public static final String NAME = "HeapHealthDecider";
private final HighHeapUsageClusterRca highHeapUsageClusterRca;
private final OldGenDecisionPolicy oldGenDecisionPolicy;
private int counter = 0;

public HeapHealthDecider(int decisionFrequency, final HighHeapUsageClusterRca highHeapUsageClusterRca) {
//TODO : refactor parent class to remove evalIntervalSeconds completely
super(5, decisionFrequency);
this.highHeapUsageClusterRca = highHeapUsageClusterRca;
oldGenDecisionPolicy = new OldGenDecisionPolicy();
oldGenDecisionPolicy = new OldGenDecisionPolicy(highHeapUsageClusterRca);
}

@Override
Expand All @@ -61,25 +53,13 @@ public Decision operate() {
}

counter = 0;
if (highHeapUsageClusterRca.getFlowUnits().isEmpty()) {
return decision;
}
// oldGenDecisionPolicy are always accepted
List<Action> oldGenPolicyActions = oldGenDecisionPolicy.evaluate();
oldGenPolicyActions.forEach(decision::addAction);

// TODO: Add actions from JvmScaleUpPolicy (128gb heaps)
// TODO: If no JvmScaleUpPolicy actions found, fetch and add genTuningPolicy actions

ResourceFlowUnit<HotClusterSummary> flowUnit = highHeapUsageClusterRca.getFlowUnits().get(0);
if (!flowUnit.hasResourceSummary()) {
return decision;
}
HotClusterSummary clusterSummary = flowUnit.getSummary();
for (HotNodeSummary nodeSummary : clusterSummary.getHotNodeSummaryList()) {
NodeKey esNode = new NodeKey(nodeSummary.getNodeID(), nodeSummary.getHostAddress());
for (HotResourceSummary resource : nodeSummary.getHotResourceSummaryList()) {
if (resource.getResource().equals(ResourceUtil.OLD_GEN_HEAP_USAGE)) {
List<Action> actions = oldGenDecisionPolicy.evaluate(esNode, resource.getValue());
actions.forEach(decision::addAction);
}
//TODO : Add policy for young gen
}
}
return decision;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@

import com.amazon.opendistro.elasticsearch.performanceanalyzer.AppContext;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.actions.Action;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.deciders.DecisionPolicy;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.decisionmaker.deciders.configs.jvm.OldGenDecisionPolicyConfig;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.flow_units.ResourceFlowUnit;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotClusterSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotNodeSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.HotResourceSummary;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.api.summaries.ResourceUtil;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.framework.core.RcaConf;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.HighHeapUsageClusterRca;
import com.amazon.opendistro.elasticsearch.performanceanalyzer.rca.store.rca.cluster.NodeKey;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -32,10 +39,15 @@
* and create dedicated action builders {@link LevelOneActionBuilder}, {@link LevelTwoActionBuilder},
* {@link LevelThreeActionBuilder} for each level of unhealthiness
*/
public class OldGenDecisionPolicy {
public class OldGenDecisionPolicy implements DecisionPolicy {
private static final Logger LOG = LogManager.getLogger(OldGenDecisionPolicy.class);
private AppContext appContext;
private RcaConf rcaConf;
private final HighHeapUsageClusterRca highHeapUsageClusterRca;

public OldGenDecisionPolicy(final HighHeapUsageClusterRca highHeapUsageClusterRca) {
this.highHeapUsageClusterRca = highHeapUsageClusterRca;
}

public void setRcaConf(final RcaConf rcaConf) {
this.rcaConf = rcaConf;
Expand All @@ -45,7 +57,30 @@ public void setAppContext(final AppContext appContext) {
this.appContext = appContext;
}

public List<Action> evaluate(final NodeKey esNode, double oldGenUsage) {
@Override
public List<Action> evaluate() {
List<Action> actions = new ArrayList<>();
if (highHeapUsageClusterRca.getFlowUnits().isEmpty()) {
return actions;
}

ResourceFlowUnit<HotClusterSummary> flowUnit = highHeapUsageClusterRca.getFlowUnits().get(0);
if (!flowUnit.hasResourceSummary()) {
return actions;
}
HotClusterSummary clusterSummary = flowUnit.getSummary();
for (HotNodeSummary nodeSummary : clusterSummary.getHotNodeSummaryList()) {
NodeKey esNode = new NodeKey(nodeSummary.getNodeID(), nodeSummary.getHostAddress());
for (HotResourceSummary resource : nodeSummary.getHotResourceSummaryList()) {
if (resource.getResource().equals(ResourceUtil.OLD_GEN_HEAP_USAGE)) {
actions.addAll(evaluate(esNode, resource.getValue()));
}
}
}
return actions;
}

private List<Action> evaluate(final NodeKey esNode, double oldGenUsage) {
//rca config / app context will not be null unless there is a bug in RCAScheduler.
if (rcaConf == null || appContext == null) {
LOG.error("rca conf/app context is null, return empty action list");
Expand Down