Skip to content

Commit 74b5bfd

Browse files
authored
Feature usage actions for archive (#83931)
Relates #81210
1 parent a7e57df commit 74b5bfd

File tree

17 files changed

+331
-77
lines changed

17 files changed

+331
-77
lines changed

benchmarks/src/main/resources/org/elasticsearch/benchmark/xcontent/monitor_cluster_stats.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,11 @@
12331233
"total" : 0,
12341234
"failed" : 0
12351235
}
1236+
},
1237+
"archive" : {
1238+
"available" : false,
1239+
"enabled" : true,
1240+
"indices_count" : 0
12361241
}
12371242
}
12381243
}

docs/reference/rest-api/info.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ Example response:
8181
"available" : true,
8282
"enabled" : true
8383
},
84+
"archive" : {
85+
"available" : true,
86+
"enabled" : true
87+
},
8488
"enrich" : {
8589
"available" : true,
8690
"enabled" : true

docs/reference/rest-api/usage.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ GET /_xpack/usage
395395
"aggregate_metric" : {
396396
"available" : true,
397397
"enabled" : true
398+
},
399+
"archive" : {
400+
"available" : true,
401+
"enabled" : true,
402+
"indices_count" : 0
398403
}
399404
}
400405
------------------------------------------------------------

server/src/main/java/org/elasticsearch/snapshots/RestoreService.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.apache.logging.log4j.LogManager;
1111
import org.apache.logging.log4j.Logger;
1212
import org.apache.logging.log4j.message.ParameterizedMessage;
13-
import org.elasticsearch.Build;
1413
import org.elasticsearch.Version;
1514
import org.elasticsearch.action.ActionListener;
1615
import org.elasticsearch.action.StepListener;
@@ -978,7 +977,8 @@ static void validateSnapshotRestorable(RestoreSnapshotRequest request, Repositor
978977
+ "]"
979978
);
980979
}
981-
if (skipVersionChecks(repository) == false && snapshotInfo.version().before(Version.CURRENT.minimumIndexCompatibilityVersion())) {
980+
if (ALLOW_BWC_INDICES_SETTING.get(repository.settings()) == false
981+
&& snapshotInfo.version().before(Version.CURRENT.minimumIndexCompatibilityVersion())) {
982982
throw new SnapshotRestoreException(
983983
new Snapshot(repository.name(), snapshotInfo.snapshotId()),
984984
"the snapshot was created with Elasticsearch version ["
@@ -1002,19 +1002,6 @@ static void validateSnapshotRestorable(RestoreSnapshotRequest request, Repositor
10021002
Setting.Property.NodeScope
10031003
);
10041004

1005-
private static boolean skipVersionChecks(RepositoryMetadata repositoryMetadata) {
1006-
if (Build.CURRENT.isSnapshot()) {
1007-
return ALLOW_BWC_INDICES_SETTING.get(repositoryMetadata.settings());
1008-
} else {
1009-
if (ALLOW_BWC_INDICES_SETTING.exists(repositoryMetadata.settings())) {
1010-
throw new IllegalArgumentException(
1011-
"Repository setting [" + ALLOW_BWC_INDICES_SETTING.getKey() + "] only allowed in release builds"
1012-
);
1013-
}
1014-
return false;
1015-
}
1016-
}
1017-
10181005
public static boolean failed(SnapshotInfo snapshot, String index) {
10191006
for (SnapshotShardFailure failure : snapshot.shardFailures()) {
10201007
if (index.equals(failure.index())) {

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackClientPlugin.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.elasticsearch.xpack.core.action.XPackUsageAction;
3737
import org.elasticsearch.xpack.core.aggregatemetric.AggregateMetricFeatureSetUsage;
3838
import org.elasticsearch.xpack.core.analytics.AnalyticsFeatureSetUsage;
39+
import org.elasticsearch.xpack.core.archive.ArchiveFeatureSetUsage;
3940
import org.elasticsearch.xpack.core.async.DeleteAsyncResultAction;
4041
import org.elasticsearch.xpack.core.ccr.AutoFollowMetadata;
4142
import org.elasticsearch.xpack.core.datastreams.DataStreamFeatureSetUsage;
@@ -552,7 +553,9 @@ public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
552553
// Data Streams
553554
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_STREAMS, DataStreamFeatureSetUsage::new),
554555
// Data Tiers
555-
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_TIERS, DataTiersFeatureSetUsage::new)
556+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.DATA_TIERS, DataTiersFeatureSetUsage::new),
557+
// Archive
558+
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.ARCHIVE, ArchiveFeatureSetUsage::new)
556559
)
557560
);
558561

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackField.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public final class XPackField {
7171
public static final String AGGREGATE_METRIC = "aggregate_metric";
7272
/** Name constant for the operator privileges feature. */
7373
public static final String OPERATOR_PRIVILEGES = "operator_privileges";
74+
/** Name constant for the archive feature. */
75+
public static final String ARCHIVE = "archive";
7476

7577
private XPackField() {}
7678

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackInfoFeatureAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class XPackInfoFeatureAction extends ActionType<XPackInfoFeatureResponse>
4747
public static final XPackInfoFeatureAction DATA_STREAMS = new XPackInfoFeatureAction(XPackField.DATA_STREAMS);
4848
public static final XPackInfoFeatureAction DATA_TIERS = new XPackInfoFeatureAction(XPackField.DATA_TIERS);
4949
public static final XPackInfoFeatureAction AGGREGATE_METRIC = new XPackInfoFeatureAction(XPackField.AGGREGATE_METRIC);
50+
public static final XPackInfoFeatureAction ARCHIVE = new XPackInfoFeatureAction(XPackField.ARCHIVE);
5051

5152
public static final List<XPackInfoFeatureAction> ALL;
5253
static {
@@ -74,7 +75,8 @@ public class XPackInfoFeatureAction extends ActionType<XPackInfoFeatureResponse>
7475
DATA_STREAMS,
7576
SEARCHABLE_SNAPSHOTS,
7677
DATA_TIERS,
77-
AGGREGATE_METRIC
78+
AGGREGATE_METRIC,
79+
ARCHIVE
7880
)
7981
);
8082
ALL = Collections.unmodifiableList(actions);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/action/XPackUsageFeatureAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class XPackUsageFeatureAction extends ActionType<XPackUsageFeatureRespons
4444
public static final XPackUsageFeatureAction DATA_STREAMS = new XPackUsageFeatureAction(XPackField.DATA_STREAMS);
4545
public static final XPackUsageFeatureAction DATA_TIERS = new XPackUsageFeatureAction(XPackField.DATA_TIERS);
4646
public static final XPackUsageFeatureAction AGGREGATE_METRIC = new XPackUsageFeatureAction(XPackField.AGGREGATE_METRIC);
47+
public static final XPackUsageFeatureAction ARCHIVE = new XPackUsageFeatureAction(XPackField.ARCHIVE);
4748

