Add usage stats for frozen indices (#44286)
Adds usage stats for frozen indices of the form: "frozen_indices" : { "available" : true, "enabled" : true, "indices_count" : 0 }
This commit is contained in:
parent
e3d2af64c4
commit
5e73c49ec8
|
@ -58,6 +58,7 @@ import org.elasticsearch.xpack.core.dataframe.transforms.SyncConfig;
|
||||||
import org.elasticsearch.xpack.core.dataframe.transforms.TimeSyncConfig;
|
import org.elasticsearch.xpack.core.dataframe.transforms.TimeSyncConfig;
|
||||||
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
|
import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction;
|
||||||
import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage;
|
import org.elasticsearch.xpack.core.flattened.FlattenedFeatureSetUsage;
|
||||||
|
import org.elasticsearch.xpack.core.frozen.FrozenIndicesFeatureSetUsage;
|
||||||
import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage;
|
import org.elasticsearch.xpack.core.graph.GraphFeatureSetUsage;
|
||||||
import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
|
import org.elasticsearch.xpack.core.graph.action.GraphExploreAction;
|
||||||
import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction;
|
import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction;
|
||||||
|
@ -521,7 +522,9 @@ public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPl
|
||||||
// Vectors
|
// Vectors
|
||||||
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VECTORS, VectorsFeatureSetUsage::new),
|
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VECTORS, VectorsFeatureSetUsage::new),
|
||||||
// Voting Only Node
|
// Voting Only Node
|
||||||
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new)
|
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.VOTING_ONLY, VotingOnlyNodeFeatureSetUsage::new),
|
||||||
|
// Frozen indices
|
||||||
|
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.FROZEN_INDICES, FrozenIndicesFeatureSetUsage::new)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@ public final class XPackField {
|
||||||
public static final String VECTORS = "vectors";
|
public static final String VECTORS = "vectors";
|
||||||
/** Name constant for the voting-only-node feature. */
|
/** Name constant for the voting-only-node feature. */
|
||||||
public static final String VOTING_ONLY = "voting_only";
|
public static final String VOTING_ONLY = "voting_only";
|
||||||
|
/** Name constant for the frozen index feature. */
|
||||||
|
public static final String FROZEN_INDICES = "frozen_indices";
|
||||||
|
|
||||||
private XPackField() {}
|
private XPackField() {}
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,9 @@ import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.lucene.util.SetOnce;
|
import org.apache.lucene.util.SetOnce;
|
||||||
import org.elasticsearch.SpecialPermission;
|
import org.elasticsearch.SpecialPermission;
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.action.ActionType;
|
|
||||||
import org.elasticsearch.action.ActionRequest;
|
import org.elasticsearch.action.ActionRequest;
|
||||||
import org.elasticsearch.action.ActionResponse;
|
import org.elasticsearch.action.ActionResponse;
|
||||||
|
import org.elasticsearch.action.ActionType;
|
||||||
import org.elasticsearch.action.support.ActionFilter;
|
import org.elasticsearch.action.support.ActionFilter;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
|
@ -63,6 +63,7 @@ import org.elasticsearch.xpack.core.action.TransportXPackInfoAction;
|
||||||
import org.elasticsearch.xpack.core.action.TransportXPackUsageAction;
|
import org.elasticsearch.xpack.core.action.TransportXPackUsageAction;
|
||||||
import org.elasticsearch.xpack.core.action.XPackInfoAction;
|
import org.elasticsearch.xpack.core.action.XPackInfoAction;
|
||||||
import org.elasticsearch.xpack.core.action.XPackUsageAction;
|
import org.elasticsearch.xpack.core.action.XPackUsageAction;
|
||||||
|
import org.elasticsearch.xpack.core.frozen.FrozenIndicesFeatureSet;
|
||||||
import org.elasticsearch.xpack.core.ml.MlMetadata;
|
import org.elasticsearch.xpack.core.ml.MlMetadata;
|
||||||
import org.elasticsearch.xpack.core.rest.action.RestFreezeIndexAction;
|
import org.elasticsearch.xpack.core.rest.action.RestFreezeIndexAction;
|
||||||
import org.elasticsearch.xpack.core.rest.action.RestReloadAnalyzersAction;
|
import org.elasticsearch.xpack.core.rest.action.RestReloadAnalyzersAction;
|
||||||
|
@ -242,6 +243,7 @@ public class XPackPlugin extends XPackClientPlugin implements ExtensiblePlugin,
|
||||||
|
|
||||||
if (transportClientMode) {
|
if (transportClientMode) {
|
||||||
modules.add(b -> b.bind(XPackLicenseState.class).toProvider(Providers.of(null)));
|
modules.add(b -> b.bind(XPackLicenseState.class).toProvider(Providers.of(null)));
|
||||||
|
modules.add(b -> bindFeatureSet(b, FrozenIndicesFeatureSet.class));
|
||||||
}
|
}
|
||||||
return modules;
|
return modules;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.xpack.core.frozen;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.ActionListener;
|
||||||
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
import org.elasticsearch.index.engine.FrozenEngine;
|
||||||
|
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||||
|
import org.elasticsearch.xpack.core.XPackField;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class FrozenIndicesFeatureSet implements XPackFeatureSet {
|
||||||
|
|
||||||
|
private final ClusterService clusterService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public FrozenIndicesFeatureSet(ClusterService clusterService) {
|
||||||
|
this.clusterService = clusterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String name() {
|
||||||
|
return XPackField.FROZEN_INDICES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean available() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean enabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> nativeCodeInfo() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void usage(ActionListener<Usage> listener) {
|
||||||
|
int numFrozenIndices = 0;
|
||||||
|
for (IndexMetaData indexMetaData : clusterService.state().metaData()) {
|
||||||
|
if (FrozenEngine.INDEX_FROZEN.get(indexMetaData.getSettings())) {
|
||||||
|
numFrozenIndices++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listener.onResponse(new FrozenIndicesFeatureSetUsage(true, true, numFrozenIndices));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.xpack.core.frozen;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||||
|
import org.elasticsearch.xpack.core.XPackField;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class FrozenIndicesFeatureSetUsage extends XPackFeatureSet.Usage {
|
||||||
|
|
||||||
|
private final int numberOfFrozenIndices;
|
||||||
|
|
||||||
|
public FrozenIndicesFeatureSetUsage(StreamInput input) throws IOException {
|
||||||
|
super(input);
|
||||||
|
numberOfFrozenIndices = input.readVInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
super.writeTo(out);
|
||||||
|
out.writeVInt(numberOfFrozenIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FrozenIndicesFeatureSetUsage(boolean available, boolean enabled, int numberOfFrozenIndices) {
|
||||||
|
super(XPackField.FROZEN_INDICES, available, enabled);
|
||||||
|
this.numberOfFrozenIndices = numberOfFrozenIndices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void innerXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
super.innerXContent(builder, params);
|
||||||
|
builder.field("indices_count", numberOfFrozenIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfFrozenIndices() {
|
||||||
|
return numberOfFrozenIndices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(available, enabled, numberOfFrozenIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
FrozenIndicesFeatureSetUsage other = (FrozenIndicesFeatureSetUsage) obj;
|
||||||
|
return Objects.equals(available, other.available) &&
|
||||||
|
Objects.equals(enabled, other.enabled) &&
|
||||||
|
Objects.equals(numberOfFrozenIndices, other.numberOfFrozenIndices);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
package org.elasticsearch.xpack.core.frozen;
|
||||||
|
|
||||||
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
|
import org.elasticsearch.test.AbstractWireSerializingTestCase;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FrozenIndicesFeatureSetUsageTests extends AbstractWireSerializingTestCase<FrozenIndicesFeatureSetUsage> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FrozenIndicesFeatureSetUsage createTestInstance() {
|
||||||
|
boolean available = randomBoolean();
|
||||||
|
boolean enabled = randomBoolean();
|
||||||
|
return new FrozenIndicesFeatureSetUsage(available, enabled, randomIntBetween(0, 100000));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FrozenIndicesFeatureSetUsage mutateInstance(FrozenIndicesFeatureSetUsage instance) throws IOException {
|
||||||
|
boolean available = instance.available();
|
||||||
|
boolean enabled = instance.enabled();
|
||||||
|
int numFrozenIndices = instance.getNumberOfFrozenIndices();
|
||||||
|
switch (between(0, 2)) {
|
||||||
|
case 0:
|
||||||
|
available = available == false;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
enabled = enabled == false;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
numFrozenIndices = randomValueOtherThan(numFrozenIndices, () -> randomIntBetween(0, 100000));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError("Illegal randomisation branch");
|
||||||
|
}
|
||||||
|
return new FrozenIndicesFeatureSetUsage(available, enabled, numFrozenIndices);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Writeable.Reader<FrozenIndicesFeatureSetUsage> instanceReader() {
|
||||||
|
return FrozenIndicesFeatureSetUsage::new;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -52,7 +52,7 @@ setup:
|
||||||
|
|
||||||
# unfreeze index
|
# unfreeze index
|
||||||
- do:
|
- do:
|
||||||
indices.freeze:
|
indices.unfreeze:
|
||||||
index: test
|
index: test
|
||||||
wait_for_active_shards: 1
|
wait_for_active_shards: 1
|
||||||
- is_true: acknowledged
|
- is_true: acknowledged
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
---
|
||||||
|
setup:
|
||||||
|
- do:
|
||||||
|
indices.create:
|
||||||
|
index: test
|
||||||
|
- do:
|
||||||
|
cluster.health:
|
||||||
|
wait_for_no_initializing_shards: true
|
||||||
|
|
||||||
|
---
|
||||||
|
"Usage stats on frozen indices":
|
||||||
|
- skip:
|
||||||
|
version: " - 7.9.99"
|
||||||
|
reason: "frozen indices have usage stats starting in version 8.0.0"
|
||||||
|
|
||||||
|
- do:
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
id: 1
|
||||||
|
body: { "foo": "bar" }
|
||||||
|
|
||||||
|
- do:
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
id: 2
|
||||||
|
body: { "foo": "bar" }
|
||||||
|
|
||||||
|
- do:
|
||||||
|
index:
|
||||||
|
index: test
|
||||||
|
id: 3
|
||||||
|
body: { "foo": "bar" }
|
||||||
|
|
||||||
|
- do: {xpack.usage: {}}
|
||||||
|
- match: { frozen_indices.available: true }
|
||||||
|
- match: { frozen_indices.enabled: true }
|
||||||
|
- match: { frozen_indices.indices_count: 0 }
|
||||||
|
|
||||||
|
# freeze index
|
||||||
|
- do:
|
||||||
|
indices.freeze:
|
||||||
|
index: test
|
||||||
|
- is_true: acknowledged
|
||||||
|
|
||||||
|
|
||||||
|
- do: {xpack.usage: {}}
|
||||||
|
- match: { frozen_indices.available: true }
|
||||||
|
- match: { frozen_indices.enabled: true }
|
||||||
|
- match: { frozen_indices.indices_count: 1 }
|
||||||
|
|
||||||
|
# unfreeze index
|
||||||
|
- do:
|
||||||
|
indices.unfreeze:
|
||||||
|
index: test
|
||||||
|
- is_true: acknowledged
|
||||||
|
|
||||||
|
- do: {xpack.usage: {}}
|
||||||
|
- match: { frozen_indices.available: true }
|
||||||
|
- match: { frozen_indices.enabled: true }
|
||||||
|
- match: { frozen_indices.indices_count: 0 }
|
Loading…
Reference in New Issue