|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ZoiloMora\ElasticAPM\Processor; |
|
4
|
|
|
|
|
5
|
|
|
use ZoiloMora\ElasticAPM\Configuration\CoreConfiguration; |
|
6
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\ByIdFinder; |
|
7
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\ByParentIdFinder; |
|
8
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\FromEventsSpanBuilder; |
|
9
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\GroupBySpanTypes; |
|
10
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\GroupSpanByTransactionId; |
|
11
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\MeasurableEventsFinder; |
|
12
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\MetricsSetBuilder; |
|
13
|
|
|
use ZoiloMora\ElasticAPM\Processor\MetricSetProcessor\SelfDurationCalculator; |
|
14
|
|
|
|
|
15
|
|
|
final class Handler |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var Processor[] |
|
19
|
|
|
*/ |
|
20
|
|
|
private $processors; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param array $processors |
|
24
|
|
|
*/ |
|
25
|
11 |
|
public function __construct(array $processors) |
|
26
|
|
|
{ |
|
27
|
11 |
|
$this->assertProcessors($processors); |
|
28
|
|
|
|
|
29
|
10 |
|
$this->processors = $processors; |
|
30
|
10 |
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param CoreConfiguration $coreConfiguration |
|
34
|
|
|
* |
|
35
|
|
|
* @return Handler |
|
36
|
|
|
*/ |
|
37
|
9 |
|
public static function create(CoreConfiguration $coreConfiguration) |
|
38
|
|
|
{ |
|
39
|
9 |
|
$processors = []; |
|
40
|
|
|
|
|
41
|
9 |
|
if (true === $coreConfiguration->metricSet()) { |
|
42
|
9 |
|
$processors[] = new MetricSetProcessor( |
|
43
|
9 |
|
new MeasurableEventsFinder(), |
|
44
|
9 |
|
new FromEventsSpanBuilder( |
|
45
|
9 |
|
new ByParentIdFinder(), |
|
46
|
9 |
|
new SelfDurationCalculator() |
|
47
|
9 |
|
), |
|
48
|
9 |
|
new GroupSpanByTransactionId(), |
|
49
|
9 |
|
new ByIdFinder(), |
|
50
|
9 |
|
new GroupBySpanTypes(), |
|
51
|
9 |
|
new MetricsSetBuilder() |
|
52
|
9 |
|
); |
|
53
|
9 |
|
} |
|
54
|
|
|
|
|
55
|
9 |
|
return new self($processors); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param array $events |
|
60
|
|
|
* |
|
61
|
|
|
* @return array |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function execute(array $events) |
|
64
|
|
|
{ |
|
65
|
2 |
|
foreach ($this->processors as $processor) { |
|
66
|
1 |
|
$events = $processor($events); |
|
67
|
2 |
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
return $events; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param array $processors |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
11 |
|
private function assertProcessors(array $processors) |
|
78
|
|
|
{ |
|
79
|
11 |
|
foreach ($processors as $processor) { |
|
80
|
11 |
|
if (false === $processor instanceof Processor) { |
|
81
|
1 |
|
throw new \InvalidArgumentException('All elements must be of type Processor.'); |
|
82
|
|
|
} |
|
83
|
10 |
|
} |
|
84
|
10 |
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|