Skip to content

Commit

Permalink
test: remove flag from CommonStatsFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu-S committed Jul 11, 2024
1 parent 6c1c4c7 commit 7e43dda
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 237 deletions.
20 changes: 0 additions & 20 deletions .idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -332,58 +332,58 @@ public void testNodeIndicesStatsDefaultResponse() {
* Optimized behavior - to avoid unnecessary IO in the form of shard-stats when not required, we not honor the levels on the
* individual data nodes instead and pre-compute information as required.
*/
public void testNodeIndicesStatsOptimizedResponse() {
String testLevel = randomFrom("null", "node", "indices", "shards", "unknown");
internalCluster().startNode();
ensureGreen();
String indexName = "test1";
index(indexName, "type", "1", "f", "f");
refresh();

NodesStatsResponse response;
CommonStatsFlags commonStatsFlags = new CommonStatsFlags();
commonStatsFlags.optimizeNodeIndicesStatsOnLevel(true);
if (!testLevel.equals("null")) {
ArrayList<String> level_arg = new ArrayList<>();
level_arg.add(testLevel);

commonStatsFlags.setLevels(level_arg.toArray(new String[0]));
}
response = client().admin().cluster().prepareNodesStats().setIndices(commonStatsFlags).get();

response.getNodes().forEach(nodeStats -> {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder = nodeStats.getIndices().toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("level", "shards")));
builder.endObject();

Map<String, Object> xContentMap = xContentBuilderToMap(builder);
LinkedHashMap indicesStatsMap = (LinkedHashMap) xContentMap.get("indices");
LinkedHashMap indicesStats = (LinkedHashMap) indicesStatsMap.get("indices");
LinkedHashMap shardStats = (LinkedHashMap) indicesStatsMap.get("shards");

switch (testLevel) {
case "shards":
assertFalse(shardStats.isEmpty());
assertFalse(indicesStats.isEmpty());
break;
case "indices":
assertTrue(shardStats.isEmpty());
assertFalse(indicesStats.isEmpty());
break;
case "node":
case "null":
case "unknown":
assertTrue(shardStats.isEmpty());
assertTrue(indicesStats.isEmpty());
break;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
// public void testNodeIndicesStatsOptimizedResponse() {
// String testLevel = randomFrom("null", "node", "indices", "shards", "unknown");
// internalCluster().startNode();
// ensureGreen();
// String indexName = "test1";
// index(indexName, "type", "1", "f", "f");
// refresh();
//
// NodesStatsResponse response;
// CommonStatsFlags commonStatsFlags = new CommonStatsFlags();
// commonStatsFlags.optimizeNodeIndicesStatsOnLevel(true);
// if (!testLevel.equals("null")) {
// ArrayList<String> level_arg = new ArrayList<>();
// level_arg.add(testLevel);
//
// commonStatsFlags.setLevels(level_arg.toArray(new String[0]));
// }
// response = client().admin().cluster().prepareNodesStats().setIndices(commonStatsFlags).get();
//
// response.getNodes().forEach(nodeStats -> {
// try {
// XContentBuilder builder = XContentFactory.jsonBuilder();
// builder.startObject();
// builder = nodeStats.getIndices().toXContent(builder, new ToXContent.MapParams(Collections.singletonMap("level", "shards")));
// builder.endObject();
//
// Map<String, Object> xContentMap = xContentBuilderToMap(builder);
// LinkedHashMap indicesStatsMap = (LinkedHashMap) xContentMap.get("indices");
// LinkedHashMap indicesStats = (LinkedHashMap) indicesStatsMap.get("indices");
// LinkedHashMap shardStats = (LinkedHashMap) indicesStatsMap.get("shards");
//
// switch (testLevel) {
// case "shards":
// assertFalse(shardStats.isEmpty());
// assertFalse(indicesStats.isEmpty());
// break;
// case "indices":
// assertTrue(shardStats.isEmpty());
// assertFalse(indicesStats.isEmpty());
// break;
// case "node":
// case "null":
// case "unknown":
// assertTrue(shardStats.isEmpty());
// assertTrue(indicesStats.isEmpty());
// break;
// }
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
// });
// }

private Map<String, Object> xContentBuilderToMap(XContentBuilder xContentBuilder) {
return XContentHelper.convertToMap(BytesReference.bytes(xContentBuilder), true, xContentBuilder.contentType()).v2();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public NodesStatsRequest indices(boolean indices) {
return this;
}

/**
* Use Optimized Response filtered based on level
*/
public NodesStatsRequest useOptimizedNodeIndicesStats(boolean useOptimizedNodeIndicesStats) {
if (this.indices != null) {
this.indices.optimizeNodeIndicesStatsOnLevel(true);
}
return this;
}
// /**
// * Use Optimized Response filtered based on level
// */
// public NodesStatsRequest useOptimizedNodeIndicesStats(boolean useOptimizedNodeIndicesStats) {
// if (this.indices != null) {
// this.indices.optimizeNodeIndicesStatsOnLevel(true);
// }
// return this;
// }

/**
* Get the names of requested metrics, excluding indices, which are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CommonStatsFlags implements Writeable, Cloneable {
// Used for metric CACHE_STATS, to determine which caches to report stats for
private EnumSet<CacheType> includeCaches = EnumSet.noneOf(CacheType.class);
private String[] levels = new String[0];
private boolean optimizeNodeIndicesStatsOnLevel = false;
// private boolean optimizeNodeIndicesStatsOnLevel = false;

/**
* @param flags flags to set. If no flags are supplied, default flags will be set.
Expand Down Expand Up @@ -101,9 +101,9 @@ public CommonStatsFlags(StreamInput in) throws IOException {
includeCaches = in.readEnumSet(CacheType.class);
levels = in.readStringArray();
}
if (in.getVersion().onOrAfter(Version.V_2_16_0)) {
optimizeNodeIndicesStatsOnLevel = in.readBoolean();
}
// if (in.getVersion().onOrAfter(Version.V_2_16_0)) {
// optimizeNodeIndicesStatsOnLevel = in.readBoolean();
// }
}

@Override
Expand All @@ -128,9 +128,9 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeEnumSet(includeCaches);
out.writeStringArrayNullable(levels);
}
if (out.getVersion().onOrAfter(Version.V_2_16_0)) {
out.writeBoolean(optimizeNodeIndicesStatsOnLevel);
}
// if (out.getVersion().onOrAfter(Version.V_2_16_0)) {
// out.writeBoolean(optimizeNodeIndicesStatsOnLevel);
// }
}

/**
Expand Down Expand Up @@ -269,13 +269,13 @@ public boolean includeSegmentFileSizes() {
return this.includeSegmentFileSizes;
}

public void optimizeNodeIndicesStatsOnLevel(boolean optimizeNodeIndicesStatsOnLevel) {
this.optimizeNodeIndicesStatsOnLevel = optimizeNodeIndicesStatsOnLevel;
}

public boolean optimizeNodeIndicesStatsOnLevel() {
return this.optimizeNodeIndicesStatsOnLevel;
}
// public void optimizeNodeIndicesStatsOnLevel(boolean optimizeNodeIndicesStatsOnLevel) {
// this.optimizeNodeIndicesStatsOnLevel = optimizeNodeIndicesStatsOnLevel;
// }
//
// public boolean optimizeNodeIndicesStatsOnLevel() {
// return this.optimizeNodeIndicesStatsOnLevel;
// }

public boolean isSet(Flag flag) {
return flags.contains(flag);
Expand Down
Loading

0 comments on commit 7e43dda

Please sign in to comment.