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

Commit 978118e

Browse files
sruti1312Sid Narayanadityaj1107JindalAditya Jindal
authored
Merge from master into opendistro-1.10 (#194)
* Update PerformanceAnalyzerIT to work with opendistro-security * Fix PerformanceAnalyzerIT causing build failure (#185) * Fix PerformanceAnalyzerIT causing build failure - Fix checkBit() logic in PerformanceAnalyzerClusterSettingHandler - Remove unused imports from PerformanceAnalyzerIT - Update PA artifacts to 1.10 * Update the Cache Hit, Miss and Eviction metrics to be emitted as delta increase/decrease (#174) Update the Cache Hit, Miss and Eviction metrics to be emitted as delta increase/decrease. Emitting the cache hit, miss and eviction metrics as delta rather than absolute values. ES reports these metrics from beginning of process/post an invalidateAll() event/ post cache clear. This change calculated the metrics count delta between each sampling to correctly reflect the increase/decrease in the metric count for the evaluation Interval (5seconds for us). This is done for FieldData, Shard Request and Node Query Cache. Co-authored-by: Jindal <[email protected]> Co-authored-by: Aditya Jindal <[email protected]> Co-authored-by: Sid Narayan <[email protected]> Co-authored-by: Aditya Jindal <[email protected]> Co-authored-by: Jindal <[email protected]> Co-authored-by: Aditya Jindal <[email protected]>
1 parent 7849650 commit 978118e

File tree

9 files changed

+384
-62
lines changed

9 files changed

+384
-62
lines changed

build.gradle

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,15 @@ String rcaDir
195195
String rcaArtifactsDir
196196

197197
static def propEnabled(property) {
198-
return System.getProperty(property) != null
198+
return System.getProperty(property) != null && System.getProperty(property).toLowerCase().equals("true")
199199
}
200200

201201
// The following Gradle tasks are used to create a PA/RCA enabled Elasticsearch cluster
202202
// Pass the -Dtests.enableIT property to Gradle to run ITs
203+
/**
204+
* cloneGitRepo clones the performance-analyzer-rca repo if the -Dtests.enableIT=true flag is passed
205+
* to the Gradle JVM
206+
*/
203207
task cloneGitRepo(type: GitClone) {
204208
rcaDir = Paths.get(getProject().getBuildDir().toString(), "performance-analyzer-rca").toString()
205209
def destination = file(rcaDir)
@@ -273,6 +277,10 @@ bundlePlugin {
273277
}
274278
}
275279

280+
/**
281+
* setupESCluster spins up a local 2 node ES cluster using the enableRca task in the performance-analyzer-rca
282+
* repo. The performance-analyzer-rca repo is cloned as part of the cloneGitRepo task.
283+
*/
276284
task setupEsCluster() {
277285
dependsOn(cloneGitRepo)
278286
onlyIf = {
@@ -287,6 +295,30 @@ task setupEsCluster() {
287295
}
288296
}
289297

298+
/**
299+
* integTestRunner is a task provided by the ES test framework, which allows us to spin up clients
300+
* and test API calls against a local or remote Elasticsearch cluster.
301+
*
302+
* The simplest way to run this task in a way that "just works" is to invoke
303+
* ./gradlew integTest -Dtests.enableIT=true -Dtests.useDockerCluster=true
304+
* which will spin up a local 2 node ES cluster on your machine, then execute the test suite against it
305+
*
306+
* A full list of options is provided below. Check our gradle.properties file for the defaults for
307+
* each of these properties.
308+
*
309+
* -Dtests.rest.cluster the Elasticsearch REST endpoint that test clients should hit
310+
* -Dtests.cluster the Elasticsearch <a href="https://discuss.elastic.co/t/transport-client-vs-rest-client/13936">transport</a>
311+
* endpoint that test clients should hit
312+
* -Dtests.enableIT a flag to enable integration testing, by default this is false
313+
* -Dtests.useDockerCluster if true, spin up a local 2 node cluster before executing tests
314+
* NOTE: if you specify this, don't specify -Dtests.rest.cluster or -Dtests.cluster
315+
* -Dtests.pa.port the port number of the PerformanceAnalyzer REST endpoint
316+
* -Dtests.https either true or false, if true, then instantiate REST and transport clients using
317+
* the https:// protocol and basic authentication via the -Dtests.user and -Dtests.password properties
318+
* -Dtests.user the username of the admin user, this is used in conjunction with -Dtests.https and
319+
* -Dtests.password to authenticate requests in the opendistro-security context
320+
* -Dtests.password the password of the admin user specified by -Dtests.user
321+
*/
290322
integTestRunner {
291323
onlyIf = {
292324
propEnabled("tests.enableIT")

gradle.properties

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,24 @@
77
systemProp.tests.rest.cluster=localhost:9200
88
# The Elasticsearch cluster node communication endpoint
99
systemProp.tests.cluster=localhost:9300
10+
1011
# The Elasticsearch cluster name for integ tests
1112
systemProp.tests.clustername=IntegTestCluster
12-
# Whether or not to spin up a new Elasticsearch cluster for integration testing
13-
# Comment this out if you don't want a cluster spun up
14-
systemProp.tests.useDockerCluster=
13+
14+
# Set this to true if you want a cluster spun up for integration testing
15+
systemProp.tests.useDockerCluster=false
16+
17+
# Set this to true if you want to enable integration testing
18+
systemProp.tests.enableIT=false
19+
20+
# The port number for the PerformanceAnalyzer WebService
21+
systemProp.tests.pa.port=9600
22+
23+
# Whether or not to use https for REST and transport clients
24+
systemProp.tests.https=false
25+
26+
# The username of the admin user (or any user able to auth requests against opendistro-security)
27+
# NOTE: this only does something if tests.https is set to true
28+
systemProp.tests.user=admin
29+
# The password of the user specified above
30+
systemProp.tests.password=admin
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9c4d17774058b44a6f2ee6b9752c4f4254414784
1+
ec2401715f3267a7ce97a971ae0270bfad6d0985

src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/NodeStatsAllShardsMetricsCollector.java

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.elasticsearch.action.admin.indices.stats.IndexShardStats;
2727
import org.elasticsearch.action.admin.indices.stats.ShardStats;
2828
import org.elasticsearch.index.shard.IndexShard;
29+
import org.elasticsearch.index.shard.ShardId;
2930
import org.elasticsearch.indices.IndicesService;
3031
import org.elasticsearch.indices.NodeIndicesStats;
3132
import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources;
@@ -42,23 +43,44 @@
4243
* on the performance of the node.
4344
*/
4445

46+
/**
47+
* currentShards: Contains the Mapping of the Shard ID to the Shard for the shards currently present on
48+
* the cluster in this run of the collector.
49+
* currentPerShardStats: Contains the mapping of the Shard Stats and the shards present in this run
50+
* of the collector.
51+
* prevPerShardStats: Contains the mapping of the Shard Stats and the shards present in the previous
52+
* run of the collector.
53+
* The diff is calculated between (currentPerShardStats and prevPerShardStats) for each shard in the
54+
* currentShards and for shards not present in the prevPerShardStat absolute value of the
55+
* currentPerShardStats is updated.
56+
*/
57+
58+
4559
@SuppressWarnings("unchecked")
4660
public class NodeStatsAllShardsMetricsCollector extends PerformanceAnalyzerMetricsCollector implements MetricsProcessor {
4761
public static final int SAMPLING_TIME_INTERVAL = MetricsConfiguration.CONFIG_MAP.get(
4862
NodeStatsAllShardsMetricsCollector.class).samplingInterval;
4963
private static final int KEYS_PATH_LENGTH = 2;
5064
private static final Logger LOG = LogManager.getLogger(NodeStatsAllShardsMetricsCollector.class);
51-
private HashMap<String, IndexShard> currentShards;
65+
private HashMap<ShardId, IndexShard> currentShards;
66+
private HashMap<ShardId, ShardStats> currentPerShardStats;
67+
private HashMap<ShardId, ShardStats> prevPerShardStats;
5268
private final PerformanceAnalyzerController controller;
5369

5470

5571
public NodeStatsAllShardsMetricsCollector(final PerformanceAnalyzerController controller) {
5672
super(SAMPLING_TIME_INTERVAL, "NodeStatsMetrics");
5773
currentShards = new HashMap<>();
74+
prevPerShardStats = new HashMap<>();
75+
currentPerShardStats = new HashMap<>();
5876
this.controller = controller;
5977
}
6078

6179
private void populateCurrentShards() {
80+
if (!currentShards.isEmpty()) {
81+
prevPerShardStats.putAll(currentPerShardStats);
82+
currentPerShardStats.clear();
83+
}
6284
currentShards.clear();
6385
currentShards = Utils.getShards();
6486
}
@@ -100,25 +122,28 @@ public void collectMetrics(long startTime) {
100122

101123
try {
102124
populateCurrentShards();
103-
// Metrics populated for all shards in every collection.
104-
for (HashMap.Entry currentShard : currentShards.entrySet() ){
105-
IndexShard currentIndexShard = (IndexShard)currentShard.getValue();
106-
IndexShardStats currentIndexShardStats = Utils.indexShardStats(indicesService,
107-
currentIndexShard, new CommonStatsFlags(CommonStatsFlags.Flag.QueryCache,
108-
CommonStatsFlags.Flag.FieldData,
109-
CommonStatsFlags.Flag.RequestCache));
110-
for (ShardStats shardStats : currentIndexShardStats.getShards()) {
111-
StringBuilder value = new StringBuilder();
112-
113-
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds());
114-
// Populate the result with cache specific metrics only.
115-
value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
116-
.append(new NodeStatsMetricsAllShardsPerCollectionStatus(shardStats).serialize());
117-
saveMetricValues(value.toString(), startTime, currentIndexShardStats.getShardId().getIndexName(),
118-
String.valueOf(currentIndexShardStats.getShardId().id()));
125+
populatePerShardStats(indicesService);
126+
127+
for (HashMap.Entry currentShard : currentPerShardStats.entrySet()) {
128+
ShardId shardId = (ShardId) currentShard.getKey();
129+
ShardStats currentShardStats = (ShardStats) currentShard.getValue();
130+
if (prevPerShardStats.size() == 0) {
131+
// Populating value for the first run.
132+
populateMetricValue(currentShardStats, startTime, shardId.getIndexName(), shardId.id());
133+
continue;
134+
}
135+
ShardStats prevShardStats = prevPerShardStats.get(shardId);
136+
if (prevShardStats == null) {
137+
// Populate value for shards which are new and were not present in the previous run.
138+
populateMetricValue(currentShardStats, startTime, shardId.getIndexName(), shardId.id());
139+
continue;
119140
}
141+
NodeStatsMetricsAllShardsPerCollectionStatus prevValue = new
142+
NodeStatsMetricsAllShardsPerCollectionStatus(prevShardStats);
143+
NodeStatsMetricsAllShardsPerCollectionStatus currValue = new
144+
NodeStatsMetricsAllShardsPerCollectionStatus(currentShardStats);
145+
populateDiffMetricValue(prevValue, currValue, startTime, shardId.getIndexName(), shardId.id());
120146
}
121-
122147
} catch (Exception ex) {
123148
LOG.debug("Exception in Collecting NodesStats Metrics: {} for startTime {} with ExceptionCode: {}",
124149
() -> ex.toString(), () -> startTime, () -> StatExceptionCode.NODESTATS_COLLECTION_ERROR.toString());
@@ -133,6 +158,55 @@ Field getNodeIndicesStatsByShardField() throws Exception {
133158
return field;
134159
}
135160

161+
public void populatePerShardStats(IndicesService indicesService) {
162+
163+
//Populate the shard stats per shard.
164+
for (HashMap.Entry currentShard : currentShards.entrySet() ){
165+
IndexShard currentIndexShard = (IndexShard)currentShard.getValue();
166+
IndexShardStats currentIndexShardStats = Utils.indexShardStats(indicesService,
167+
currentIndexShard, new CommonStatsFlags(CommonStatsFlags.Flag.QueryCache,
168+
CommonStatsFlags.Flag.FieldData,
169+
CommonStatsFlags.Flag.RequestCache));
170+
for (ShardStats shardStats : currentIndexShardStats.getShards()) {
171+
currentPerShardStats.put(currentIndexShardStats.getShardId(), shardStats);
172+
}
173+
}
174+
return;
175+
}
176+
177+
public void populateMetricValue(ShardStats shardStats, long startTime, String IndexName, int ShardId) {
178+
StringBuilder value = new StringBuilder();
179+
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds());
180+
// Populate the result with cache specific metrics only.
181+
value.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
182+
.append(new NodeStatsMetricsAllShardsPerCollectionStatus(shardStats).serialize());
183+
saveMetricValues(value.toString(), startTime, IndexName,
184+
String.valueOf(ShardId));
185+
}
186+
187+
public void populateDiffMetricValue(NodeStatsMetricsAllShardsPerCollectionStatus prevValue,
188+
NodeStatsMetricsAllShardsPerCollectionStatus currValue,
189+
long startTime, String IndexName, int ShardId) {
190+
StringBuilder value = new StringBuilder();
191+
192+
NodeStatsMetricsAllShardsPerCollectionStatus nodeStatsMetrics = new NodeStatsMetricsAllShardsPerCollectionStatus(
193+
Math.max((currValue.queryCacheHitCount - prevValue.queryCacheHitCount), 0),
194+
Math.max((currValue.queryCacheMissCount - prevValue.queryCacheMissCount), 0),
195+
Math.max((currValue.queryCacheInBytes - prevValue.queryCacheInBytes), 0),
196+
Math.max((currValue.fieldDataEvictions - prevValue.fieldDataEvictions), 0),
197+
Math.max((currValue.fieldDataInBytes - prevValue.fieldDataInBytes), 0),
198+
Math.max((currValue.requestCacheHitCount - prevValue.requestCacheHitCount), 0),
199+
Math.max((currValue.requestCacheMissCount - prevValue.requestCacheMissCount), 0),
200+
Math.max((currValue.requestCacheEvictions - prevValue.requestCacheEvictions), 0),
201+
Math.max((currValue.requestCacheInBytes - prevValue.requestCacheInBytes), 0));
202+
203+
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds())
204+
.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor)
205+
.append(nodeStatsMetrics.serialize());
206+
saveMetricValues(value.toString(), startTime, IndexName,
207+
String.valueOf(ShardId));
208+
}
209+
136210
public class NodeStatsMetricsAllShardsPerCollectionStatus extends MetricStatus {
137211

138212
@JsonIgnore

src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/NodeStatsFixedShardsMetricsCollector.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.elasticsearch.action.admin.indices.stats.IndexShardStats;
2828
import org.elasticsearch.action.admin.indices.stats.ShardStats;
2929
import org.elasticsearch.index.shard.IndexShard;
30+
import org.elasticsearch.index.shard.ShardId;
3031
import org.elasticsearch.indices.IndicesService;
3132
import org.elasticsearch.indices.NodeIndicesStats;
3233
import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources;
@@ -51,8 +52,8 @@ public class NodeStatsFixedShardsMetricsCollector extends PerformanceAnalyzerMet
5152
NodeStatsAllShardsMetricsCollector.class).samplingInterval;
5253
private static final int KEYS_PATH_LENGTH = 2;
5354
private static final Logger LOG = LogManager.getLogger(NodeStatsFixedShardsMetricsCollector.class);
54-
private HashMap<String, IndexShard> currentShards;
55-
private Iterator<HashMap.Entry<String, IndexShard>> currentShardsIter;
55+
private HashMap<ShardId, IndexShard> currentShards;
56+
private Iterator<HashMap.Entry<ShardId, IndexShard>> currentShardsIter;
5657
private final PerformanceAnalyzerController controller;
5758

5859
public NodeStatsFixedShardsMetricsCollector(final PerformanceAnalyzerController controller) {
@@ -105,7 +106,7 @@ private void populateCurrentShards() {
105106
} };
106107

107108
private long getIndexBufferBytes(ShardStats shardStats) {
108-
IndexShard shard = currentShards.get(Utils.getUniqueShardIdKey(shardStats.getShardRouting().shardId()));
109+
IndexShard shard = currentShards.get(shardStats.getShardRouting().shardId());
109110

110111
if (shard == null) {
111112
return 0;

src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public class PerformanceAnalyzerClusterSettingHandler implements ClusterSettingL
1010
private static final int BIT_ONE = 1;
1111
private static final int CLUSTER_SETTING_DISABLED_VALUE = 0;
1212
private static final int ENABLED_VALUE = 1;
13+
private static final int MAX_ALLOWED_BIT_POS = Math.min(PerformanceAnalyzerFeatureBits.values().length, Integer.SIZE - 1);
1314
private static final int RCA_ENABLED_BIT_POS = PerformanceAnalyzerFeatureBits.RCA_BIT.ordinal();
1415
private static final int PA_ENABLED_BIT_POS = PerformanceAnalyzerFeatureBits.PA_BIT.ordinal();
1516
private static final int LOGGING_ENABLED_BIT_POS = PerformanceAnalyzerFeatureBits.LOGGING_BIT.ordinal();
16-
private static final int MAX_ALLOWED_BIT_POS = Math.min(PerformanceAnalyzerFeatureBits.values().length, Integer.SIZE - 1);
1717

1818
private final PerformanceAnalyzerController controller;
1919
private final ClusterSettingsManager clusterSettingsManager;
@@ -219,7 +219,7 @@ private int resetBit(int number, int bitPosition) {
219219
* @param bitPosition The position of the bit in the clusterSettingValue
220220
* @return true if the bit is set, false otherwise.
221221
*/
222-
private boolean checkBit(int clusterSettingValue, int bitPosition) {
223-
return ((bitPosition < MAX_ALLOWED_BIT_POS) & (clusterSettingValue & (1 << bitPosition)) == ENABLED_VALUE);
222+
public static boolean checkBit(int clusterSettingValue, int bitPosition) {
223+
return ((bitPosition < MAX_ALLOWED_BIT_POS) && (clusterSettingValue & (1 << bitPosition)) > 0);
224224
}
225225
}

src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/util/Utils.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,19 @@ public static IndexShardStats indexShardStats(final IndicesService indicesServic
8585
});
8686
}
8787

88-
public static HashMap<String, IndexShard> getShards() {
89-
HashMap<String, IndexShard> shards = new HashMap<>();
88+
public static HashMap<ShardId, IndexShard> getShards() {
89+
HashMap<ShardId, IndexShard> shards = new HashMap<>();
9090
Iterator<IndexService> indexServices = ESResources.INSTANCE.getIndicesService().iterator();
9191
while (indexServices.hasNext()) {
9292
Iterator<IndexShard> indexShards = indexServices.next().iterator();
9393
while (indexShards.hasNext()) {
9494
IndexShard shard = indexShards.next();
95-
shards.put(getUniqueShardIdKey(shard.shardId()), shard);
95+
shards.put(shard.shardId(), shard);
9696
}
9797
}
9898
return shards;
9999
}
100100

101-
public static String getUniqueShardIdKey(ShardId shardId) {
102-
return "[" + shardId.hashCode() + "][" + shardId.getId() + "]";
103-
}
104-
105101
public static final EnumSet<IndexShardState> CAN_WRITE_INDEX_BUFFER_STATES = EnumSet.of(
106102
IndexShardState.RECOVERING, IndexShardState.POST_RECOVERY, IndexShardState.STARTED);
107103

0 commit comments

Comments
 (0)