4849
static final List<XPackUsageFeatureAction> ALL = List.of(
4950
AGGREGATE_METRIC,
@@ -66,7 +67,8 @@ public class XPackUsageFeatureAction extends ActionType<XPackUsageFeatureRespons
6667
SQL,
6768
TRANSFORM,
6869
VOTING_ONLY,
69-
WATCHER
70+
WATCHER,
71+
ARCHIVE
7072
);
7173

7274
// public for testing
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.archive;
9+
10+
import org.elasticsearch.Version;
11+
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.xcontent.ToXContent;
14+
import org.elasticsearch.xcontent.XContentBuilder;
15+
import org.elasticsearch.xpack.core.XPackFeatureSet;
16+
import org.elasticsearch.xpack.core.XPackField;
17+
18+
import java.io.IOException;
19+
import java.util.Objects;
20+
21+
public class ArchiveFeatureSetUsage extends XPackFeatureSet.Usage {
22+
23+
private final int numberOfArchiveIndices;
24+
25+
public ArchiveFeatureSetUsage(StreamInput input) throws IOException {
26+
super(input);
27+
numberOfArchiveIndices = input.readVInt();
28+
}
29+
30+
@Override
31+
public Version getMinimalSupportedVersion() {
32+
return Version.V_8_2_0;
33+
}
34+
35+
@Override
36+
public void writeTo(StreamOutput out) throws IOException {
37+
super.writeTo(out);
38+
out.writeVInt(numberOfArchiveIndices);
39+
}
40+
41+
public ArchiveFeatureSetUsage(boolean available, int numberOfArchiveIndices) {
42+
super(XPackField.ARCHIVE, available, true);
43+
this.numberOfArchiveIndices = numberOfArchiveIndices;
44+
}
45+
46+
public int getNumberOfArchiveIndices() {
47+
return numberOfArchiveIndices;
48+
}
49+
50+
@Override
51+
protected void innerXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
52+
super.innerXContent(builder, params);
53+
builder.field("indices_count", numberOfArchiveIndices);
54+
}
55+
56+
@Override
57+
public int hashCode() {
58+
return Objects.hash(available, enabled, numberOfArchiveIndices);
59+
}
60+
61+
@Override
62+
public boolean equals(Object obj) {
63+
if (obj == null) {
64+
return false;
65+
}
66+
if (getClass() != obj.getClass()) {
67+
return false;
68+
}
69+
ArchiveFeatureSetUsage other = (ArchiveFeatureSetUsage) obj;
70+
return available == other.available && enabled == other.enabled && numberOfArchiveIndices == other.numberOfArchiveIndices;
71+
}
72+
73+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
package org.elasticsearch.xpack.core.archive;
8+
9+
import org.elasticsearch.common.io.stream.Writeable;
10+
import org.elasticsearch.test.AbstractWireSerializingTestCase;
11+
12+
import java.io.IOException;
13+
14+
public class ArchiveFeatureSetUsageTests extends AbstractWireSerializingTestCase<ArchiveFeatureSetUsage> {
15+
16+
@Override
17+
protected ArchiveFeatureSetUsage createTestInstance() {
18+
boolean available = randomBoolean();
19+
return new ArchiveFeatureSetUsage(available, randomIntBetween(0, 100000));
20+
}
21+
22+
@Override
23+
protected ArchiveFeatureSetUsage mutateInstance(ArchiveFeatureSetUsage instance) throws IOException {
24+
boolean available = instance.available();
25+
int numArchiveIndices = instance.getNumberOfArchiveIndices();
26+
switch (between(0, 1)) {
27+
case 0 -> available = available == false;
28+
case 1 -> numArchiveIndices = randomValueOtherThan(numArchiveIndices, () -> randomIntBetween(0, 100000));
29+
default -> throw new AssertionError("Illegal randomisation branch");
30+
}
31+
return new ArchiveFeatureSetUsage(available, numArchiveIndices);
32+
}
33+
34+
@Override
35+
protected Writeable.Reader<ArchiveFeatureSetUsage> instanceReader() {
36+
return ArchiveFeatureSetUsage::new;
37+
}
38+
39+
}

0 commit comments

Comments
 (0)