Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Remove] Type Specific Index Stats #2198

Merged
merged 1 commit into from
Feb 21, 2022
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
Expand Up @@ -438,7 +438,7 @@ public void testMultiGet() throws IOException {
}
}

public void testMultiGetWithTypes() throws IOException {
public void testMultiGetWithIds() throws IOException {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick cleanup unrelated to this PR (from #2168)

BulkRequest bulk = new BulkRequest();
bulk.setRefreshPolicy(RefreshPolicy.IMMEDIATE);
bulk.add(new IndexRequest("index", "type", "id1").source("{\"field\":\"value1\"}", XContentType.JSON));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,40 +1079,6 @@ public void testGroupsParam() throws Exception {

}

public void testTypesParam() throws Exception {
createIndex("test1");
createIndex("test2");

ensureGreen();

client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
client().prepareIndex("test2", "baz", Integer.toString(1)).setSource("foo", "bar").execute().actionGet();
refresh();

IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats();
IndicesStatsResponse stats = builder.execute().actionGet();

assertThat(stats.getTotal().indexing.getTotal().getIndexCount(), greaterThan(0L));
assertThat(stats.getTotal().indexing.getTypeStats(), is(nullValue()));

stats = builder.setTypes("bar").execute().actionGet();
assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
assertThat(stats.getTotal().indexing.getTypeStats().containsKey("baz"), is(false));

stats = builder.setTypes("bar", "baz").execute().actionGet();
assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
assertThat(stats.getTotal().indexing.getTypeStats().get("baz").getIndexCount(), greaterThan(0L));

stats = builder.setTypes("*").execute().actionGet();
assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
assertThat(stats.getTotal().indexing.getTypeStats().get("baz").getIndexCount(), greaterThan(0L));

stats = builder.setTypes("*r").execute().actionGet();
assertThat(stats.getTotal().indexing.getTypeStats().get("bar").getIndexCount(), greaterThan(0L));
assertThat(stats.getTotal().indexing.getTypeStats().containsKey("baz"), is(false));

}

private static void set(Flag flag, IndicesStatsRequestBuilder builder, boolean set) {
switch (flag) {
case Docs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public CommonStats(IndicesQueryCache indicesQueryCache, IndexShard indexShard, C
store = indexShard.storeStats();
break;
case Indexing:
indexing = indexShard.indexingStats(flags.types());
indexing = indexShard.indexingStats();
break;
case Get:
get = indexShard.getStats();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.opensearch.LegacyESVersion;
import org.opensearch.Version;
import org.opensearch.common.Strings;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.io.stream.Writeable;
Expand All @@ -48,7 +49,6 @@ public class CommonStatsFlags implements Writeable, Cloneable {
public static final CommonStatsFlags NONE = new CommonStatsFlags().clear();

private EnumSet<Flag> flags = EnumSet.allOf(Flag.class);
private String[] types = null;
private String[] groups = null;
private String[] fieldDataFields = null;
private String[] completionDataFields = null;
Expand All @@ -75,7 +75,9 @@ public CommonStatsFlags(StreamInput in) throws IOException {
flags.add(flag);
}
}
types = in.readStringArray();
if (in.getVersion().before(Version.V_2_0_0)) {
in.readStringArray();
}
groups = in.readStringArray();
fieldDataFields = in.readStringArray();
completionDataFields = in.readStringArray();
Expand All @@ -97,7 +99,9 @@ public void writeTo(StreamOutput out) throws IOException {
}
out.writeLong(longFlags);

out.writeStringArrayNullable(types);
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeStringArrayNullable(Strings.EMPTY_ARRAY);
}
out.writeStringArrayNullable(groups);
out.writeStringArrayNullable(fieldDataFields);
out.writeStringArrayNullable(completionDataFields);
Expand All @@ -116,7 +120,6 @@ public void writeTo(StreamOutput out) throws IOException {
*/
public CommonStatsFlags all() {
flags = EnumSet.allOf(Flag.class);
types = null;
groups = null;
fieldDataFields = null;
completionDataFields = null;
Expand All @@ -132,7 +135,6 @@ public CommonStatsFlags all() {
*/
public CommonStatsFlags clear() {
flags = EnumSet.noneOf(Flag.class);
types = null;
groups = null;
fieldDataFields = null;
completionDataFields = null;
Expand All @@ -151,23 +153,6 @@ public Flag[] getFlags() {
return flags.toArray(new Flag[flags.size()]);
}

/**
* Document types to return stats for. Mainly affects {@link Flag#Indexing} when
* enabled, returning specific indexing stats for those types.
*/
public CommonStatsFlags types(String... types) {
this.types = types;
return this;
}

/**
* Document types to return stats for. Mainly affects {@link Flag#Indexing} when
* enabled, returning specific indexing stats for those types.
*/
public String[] types() {
return this.types;
}

/**
* Sets specific search group stats to retrieve the stats for. Mainly affects search
* when enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,6 @@ public IndicesStatsRequest flags(CommonStatsFlags flags) {
return this;
}

/**
* Document types to return stats for. Mainly affects {@link #indexing(boolean)} when
* enabled, returning specific indexing stats for those types.
*/
public IndicesStatsRequest types(String... types) {
flags.types(types);
return this;
}

/**
* Document types to return stats for. Mainly affects {@link #indexing(boolean)} when
* enabled, returning specific indexing stats for those types.
*/
public String[] types() {
return this.flags.types();
}

/**
* Sets specific search group stats to retrieve the stats for. Mainly affects search
* when enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ public final IndicesStatsRequestBuilder setTimeout(TimeValue timeout) {
return this;
}

/**
* Document types to return stats for. Mainly affects {@link #setIndexing(boolean)} when
* enabled, returning specific indexing stats for those types.
*/
public IndicesStatsRequestBuilder setTypes(String... types) {
request.types(types);
return this;
}

public IndicesStatsRequestBuilder setGroups(String... groups) {
request.groups(groups);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ protected void shardOperation(final UpdateRequest request, final ActionListener<
if (indexServiceOrNull != null) {
IndexShard shard = indexService.getShardOrNull(shardId.getId());
if (shard != null) {
shard.noopUpdate(request.type());
shard.noopUpdate();
}
}
listener.onResponse(update);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ public IndexingStats indexingStats(String... types) {
throttled = engine.isThrottled();
throttleTimeInMillis = engine.getIndexThrottleTimeInMillis();
}
return internalIndexingStats.stats(throttled, throttleTimeInMillis, types);
return internalIndexingStats.stats(throttled, throttleTimeInMillis);
}

public SearchStats searchStats(String... groups) {
Expand Down Expand Up @@ -2847,11 +2847,9 @@ public boolean pendingInSync() {

/**
* Should be called for each no-op update operation to increment relevant statistics.
*
* @param type the doc type of the update
*/
public void noopUpdate(String type) {
internalIndexingStats.noopUpdate(type);
public void noopUpdate() {
internalIndexingStats.noopUpdate();
}

public void maybeCheckIndex() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@

package org.opensearch.index.shard;

import org.opensearch.common.Nullable;
import org.opensearch.Version;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.io.stream.Writeable;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.ToXContentFragment;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.index.mapper.MapperService;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class IndexingStats implements Writeable, ToXContentFragment {
Expand Down Expand Up @@ -219,47 +219,30 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws

private final Stats totalStats;

@Nullable
private Map<String, Stats> typeStats;

public IndexingStats() {
totalStats = new Stats();
}

public IndexingStats(StreamInput in) throws IOException {
totalStats = new Stats(in);
if (in.readBoolean()) {
typeStats = in.readMap(StreamInput::readString, Stats::new);
if (in.getVersion().before(Version.V_2_0_0)) {
if (in.readBoolean()) {
Map<String, Stats> typeStats = in.readMap(StreamInput::readString, Stats::new);
assert typeStats.size() == 1;
assert typeStats.containsKey(MapperService.SINGLE_MAPPING_NAME);
}
}
}

public IndexingStats(Stats totalStats, @Nullable Map<String, Stats> typeStats) {
public IndexingStats(Stats totalStats) {
this.totalStats = totalStats;
this.typeStats = typeStats;
}

public void add(IndexingStats indexingStats) {
add(indexingStats, true);
}

public void add(IndexingStats indexingStats, boolean includeTypes) {
if (indexingStats == null) {
return;
}
addTotals(indexingStats);
if (includeTypes && indexingStats.typeStats != null && !indexingStats.typeStats.isEmpty()) {
if (typeStats == null) {
typeStats = new HashMap<>(indexingStats.typeStats.size());
}
for (Map.Entry<String, Stats> entry : indexingStats.typeStats.entrySet()) {
Stats stats = typeStats.get(entry.getKey());
if (stats == null) {
typeStats.put(entry.getKey(), entry.getValue());
} else {
stats.add(entry.getValue());
}
}
}
}

public void addTotals(IndexingStats indexingStats) {
Expand All @@ -273,31 +256,16 @@ public Stats getTotal() {
return this.totalStats;
}

@Nullable
public Map<String, Stats> getTypeStats() {
return this.typeStats;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
builder.startObject(Fields.INDEXING);
totalStats.toXContent(builder, params);
if (typeStats != null && !typeStats.isEmpty()) {
builder.startObject(Fields.TYPES);
for (Map.Entry<String, Stats> entry : typeStats.entrySet()) {
builder.startObject(entry.getKey());
entry.getValue().toXContent(builder, params);
builder.endObject();
}
builder.endObject();
}
builder.endObject();
return builder;
}

static final class Fields {
static final String INDEXING = "indexing";
static final String TYPES = "types";
static final String INDEX_TOTAL = "index_total";
static final String INDEX_TIME = "index_time";
static final String INDEX_TIME_IN_MILLIS = "index_time_in_millis";
Expand All @@ -316,11 +284,8 @@ static final class Fields {
@Override
public void writeTo(StreamOutput out) throws IOException {
totalStats.writeTo(out);
if (typeStats == null || typeStats.isEmpty()) {
if (out.getVersion().before(Version.V_2_0_0)) {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeMap(typeStats, StreamOutput::writeString, (stream, stats) -> stats.writeTo(stream));
}
}
}
Loading