diff --git a/libs/core/src/main/java/org/opensearch/rest/RestStatus.java b/libs/core/src/main/java/org/opensearch/rest/RestStatus.java index 8c718a5c8091c..affcc56b9d594 100644 --- a/libs/core/src/main/java/org/opensearch/rest/RestStatus.java +++ b/libs/core/src/main/java/org/opensearch/rest/RestStatus.java @@ -431,6 +431,13 @@ public enum RestStatus { * next-hop server. */ EXPECTATION_FAILED(417), + /** + * Any attempt to brew coffee with a teapot should result in the error code "418 I'm a teapot". The resulting + * entity body MAY be short and stout. + *
+ * @see I'm a teapot!
+ */
+ I_AM_A_TEAPOT(418),
/**
* The request was directed at a server that is not able to produce a response. This can be sent by a server
* that is not configured to produce responses for the combination of scheme and authority that are included
@@ -559,4 +566,8 @@ public static RestStatus status(int successfulShards, int totalShards, ShardOper
public static RestStatus fromCode(int code) {
return CODE_TO_STATUS.get(code);
}
+
+ public static Boolean isValidRestCode(int code) {
+ return null != fromCode(code);
+ }
}
diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.stats/11_indices_metrics.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.stats/11_indices_metrics.yml
index 1f1f42890355e..b0ce51902a7cc 100644
--- a/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.stats/11_indices_metrics.yml
+++ b/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.stats/11_indices_metrics.yml
@@ -138,6 +138,34 @@
- is_false: nodes.$node_id.indices.translog
- is_false: nodes.$node_id.indices.recovery
+---
+"Metric - indexing doc_status":
+ - skip:
+ features: [arbitrary_key]
+ - do:
+ nodes.info: {}
+ - set:
+ nodes._arbitrary_key_: node_id
+
+ - do:
+ nodes.stats: { metric: indices, index_metric: indexing }
+
+ - is_false: nodes.$node_id.indices.docs
+ - is_false: nodes.$node_id.indices.store
+ - is_true: nodes.$node_id.indices.indexing
+ - is_true: nodes.$node_id.indices.indexing.doc_status
+ - is_false: nodes.$node_id.indices.get
+ - is_false: nodes.$node_id.indices.search
+ - is_false: nodes.$node_id.indices.merges
+ - is_false: nodes.$node_id.indices.refresh
+ - is_false: nodes.$node_id.indices.flush
+ - is_false: nodes.$node_id.indices.warmer
+ - is_false: nodes.$node_id.indices.query_cache
+ - is_false: nodes.$node_id.indices.fielddata
+ - is_false: nodes.$node_id.indices.completion
+ - is_false: nodes.$node_id.indices.segments
+ - is_false: nodes.$node_id.indices.translog
+ - is_false: nodes.$node_id.indices.recovery
---
"Metric - recovery":
diff --git a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java
index 18a39afc48079..f7a26ae12e9c9 100644
--- a/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java
+++ b/server/src/main/java/org/opensearch/action/bulk/TransportBulkAction.java
@@ -80,6 +80,7 @@
import org.opensearch.index.seqno.SequenceNumbers;
import org.opensearch.index.shard.ShardId;
import org.opensearch.indices.IndexClosedException;
+import org.opensearch.indices.IndicesService;
import org.opensearch.indices.SystemIndices;
import org.opensearch.ingest.IngestService;
import org.opensearch.node.NodeClosedException;
@@ -130,6 +131,7 @@ public class TransportBulkAction extends HandledTransportAction> INDEXING_DOC_STATUS_KEYS_SETTING = Setting.listSetting(
+ "cluster.doc_status_keys",
+ INDEXING_DOC_STATUS_DEFAULT_KEYS,
+ IndicesService::validateDocStatusKey,
+ Property.Consistent,
+ Property.NodeScope
+ );
+
/**
* The node's settings.
*/
@@ -1015,6 +1046,18 @@ public IndicesQueryCache getIndicesQueryCache() {
return indicesQueryCache;
}
+ public void incrementDocStatusCounter(final RestStatus status) {
+ int code = status.getStatus();
+
+ if (INDEXING_DOC_STATUS_KEYS_SETTING.get(clusterService.getSettings()).contains(String.valueOf(code))) {
+ oldShardsStats
+ .indexingStats
+ .getTotal()
+ .getDocStatusStats()
+ .inc(code);
+ }
+ }
+
/**
* Statistics for old shards
*
diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java
index 0846a5f8dec5c..79237216ed16a 100644
--- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java
+++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIndicesThatCannotBeCreatedTests.java
@@ -154,6 +154,7 @@ private void indicesThatCannotBeCreatedTestCase(
Settings.EMPTY,
new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null)
),
+ null,
new SystemIndices(emptyMap())
) {
@Override
diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java
index 6a514b47e55a4..75928a179ad72 100644
--- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java
+++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionIngestTests.java
@@ -170,6 +170,7 @@ class TestTransportBulkAction extends TransportBulkAction {
SETTINGS,
new ClusterService(SETTINGS, new ClusterSettings(SETTINGS, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), null)
),
+ null,
new SystemIndices(emptyMap())
);
}
diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java
index d53b860e6524a..580bc46765809 100644
--- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java
+++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTests.java
@@ -114,6 +114,7 @@ class TestTransportBulkAction extends TransportBulkAction {
new Resolver(),
new AutoCreateIndex(Settings.EMPTY, clusterService.getClusterSettings(), new Resolver(), new SystemIndices(emptyMap())),
new IndexingPressureService(Settings.EMPTY, clusterService),
+ null,
new SystemIndices(emptyMap())
);
}
diff --git a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTookTests.java b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTookTests.java
index 2361b69e9b82c..854b0478932bf 100644
--- a/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTookTests.java
+++ b/server/src/test/java/org/opensearch/action/bulk/TransportBulkActionTookTests.java
@@ -278,6 +278,7 @@ static class TestTransportBulkAction extends TransportBulkAction {
indexNameExpressionResolver,
autoCreateIndex,
new IndexingPressureService(Settings.EMPTY, clusterService),
+ null,
new SystemIndices(emptyMap()),
relativeTimeProvider
);
diff --git a/server/src/test/java/org/opensearch/rest/RestStatusTests.java b/server/src/test/java/org/opensearch/rest/RestStatusTests.java
new file mode 100644
index 0000000000000..61c5cce0c08fe
--- /dev/null
+++ b/server/src/test/java/org/opensearch/rest/RestStatusTests.java
@@ -0,0 +1,23 @@
+/*
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * The OpenSearch Contributors require contributions made to
+ * this file be licensed under the Apache-2.0 license or a
+ * compatible open source license.
+ */
+
+package org.opensearch.rest;
+
+import org.opensearch.test.OpenSearchTestCase;
+
+public class RestStatusTests extends OpenSearchTestCase {
+
+ public void testValidRestCode() {
+ assertTrue(RestStatus.isValidRestCode(418));
+ }
+
+ public void testInvalidRestCode() {
+ assertFalse(RestStatus.isValidRestCode(1999));
+ }
+
+}
diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java
index 88899a1b282af..ec78575e85309 100644
--- a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java
+++ b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java
@@ -1977,6 +1977,7 @@ public void onFailure(final Exception e) {
indexNameExpressionResolver,
new AutoCreateIndex(settings, clusterSettings, indexNameExpressionResolver, new SystemIndices(emptyMap())),
new IndexingPressureService(settings, clusterService),
+ null,
new SystemIndices(emptyMap())
)
);