forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic searchable snapshots usage information (#58828) (#59160)
Adds super basic usage information for searchable snapshots, to be extended later. Backport of #58828
- Loading branch information
Showing
10 changed files
with
321 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...a/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotFeatureSetUsage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.searchablesnapshots; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ToXContent; | ||
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 SearchableSnapshotFeatureSetUsage extends XPackFeatureSet.Usage { | ||
|
||
private final int numberOfSearchableSnapshotIndices; | ||
|
||
public SearchableSnapshotFeatureSetUsage(StreamInput input) throws IOException { | ||
super(input); | ||
numberOfSearchableSnapshotIndices = input.readVInt(); | ||
} | ||
|
||
@Override | ||
public Version getMinimalSupportedVersion() { | ||
return Version.V_7_9_0; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeVInt(numberOfSearchableSnapshotIndices); | ||
} | ||
|
||
public SearchableSnapshotFeatureSetUsage(boolean available, | ||
int numberOfSearchableSnapshotIndices) { | ||
super(XPackField.SEARCHABLE_SNAPSHOTS, available, true); | ||
this.numberOfSearchableSnapshotIndices = numberOfSearchableSnapshotIndices; | ||
} | ||
|
||
@Override | ||
protected void innerXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
super.innerXContent(builder, params); | ||
builder.field("indices_count", numberOfSearchableSnapshotIndices); | ||
} | ||
|
||
public int getNumberOfSearchableSnapshotIndices() { | ||
return numberOfSearchableSnapshotIndices; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(available, enabled, numberOfSearchableSnapshotIndices); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
SearchableSnapshotFeatureSetUsage other = (SearchableSnapshotFeatureSetUsage) obj; | ||
return Objects.equals(available, other.available) && | ||
Objects.equals(enabled, other.enabled) && | ||
Objects.equals(numberOfSearchableSnapshotIndices, other.numberOfSearchableSnapshotIndices); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../java/org/elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* 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.searchablesnapshots; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshotsConstants; | ||
|
||
import java.util.Map; | ||
|
||
public class SearchableSnapshotsFeatureSet implements XPackFeatureSet { | ||
|
||
private final XPackLicenseState licenseState; | ||
private final ClusterService clusterService; | ||
|
||
@Inject | ||
public SearchableSnapshotsFeatureSet(@Nullable XPackLicenseState licenseState, ClusterService clusterService) { | ||
this.licenseState = licenseState; | ||
this.clusterService = clusterService; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return XPackField.SEARCHABLE_SNAPSHOTS; | ||
} | ||
|
||
@Override | ||
public boolean available() { | ||
return licenseState.isAllowed(XPackLicenseState.Feature.SEARCHABLE_SNAPSHOTS); | ||
} | ||
|
||
@Override | ||
public boolean enabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Map<String, Object> nativeCodeInfo() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void usage(ActionListener<XPackFeatureSet.Usage> listener) { | ||
ClusterState state = clusterService.state(); | ||
int numSnapIndices = 0; | ||
for (IndexMetadata indexMetadata : state.metadata()) { | ||
if (SearchableSnapshotsConstants.isSearchableSnapshotStore(indexMetadata.getSettings())) { | ||
numSnapIndices++; | ||
} | ||
} | ||
listener.onResponse( | ||
new SearchableSnapshotFeatureSetUsage( | ||
available(), | ||
numSnapIndices | ||
) | ||
); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...elasticsearch/xpack/core/searchablesnapshots/SearchableSnapshotsFeatureSetUsageTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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.searchablesnapshots; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class SearchableSnapshotsFeatureSetUsageTests extends AbstractWireSerializingTestCase<SearchableSnapshotFeatureSetUsage> { | ||
|
||
@Override | ||
protected SearchableSnapshotFeatureSetUsage createTestInstance() { | ||
boolean available = randomBoolean(); | ||
return new SearchableSnapshotFeatureSetUsage(available, randomIntBetween(0, 100000)); | ||
} | ||
|
||
@Override | ||
protected SearchableSnapshotFeatureSetUsage mutateInstance(SearchableSnapshotFeatureSetUsage instance) throws IOException { | ||
boolean available = instance.available(); | ||
int numSearchableSnapshotIndices = instance.getNumberOfSearchableSnapshotIndices(); | ||
switch (between(0, 1)) { | ||
case 0: | ||
available = available == false; | ||
break; | ||
case 1: | ||
numSearchableSnapshotIndices = randomValueOtherThan(numSearchableSnapshotIndices, () -> randomIntBetween(0, 100000)); | ||
break; | ||
default: | ||
throw new AssertionError("Illegal randomisation branch"); | ||
} | ||
return new SearchableSnapshotFeatureSetUsage(available, numSearchableSnapshotIndices); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<SearchableSnapshotFeatureSetUsage> instanceReader() { | ||
return SearchableSnapshotFeatureSetUsage::new; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.