19
19
import org .elasticsearch .action .ActionListener ;
20
20
import org .elasticsearch .action .DocWriteRequest ;
21
21
import org .elasticsearch .action .admin .cluster .node .info .NodeInfo ;
22
+ import org .elasticsearch .action .admin .cluster .node .info .NodesInfoMetrics ;
23
+ import org .elasticsearch .action .admin .cluster .node .info .NodesInfoRequest ;
22
24
import org .elasticsearch .action .admin .cluster .node .info .NodesInfoResponse ;
23
25
import org .elasticsearch .action .bulk .FailureStoreMetrics ;
24
26
import org .elasticsearch .action .bulk .IndexDocFailureStoreStatus ;
29
31
import org .elasticsearch .action .support .RefCountingRunnable ;
30
32
import org .elasticsearch .action .support .master .AcknowledgedResponse ;
31
33
import org .elasticsearch .client .internal .Client ;
34
+ import org .elasticsearch .client .internal .OriginSettingClient ;
32
35
import org .elasticsearch .cluster .ClusterChangedEvent ;
33
36
import org .elasticsearch .cluster .ClusterState ;
34
37
import org .elasticsearch .cluster .ClusterStateApplier ;
@@ -153,11 +156,24 @@ public static boolean locallySupportedIngestFeature(NodeFeature nodeFeature) {
153
156
private volatile ClusterState state ;
154
157
private final ProjectResolver projectResolver ;
155
158
private final FeatureService featureService ;
159
+ private final Consumer <ActionListener <NodesInfoResponse >> nodeInfoListener ;
156
160
157
161
private static BiFunction <Long , Runnable , Scheduler .ScheduledCancellable > createScheduler (ThreadPool threadPool ) {
158
162
return (delay , command ) -> threadPool .schedule (command , TimeValue .timeValueMillis (delay ), threadPool .generic ());
159
163
}
160
164
165
+ private static Consumer <ActionListener <NodesInfoResponse >> createNodeInfoListener (Client client ) {
166
+ // This client is only used to perform an internal implementation detail,
167
+ // so uses an internal origin context rather than the user context
168
+ final OriginSettingClient originSettingClient = new OriginSettingClient (client , INGEST_ORIGIN );
169
+ return (nodeListener ) -> {
170
+ NodesInfoRequest nodesInfoRequest = new NodesInfoRequest ();
171
+ nodesInfoRequest .clear ();
172
+ nodesInfoRequest .addMetric (NodesInfoMetrics .Metric .INGEST .metricName ());
173
+ originSettingClient .admin ().cluster ().nodesInfo (nodesInfoRequest , nodeListener );
174
+ };
175
+ }
176
+
161
177
public static MatcherWatchdog createGrokThreadWatchdog (Environment env , ThreadPool threadPool ) {
162
178
final Settings settings = env .settings ();
163
179
final BiFunction <Long , Runnable , Scheduler .ScheduledCancellable > scheduler = createScheduler (threadPool );
@@ -240,7 +256,8 @@ public IngestService(
240
256
MatcherWatchdog matcherWatchdog ,
241
257
FailureStoreMetrics failureStoreMetrics ,
242
258
ProjectResolver projectResolver ,
243
- FeatureService featureService
259
+ FeatureService featureService ,
260
+ Consumer <ActionListener <NodesInfoResponse >> nodeInfoListener
244
261
) {
245
262
this .clusterService = clusterService ;
246
263
this .scriptService = scriptService ;
@@ -264,6 +281,36 @@ public IngestService(
264
281
this .failureStoreMetrics = failureStoreMetrics ;
265
282
this .projectResolver = projectResolver ;
266
283
this .featureService = featureService ;
284
+ this .nodeInfoListener = nodeInfoListener ;
285
+ }
286
+
287
+ public IngestService (
288
+ ClusterService clusterService ,
289
+ ThreadPool threadPool ,
290
+ Environment env ,
291
+ ScriptService scriptService ,
292
+ AnalysisRegistry analysisRegistry ,
293
+ List <IngestPlugin > ingestPlugins ,
294
+ Client client ,
295
+ MatcherWatchdog matcherWatchdog ,
296
+ FailureStoreMetrics failureStoreMetrics ,
297
+ ProjectResolver projectResolver ,
298
+ FeatureService featureService
299
+ ) {
300
+ this (
301
+ clusterService ,
302
+ threadPool ,
303
+ env ,
304
+ scriptService ,
305
+ analysisRegistry ,
306
+ ingestPlugins ,
307
+ client ,
308
+ matcherWatchdog ,
309
+ failureStoreMetrics ,
310
+ projectResolver ,
311
+ featureService ,
312
+ createNodeInfoListener (client )
313
+ );
267
314
}
268
315
269
316
/**
@@ -282,6 +329,7 @@ public IngestService(
282
329
this .failureStoreMetrics = ingestService .failureStoreMetrics ;
283
330
this .projectResolver = ingestService .projectResolver ;
284
331
this .featureService = ingestService .featureService ;
332
+ this .nodeInfoListener = ingestService .nodeInfoListener ;
285
333
}
286
334
287
335
private static Map <String , Processor .Factory > processorFactories (List <IngestPlugin > ingestPlugins , Processor .Parameters parameters ) {
@@ -535,12 +583,8 @@ static List<PipelineConfiguration> innerGetPipelines(IngestMetadata ingestMetada
535
583
/**
536
584
* Stores the specified pipeline definition in the request.
537
585
*/
538
- public void putPipeline (
539
- ProjectId projectId ,
540
- PutPipelineRequest request ,
541
- ActionListener <AcknowledgedResponse > listener ,
542
- Consumer <ActionListener <NodesInfoResponse >> nodeInfoListener
543
- ) throws Exception {
586
+ public void putPipeline (ProjectId projectId , PutPipelineRequest request , ActionListener <AcknowledgedResponse > listener )
587
+ throws Exception {
544
588
if (isNoOpPipelineUpdate (state .metadata ().getProject (projectId ), request )) {
545
589
// existing pipeline matches request pipeline -- no need to update
546
590
listener .onResponse (AcknowledgedResponse .TRUE );
0 commit comments