|
19 | 19 |
|
20 | 20 | package org.elasticsearch.ingest; |
21 | 21 |
|
| 22 | +import java.util.ArrayList; |
| 23 | +import java.util.Collections; |
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.HashSet; |
| 26 | +import java.util.List; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Objects; |
| 29 | +import java.util.Set; |
| 30 | +import java.util.concurrent.TimeUnit; |
| 31 | +import java.util.function.BiConsumer; |
| 32 | +import java.util.function.Consumer; |
| 33 | +import java.util.stream.Collectors; |
| 34 | + |
22 | 35 | import org.elasticsearch.ElasticsearchParseException; |
23 | 36 | import org.elasticsearch.ExceptionsHelper; |
24 | 37 | import org.elasticsearch.ResourceNotFoundException; |
|
36 | 49 | import org.elasticsearch.cluster.metadata.MetaData; |
37 | 50 | import org.elasticsearch.cluster.node.DiscoveryNode; |
38 | 51 | import org.elasticsearch.cluster.service.ClusterService; |
39 | | -import org.elasticsearch.common.collect.Tuple; |
40 | 52 | import org.elasticsearch.common.regex.Regex; |
41 | 53 | import org.elasticsearch.common.unit.TimeValue; |
42 | 54 | import org.elasticsearch.common.util.concurrent.AbstractRunnable; |
|
49 | 61 | import org.elasticsearch.script.ScriptService; |
50 | 62 | import org.elasticsearch.threadpool.ThreadPool; |
51 | 63 |
|
52 | | -import java.util.ArrayList; |
53 | | -import java.util.Collections; |
54 | | -import java.util.HashMap; |
55 | | -import java.util.HashSet; |
56 | | -import java.util.Iterator; |
57 | | -import java.util.List; |
58 | | -import java.util.Map; |
59 | | -import java.util.Objects; |
60 | | -import java.util.Set; |
61 | | -import java.util.concurrent.TimeUnit; |
62 | | -import java.util.function.BiConsumer; |
63 | | -import java.util.function.Consumer; |
64 | | - |
65 | 64 | /** |
66 | 65 | * Holder class for several ingest related services. |
67 | 66 | */ |
@@ -263,59 +262,11 @@ public void applyClusterState(final ClusterChangedEvent event) { |
263 | 262 | Pipeline originalPipeline = originalPipelines.get(id); |
264 | 263 | if (originalPipeline != null) { |
265 | 264 | pipeline.getMetrics().add(originalPipeline.getMetrics()); |
266 | | - List<Tuple<Processor, IngestMetric>> oldPerProcessMetrics = new ArrayList<>(); |
267 | | - List<Tuple<Processor, IngestMetric>> newPerProcessMetrics = new ArrayList<>(); |
268 | | - getProcessorMetrics(originalPipeline.getCompoundProcessor(), oldPerProcessMetrics); |
269 | | - getProcessorMetrics(pipeline.getCompoundProcessor(), newPerProcessMetrics); |
270 | | - //Best attempt to populate new processor metrics using a parallel array of the old metrics. This is not ideal since |
271 | | - //the per processor metrics may get reset when the arrays don't match. However, to get to an ideal model, unique and |
272 | | - //consistent id's per processor and/or semantic equals for each processor will be needed. |
273 | | - if (newPerProcessMetrics.size() == oldPerProcessMetrics.size()) { |
274 | | - Iterator<Tuple<Processor, IngestMetric>> oldMetricsIterator = oldPerProcessMetrics.iterator(); |
275 | | - for (Tuple<Processor, IngestMetric> compositeMetric : newPerProcessMetrics) { |
276 | | - String type = compositeMetric.v1().getType(); |
277 | | - IngestMetric metric = compositeMetric.v2(); |
278 | | - if (oldMetricsIterator.hasNext()) { |
279 | | - Tuple<Processor, IngestMetric> oldCompositeMetric = oldMetricsIterator.next(); |
280 | | - String oldType = oldCompositeMetric.v1().getType(); |
281 | | - IngestMetric oldMetric = oldCompositeMetric.v2(); |
282 | | - if (type.equals(oldType)) { |
283 | | - metric.add(oldMetric); |
284 | | - } |
285 | | - } |
286 | | - } |
287 | | - } |
288 | 265 | } |
289 | 266 | }); |
290 | 267 | } |
291 | 268 | } |
292 | 269 |
|
293 | | - /** |
294 | | - * Recursive method to obtain all of the non-failure processors for given compoundProcessor. Since conditionals are implemented as |
295 | | - * wrappers to the actual processor, always prefer the actual processor's metric over the conditional processor's metric. |
296 | | - * @param compoundProcessor The compound processor to start walking the non-failure processors |
297 | | - * @param processorMetrics The list of {@link Processor} {@link IngestMetric} tuples. |
298 | | - * @return the processorMetrics for all non-failure processor that belong to the original compoundProcessor |
299 | | - */ |
300 | | - private static List<Tuple<Processor, IngestMetric>> getProcessorMetrics(CompoundProcessor compoundProcessor, |
301 | | - List<Tuple<Processor, IngestMetric>> processorMetrics) { |
302 | | - //only surface the top level non-failure processors, on-failure processor times will be included in the top level non-failure |
303 | | - for (Tuple<Processor, IngestMetric> processorWithMetric : compoundProcessor.getProcessorsWithMetrics()) { |
304 | | - Processor processor = processorWithMetric.v1(); |
305 | | - IngestMetric metric = processorWithMetric.v2(); |
306 | | - if (processor instanceof CompoundProcessor) { |
307 | | - getProcessorMetrics((CompoundProcessor) processor, processorMetrics); |
308 | | - } else { |
309 | | - //Prefer the conditional's metric since it only includes metrics when the conditional evaluated to true. |
310 | | - if (processor instanceof ConditionalProcessor) { |
311 | | - metric = ((ConditionalProcessor) processor).getMetric(); |
312 | | - } |
313 | | - processorMetrics.add(new Tuple<>(processor, metric)); |
314 | | - } |
315 | | - } |
316 | | - return processorMetrics; |
317 | | - } |
318 | | - |
319 | 270 | private static Pipeline substitutePipeline(String id, ElasticsearchParseException e) { |
320 | 271 | String tag = e.getHeaderKeys().contains("processor_tag") ? e.getHeader("processor_tag").get(0) : null; |
321 | 272 | String type = e.getHeaderKeys().contains("processor_type") ? e.getHeader("processor_type").get(0) : "unknown"; |
@@ -420,42 +371,11 @@ protected void doRun() { |
420 | 371 | } |
421 | 372 |
|
422 | 373 | public IngestStats stats() { |
423 | | - IngestStats.Builder statsBuilder = new IngestStats.Builder(); |
424 | | - statsBuilder.addTotalMetrics(totalMetrics); |
425 | | - pipelines.forEach((id, pipeline) -> { |
426 | | - CompoundProcessor rootProcessor = pipeline.getCompoundProcessor(); |
427 | | - statsBuilder.addPipelineMetrics(id, pipeline.getMetrics()); |
428 | | - List<Tuple<Processor, IngestMetric>> processorMetrics = new ArrayList<>(); |
429 | | - getProcessorMetrics(rootProcessor, processorMetrics); |
430 | | - processorMetrics.forEach(t -> { |
431 | | - Processor processor = t.v1(); |
432 | | - IngestMetric processorMetric = t.v2(); |
433 | | - statsBuilder.addProcessorMetrics(id, getProcessorName(processor), processorMetric); |
434 | | - }); |
435 | | - }); |
436 | | - return statsBuilder.build(); |
437 | | - } |
438 | 374 |
|
439 | | - //package private for testing |
440 | | - static String getProcessorName(Processor processor){ |
441 | | - // conditionals are implemented as wrappers around the real processor, so get the real processor for the correct type for the name |
442 | | - if(processor instanceof ConditionalProcessor){ |
443 | | - processor = ((ConditionalProcessor) processor).getProcessor(); |
444 | | - } |
445 | | - StringBuilder sb = new StringBuilder(5); |
446 | | - sb.append(processor.getType()); |
| 375 | + Map<String, IngestStats.Stats> statsPerPipeline = |
| 376 | + pipelines.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getMetrics().createStats())); |
447 | 377 |
|
448 | | - if(processor instanceof PipelineProcessor){ |
449 | | - String pipelineName = ((PipelineProcessor) processor).getPipelineName(); |
450 | | - sb.append(":"); |
451 | | - sb.append(pipelineName); |
452 | | - } |
453 | | - String tag = processor.getTag(); |
454 | | - if(tag != null && !tag.isEmpty()){ |
455 | | - sb.append(":"); |
456 | | - sb.append(tag); |
457 | | - } |
458 | | - return sb.toString(); |
| 378 | + return new IngestStats(totalMetrics.createStats(), statsPerPipeline); |
459 | 379 | } |
460 | 380 |
|
461 | 381 | private void innerExecute(IndexRequest indexRequest, Pipeline pipeline, Consumer<IndexRequest> itemDroppedHandler) throws Exception { |
|
0 commit comments