Skip to content

Add a flag to set whether a system index is readable on SystemIndexDescriptor #17296

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

Closed
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Added ability to retrieve value from DocValues in a flat_object filed([#16802](https://github.com/opensearch-project/OpenSearch/pull/16802))
- Improve performace of NumericTermAggregation by avoiding unnecessary sorting([#17252](https://github.com/opensearch-project/OpenSearch/pull/17252))
- [Rule Based Auto-tagging] Add in-memory attribute value store ([#17342](https://github.com/opensearch-project/OpenSearch/pull/17342))
- Add a flag to set whether a system index is readable on SystemIndexDescriptor ([#17296](https://github.com/opensearch-project/OpenSearch/pull/17296))

### Dependencies
- Bump `org.awaitility:awaitility` from 4.2.0 to 4.3.0 ([#17230](https://github.com/opensearch-project/OpenSearch/pull/17230), [#17439](https://github.com/opensearch-project/OpenSearch/pull/17439))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ public class SystemIndexDescriptor {
private final String indexPattern;
private final String description;
private final CharacterRunAutomaton indexPatternAutomaton;
private boolean readable;

/**
*
* @param indexPattern The pattern of index names that this descriptor will be used for. Must start with a '.' character.
* @param description The name of the plugin responsible for this system index.
* @param readable Whether this system index is readable. A readable index is one where search and get actions are permitted.
*/
public SystemIndexDescriptor(String indexPattern, String description) {
public SystemIndexDescriptor(String indexPattern, String description, boolean readable) {
Objects.requireNonNull(indexPattern, "system index pattern must not be null");
if (indexPattern.length() < 2) {
throw new IllegalArgumentException(
Expand All @@ -79,6 +81,16 @@ public SystemIndexDescriptor(String indexPattern, String description) {
Automaton a = Operations.determinize(Regex.simpleMatchToAutomaton(indexPattern), Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);
this.indexPatternAutomaton = new CharacterRunAutomaton(a);
this.description = description;
this.readable = readable;
}

/**
*
* @param indexPattern The pattern of index names that this descriptor will be used for. Must start with a '.' character.
* @param description The name of the plugin responsible for this system index.
*/
public SystemIndexDescriptor(String indexPattern, String description) {
this(indexPattern, description, false);
}

/**
Expand All @@ -104,9 +116,33 @@ public String getDescription() {
return description;
}

/**
* @return A boolean corresponding to whether this system index is readable.
*/
public boolean isReadable() {
return readable;
}

@Override
public String toString() {
return "SystemIndexDescriptor[pattern=[" + indexPattern + "], description=[" + description + "]]";
return "SystemIndexDescriptor[pattern=[" + indexPattern + "], description=[" + description + "], readable=[" + readable + "]]";
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof SystemIndexDescriptor)) {
return false;
}
SystemIndexDescriptor other = (SystemIndexDescriptor) obj;
return indexPattern.equals(other.indexPattern);
}

@Override
public int hashCode() {
return Objects.hash(indexPattern);
}

// TODO: Index settings and mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public static Set<String> matchesSystemIndexPattern(Set<String> indexExpressions
return indexExpressions.stream().filter(pattern -> Regex.simpleMatch(SYSTEM_INDEX_PATTERNS, pattern)).collect(Collectors.toSet());
}

public static Set<SystemIndexDescriptor> matchesSystemIndexDescriptor(Set<String> indexExpressions) {
return getAllDescriptors().stream()
.filter(descriptor -> indexExpressions.stream().anyMatch(pattern -> Regex.simpleMatch(descriptor.getIndexPattern(), pattern)))
.collect(Collectors.toSet());
}

public static Set<String> matchesPluginSystemIndexPattern(String pluginClassName, Set<String> indexExpressions) {
if (!SYSTEM_INDEX_DESCRIPTORS_MAP.containsKey(pluginClassName)) {
return Collections.emptySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.opensearch.tasks.TaskResultsService.TASK_INDEX;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
Expand Down Expand Up @@ -189,6 +191,16 @@ public void testSystemIndexMatching() {
equalTo(Set.of(".system-index1", ".system-index-pattern1"))
);
assertThat(SystemIndexRegistry.matchesSystemIndexPattern(Set.of(".not-system")), equalTo(Collections.emptySet()));

assertThat(
SystemIndexRegistry.matchesSystemIndexDescriptor(Set.of(".system-index1", ".system-index2")),
containsInAnyOrder(
Stream.concat(
plugin1.getSystemIndexDescriptors(Settings.EMPTY).stream(),
plugin2.getSystemIndexDescriptors(Settings.EMPTY).stream()
).toArray()
)
);
}

public void testRegisteredSystemIndexGetAllDescriptors() {
Expand Down
Loading