Skip to content

Commit 99eaf02

Browse files
author
Rai
committed
Resolved the comments
Signed-off-by: Rai <nndri@amazon.com>
1 parent 8a39f44 commit 99eaf02

7 files changed

Lines changed: 51 additions & 74 deletions

File tree

server/src/main/java/org/opensearch/action/ingest/SimulateExecutionService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ void executeDocument(
9191
}
9292

9393
public void execute(SimulatePipelineRequest.Parsed request, ActionListener<SimulatePipelineResponse> listener) {
94-
9594
threadPool.executor(THREAD_POOL_NAME).execute(ActionRunnable.wrap(listener, l -> {
9695
final AtomicInteger counter = new AtomicInteger();
9796
final List<SimulateDocumentResult> responses = new CopyOnWriteArrayList<>(

server/src/main/java/org/opensearch/action/ingest/SimulatePipelineTransportAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.opensearch.common.xcontent.XContentHelper;
3939
import org.opensearch.core.action.ActionListener;
4040
import org.opensearch.core.common.io.stream.Writeable;
41-
import org.opensearch.ingest.IngestPipelineValidator;
4241
import org.opensearch.ingest.IngestService;
4342
import org.opensearch.tasks.Task;
4443
import org.opensearch.threadpool.ThreadPool;
@@ -89,7 +88,7 @@ protected void doExecute(Task task, SimulatePipelineRequest request, ActionListe
8988
return;
9089
}
9190

92-
IngestPipelineValidator.validateIngestPipeline(simulateRequest.getPipeline(), ingestService.getClusterService());
91+
ingestService.validateProcessorCountForIngestPipeline(simulateRequest.getPipeline());
9392

9493
executionService.execute(simulateRequest, listener);
9594
}

server/src/main/java/org/opensearch/common/settings/ClusterSettings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
import org.opensearch.indices.fielddata.cache.IndicesFieldDataCache;
133133
import org.opensearch.indices.recovery.RecoverySettings;
134134
import org.opensearch.indices.store.IndicesStore;
135-
import org.opensearch.ingest.IngestPipelineValidator;
135+
import org.opensearch.ingest.IngestService;
136136
import org.opensearch.monitor.fs.FsHealthService;
137137
import org.opensearch.monitor.fs.FsService;
138138
import org.opensearch.monitor.jvm.JvmGcMonitorService;
@@ -406,7 +406,7 @@ public void apply(Settings value, Settings current, Settings previous) {
406406
ClusterService.USER_DEFINED_METADATA,
407407
ClusterManagerService.MASTER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING, // deprecated
408408
ClusterManagerService.CLUSTER_MANAGER_SERVICE_SLOW_TASK_LOGGING_THRESHOLD_SETTING,
409-
IngestPipelineValidator.MAX_NUMBER_OF_INGEST_PROCESSORS,
409+
IngestService.MAX_NUMBER_OF_INGEST_PROCESSORS,
410410
SearchService.DEFAULT_SEARCH_TIMEOUT_SETTING,
411411
SearchService.DEFAULT_ALLOW_PARTIAL_SEARCH_RESULTS,
412412
TransportSearchAction.SHARD_COUNT_LIMIT_SETTING,

server/src/main/java/org/opensearch/ingest/IngestPipelineValidator.java

Lines changed: 0 additions & 54 deletions
This file was deleted.

server/src/main/java/org/opensearch/ingest/IngestService.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.opensearch.common.collect.Tuple;
6363
import org.opensearch.common.metrics.OperationMetrics;
6464
import org.opensearch.common.regex.Regex;
65+
import org.opensearch.common.settings.Setting;
6566
import org.opensearch.common.settings.Settings;
6667
import org.opensearch.common.unit.TimeValue;
6768
import org.opensearch.common.util.concurrent.AbstractRunnable;
@@ -107,6 +108,18 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
107108

108109
public static final String INGEST_ORIGIN = "ingest";
109110

111+
/**
112+
* Defines the limit for the number of processors which can run on a given document during ingestion.
113+
*/
114+
public static final Setting<Integer> MAX_NUMBER_OF_INGEST_PROCESSORS = Setting.intSetting(
115+
"cluster.ingest.max_number_processors",
116+
Integer.MAX_VALUE,
117+
1,
118+
Integer.MAX_VALUE,
119+
Setting.Property.NodeScope,
120+
Setting.Property.Dynamic
121+
);
122+
110123
private static final Logger logger = LogManager.getLogger(IngestService.class);
111124

112125
private final ClusterService clusterService;
@@ -123,6 +136,7 @@ public class IngestService implements ClusterStateApplier, ReportingService<Inge
123136
private final ClusterManagerTaskThrottler.ThrottlingKey putPipelineTaskKey;
124137
private final ClusterManagerTaskThrottler.ThrottlingKey deletePipelineTaskKey;
125138
private volatile ClusterState state;
139+
private volatile int maxIngestProcessorCount;
126140

127141
public IngestService(
128142
ClusterService clusterService,
@@ -156,6 +170,12 @@ public IngestService(
156170
// Task is onboarded for throttling, it will get retried from associated TransportClusterManagerNodeAction.
157171
putPipelineTaskKey = clusterService.registerClusterManagerTask(ClusterManagerTaskKeys.PUT_PIPELINE_KEY, true);
158172
deletePipelineTaskKey = clusterService.registerClusterManagerTask(ClusterManagerTaskKeys.DELETE_PIPELINE_KEY, true);
173+
clusterService.getClusterSettings().addSettingsUpdateConsumer(MAX_NUMBER_OF_INGEST_PROCESSORS, this::setMaxIngestProcessorCount);
174+
setMaxIngestProcessorCount(clusterService.getClusterSettings().get(MAX_NUMBER_OF_INGEST_PROCESSORS));
175+
}
176+
177+
private void setMaxIngestProcessorCount(Integer maxIngestProcessorCount) {
178+
this.maxIngestProcessorCount = maxIngestProcessorCount;
159179
}
160180

161181
private static Map<String, Processor.Factory> processorFactories(List<IngestPlugin> ingestPlugins, Processor.Parameters parameters) {
@@ -495,7 +515,7 @@ void validatePipeline(Map<DiscoveryNode, IngestInfo> ingestInfos, PutPipelineReq
495515
Map<String, Object> pipelineConfig = XContentHelper.convertToMap(request.getSource(), false, request.getMediaType()).v2();
496516
Pipeline pipeline = Pipeline.create(request.getId(), pipelineConfig, processorFactories, scriptService);
497517

498-
IngestPipelineValidator.validateIngestPipeline(pipeline, clusterService);
518+
validateProcessorCountForIngestPipeline(pipeline);
499519

500520
List<Exception> exceptions = new ArrayList<>();
501521
for (Processor processor : pipeline.flattenAllProcessors()) {
@@ -510,6 +530,20 @@ void validatePipeline(Map<DiscoveryNode, IngestInfo> ingestInfos, PutPipelineReq
510530
ExceptionsHelper.rethrowAndSuppress(exceptions);
511531
}
512532

533+
public void validateProcessorCountForIngestPipeline(Pipeline pipeline) {
534+
List<Processor> processors = pipeline.getCompoundProcessor().getProcessors();
535+
536+
if (processors.size() > maxIngestProcessorCount) {
537+
throw new IllegalStateException(
538+
"Cannot use more than the maximum processors allowed. Number of processors being configured is ["
539+
+ processors.size()
540+
+ "] which exceeds the maximum allowed configuration of ["
541+
+ maxIngestProcessorCount
542+
+ "] processors."
543+
);
544+
}
545+
}
546+
513547
public void executeBulkRequest(
514548
int numberOfActionRequests,
515549
Iterable<DocWriteRequest<?>> actionRequests,
@@ -1102,7 +1136,6 @@ void innerUpdatePipelines(IngestMetadata newIngestMetadata) {
11021136
processorFactories,
11031137
scriptService
11041138
);
1105-
IngestPipelineValidator.validateIngestPipeline(newPipeline, clusterService);
11061139
newPipelines.put(newConfiguration.getId(), new PipelineHolder(newConfiguration, newPipeline));
11071140

11081141
if (previous == null) {

server/src/test/java/org/opensearch/cluster/service/ClusterServiceTests.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.opensearch.common.settings.ClusterSettings;
1212
import org.opensearch.common.settings.Settings;
13-
import org.opensearch.ingest.IngestPipelineValidator;
1413
import org.opensearch.test.OpenSearchTestCase;
1514
import org.opensearch.threadpool.TestThreadPool;
1615
import org.junit.After;
@@ -38,16 +37,4 @@ public void testDeprecatedGetMasterServiceBWC() {
3837
assertThat(masterService, equalTo(clusterManagerService));
3938
}
4039
}
41-
42-
public void testUpdateMaxIngestProcessorCountSetting() {
43-
ClusterSettings clusterSettings = new ClusterSettings(Settings.builder().build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
44-
45-
// verify defaults
46-
assertEquals(Integer.MAX_VALUE, clusterSettings.get(IngestPipelineValidator.MAX_NUMBER_OF_INGEST_PROCESSORS).intValue());
47-
48-
// verify update max processor
49-
Settings newSettings = Settings.builder().put("cluster.ingest.max_number_processors", 3).build();
50-
clusterSettings.applySettings(newSettings);
51-
assertEquals(3, clusterSettings.get(IngestPipelineValidator.MAX_NUMBER_OF_INGEST_PROCESSORS).intValue());
52-
}
5340
}

server/src/test/java/org/opensearch/ingest/IngestServiceTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.opensearch.cluster.service.ClusterService;
5959
import org.opensearch.common.SetOnce;
6060
import org.opensearch.common.metrics.OperationStats;
61+
import org.opensearch.common.settings.ClusterSettings;
6162
import org.opensearch.common.settings.Settings;
6263
import org.opensearch.common.util.concurrent.OpenSearchExecutors;
6364
import org.opensearch.common.xcontent.XContentType;
@@ -2058,6 +2059,18 @@ public void testPrepareBatches_different_index_pipeline() {
20582059
assertEquals(4, batches.size());
20592060
}
20602061

2062+
public void testUpdateMaxIngestProcessorCountSetting() {
2063+
ClusterSettings clusterSettings = new ClusterSettings(Settings.builder().build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
2064+
2065+
// verify defaults
2066+
assertEquals(Integer.MAX_VALUE, clusterSettings.get(IngestService.MAX_NUMBER_OF_INGEST_PROCESSORS).intValue());
2067+
2068+
// verify update max processor
2069+
Settings newSettings = Settings.builder().put("cluster.ingest.max_number_processors", 3).build();
2070+
clusterSettings.applySettings(newSettings);
2071+
assertEquals(3, clusterSettings.get(IngestService.MAX_NUMBER_OF_INGEST_PROCESSORS).intValue());
2072+
}
2073+
20612074
private IngestService.IndexRequestWrapper createIndexRequestWrapper(String index, List<String> pipelines) {
20622075
IndexRequest indexRequest = new IndexRequest(index);
20632076
return new IngestService.IndexRequestWrapper(0, indexRequest, pipelines, true);

0 commit comments

Comments
 (0)