Skip to content
Draft
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 @@ -78,6 +78,10 @@
],
"description":"A health status (\"green\", \"yellow\", or \"red\" to filter only indices matching the specified health status"
},
"system":{
"type":"boolean",
"description":"If specified, return only system indices when true or only non-system indices when false"
},
"help":{
"type":"boolean",
"description":"Return help information",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ public class ActionModule extends AbstractModule {
private final RequestValidators<IndicesAliasesRequest> indicesAliasesRequestRequestValidators;
private final ThreadPool threadPool;
private final ExtensionsManager extensionsManager;
private final SystemIndices systemIndices;
private final ResponseLimitSettings responseLimitSettings;

public ActionModule(
Expand All @@ -607,6 +608,7 @@ public ActionModule(
this.actionPlugins = actionPlugins;
this.threadPool = threadPool;
this.extensionsManager = extensionsManager;
this.systemIndices = systemIndices;
actions = setupActions(actionPlugins);
actionFilters = setupActionFilters(actionPlugins);
dynamicActionRegistry = new DynamicActionRegistry();
Expand Down Expand Up @@ -1059,7 +1061,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestClusterManagerAction());
registerHandler.accept(new RestNodesAction());
registerHandler.accept(new RestTasksAction(nodesInCluster));
registerHandler.accept(new RestIndicesAction(responseLimitSettings));
registerHandler.accept(new RestIndicesAction(responseLimitSettings, systemIndices));
registerHandler.accept(new RestSegmentsAction(responseLimitSettings));
// Fully qualified to prevent interference with rest.action.count.RestCountAction
registerHandler.accept(new org.opensearch.rest.action.cat.RestCountAction());
Expand All @@ -1077,7 +1079,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestTemplatesAction());

// LIST API
registerHandler.accept(new RestIndicesListAction(responseLimitSettings));
registerHandler.accept(new RestIndicesListAction(responseLimitSettings, systemIndices));
registerHandler.accept(new RestShardsListAction());

// Point in time API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.opensearch.core.common.Strings;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.merge.MergedSegmentWarmerStats;
import org.opensearch.indices.SystemIndexDescriptor;
import org.opensearch.indices.SystemIndices;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.RestResponse;
import org.opensearch.rest.action.RestResponseListener;
Expand Down Expand Up @@ -106,10 +108,12 @@ public class RestIndicesAction extends AbstractListAction {
private static final String DUPLICATE_PARAMETER_ERROR_MESSAGE =
"Please only use one of the request parameters [master_timeout, cluster_manager_timeout].";

private final SystemIndices systemIndices;
private final ResponseLimitSettings responseLimitSettings;

public RestIndicesAction(ResponseLimitSettings responseLimitSettings) {
public RestIndicesAction(ResponseLimitSettings responseLimitSettings, SystemIndices systemIndices) {
this.responseLimitSettings = responseLimitSettings;
this.systemIndices = systemIndices;
}

@Override
Expand Down Expand Up @@ -397,7 +401,7 @@ public void onFailure(final Exception e) {
private static final Set<String> RESPONSE_PARAMS;

static {
final Set<String> responseParams = new HashSet<>(asList("local", "health"));
final Set<String> responseParams = new HashSet<>(asList("local", "health", "system"));
responseParams.addAll(AbstractCatAction.RESPONSE_PARAMS);
RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams);
}
Expand Down Expand Up @@ -430,6 +434,13 @@ protected Table getTableWithHeader(final RestRequest request, final PageToken pa
table.addCell("store.size", "sibling:pri;alias:ss,storeSize;text-align:right;desc:store size of primaries & replicas");
table.addCell("pri.store.size", "text-align:right;desc:store size of primaries");

final String systemColumnDefault = request.hasParam("system") ? "" : "default:false;";
table.addCell("system", "alias:sys;" + systemColumnDefault + "desc:whether the index is a system index");
table.addCell(
"system.description",
"alias:sysdesc;" + systemColumnDefault + "desc:description from the matching system index descriptor"
);

table.addCell("completion.size", "sibling:pri;alias:cs,completionSize;default:false;text-align:right;desc:size of completion");
table.addCell("pri.completion.size", "default:false;text-align:right;desc:size of completion");

Expand Down Expand Up @@ -899,6 +910,7 @@ protected Table buildTable(
final PageToken pageToken
) {
final String healthParam = request.param("health");
final Boolean systemParam = request.hasParam("system") ? request.paramAsBoolean("system", false) : null;
final Table table = getTableWithHeader(request, pageToken);

while (tableIterator.hasNext()) {
Expand Down Expand Up @@ -942,6 +954,10 @@ protected Table buildTable(
}
}

if (systemParam != null && systemParam != indexMetadata.isSystem()) {
continue;
}

final CommonStats primaryStats;
final CommonStats totalStats;

Expand Down Expand Up @@ -971,6 +987,10 @@ protected Table buildTable(
table.addCell(totalStats.getStore() == null ? null : totalStats.getStore().size());
table.addCell(primaryStats.getStore() == null ? null : primaryStats.getStore().size());

table.addCell(indexMetadata.isSystem());
SystemIndexDescriptor descriptor = indexMetadata.isSystem() ? systemIndices.findMatchingDescriptor(indexName) : null;
table.addCell(descriptor == null ? null : descriptor.getDescription());

table.addCell(totalStats.getCompletion() == null ? null : totalStats.getCompletion().getSize());
table.addCell(primaryStats.getCompletion() == null ? null : primaryStats.getCompletion().getSize());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.opensearch.common.breaker.ResponseLimitSettings;
import org.opensearch.common.collect.Tuple;
import org.opensearch.common.settings.Settings;
import org.opensearch.indices.SystemIndices;
import org.opensearch.rest.RestRequest;
import org.opensearch.rest.action.cat.RestIndicesAction;

Expand All @@ -36,8 +37,8 @@ public class RestIndicesListAction extends RestIndicesAction {
private static final int MAX_SUPPORTED_LIST_INDICES_PAGE_SIZE = 5000;
private static final int DEFAULT_LIST_INDICES_PAGE_SIZE = 500;

public RestIndicesListAction(final ResponseLimitSettings responseLimitSettings) {
super(responseLimitSettings);
public RestIndicesListAction(final ResponseLimitSettings responseLimitSettings, final SystemIndices systemIndices) {
super(responseLimitSettings, systemIndices);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.indices.SystemIndices;
import org.opensearch.rest.BaseRestHandler;
import org.opensearch.rest.action.admin.cluster.RestCleanupRepositoryAction;
import org.opensearch.rest.action.admin.cluster.RestCloneSnapshotAction;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void testCatIndices() {
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
Settings settings = Settings.builder().build();
ResponseLimitSettings responseLimitSettings = new ResponseLimitSettings(clusterSettings, settings);
RestIndicesAction action = new RestIndicesAction(responseLimitSettings);
RestIndicesAction action = new RestIndicesAction(responseLimitSettings, new SystemIndices(Collections.emptyMap()));
Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(getRestRequestWithBothParams(), client));
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE));
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE);
Expand Down
Loading
Loading