@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function render(Collection $metrics) |
19 | 19 | { |
20 | - $text = $metrics->flatMap(function (MetricFamilySamples $family) { |
|
20 | + $text = $metrics->flatMap(function(MetricFamilySamples $family) { |
|
21 | 21 | return $this->transform($family); |
22 | 22 | })->implode("\n"); |
23 | 23 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | protected function serialize(Collection $labels): string |
33 | 33 | { |
34 | - $quoted = $labels->map(function (string $value) { |
|
34 | + $quoted = $labels->map(function(string $value) { |
|
35 | 35 | return "\"{$value}\""; |
36 | 36 | }); |
37 | 37 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | "# TYPE {$this->key($metric)} {$metric->type()}", |
55 | 55 | ]); |
56 | 56 | |
57 | - $metrics = $family->samples()->map(function (Sample $sample) { |
|
57 | + $metrics = $family->samples()->map(function(Sample $sample) { |
|
58 | 58 | $labels = $this->serialize($sample->labels()); |
59 | 59 | |
60 | 60 | return "{$sample->name()}{{$labels}} {$sample->value()}"; |
@@ -51,11 +51,11 @@ |
||
51 | 51 | ->merge($this->gauges) |
52 | 52 | ->merge($this->histograms) |
53 | 53 | ->merge($this->summaries) |
54 | - ->mapWithKeys(function (Metric $metric) { |
|
54 | + ->mapWithKeys(function(Metric $metric) { |
|
55 | 55 | return [ |
56 | 56 | get_class($metric) => $metric::storage()->collect($metric), |
57 | 57 | ]; |
58 | - })->map(function (Collection $samples, string $namespace) { |
|
58 | + })->map(function(Collection $samples, string $namespace) { |
|
59 | 59 | return new MetricFamilySamples(new $namespace, $samples); |
60 | 60 | })->values(); |
61 | 61 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | case $metric instanceof Histogram: |
52 | 52 | return $this->samples($metric, $items->merge($this->redis->hgetall("{$key}:SUM"))); |
53 | 53 | case $metric instanceof Summary: |
54 | - return $this->samples($metric, $items->map(function (string $key) { |
|
54 | + return $this->samples($metric, $items->map(function(string $key) { |
|
55 | 55 | return new Collection($this->redis->lrange($key, 0, -1)); |
56 | 56 | })); |
57 | 57 | default: |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | */ |
20 | 20 | protected function group(): Collection |
21 | 21 | { |
22 | - return parent::group()->map(function (Collection $stored) { |
|
22 | + return parent::group()->map(function(Collection $stored) { |
|
23 | 23 | return $stored->first(); |
24 | - })->map(function (array $stored) { |
|
24 | + })->map(function(array $stored) { |
|
25 | 25 | /** @var Collection $values */ |
26 | 26 | $values = $stored['value']; |
27 | 27 | $count = $values->count(); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | ->map($this->calculate($values->sort()->values(), $count)) |
32 | 32 | ->push(compact('count')) |
33 | 33 | ->push(['sum' => $values->sum()]) |
34 | - ->map(function ($item) use ($stored) { |
|
34 | + ->map(function($item) use ($stored) { |
|
35 | 35 | $item['labels'] = $stored['labels']; |
36 | 36 | |
37 | 37 | return $item; |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function sample(string $name): Closure |
46 | 46 | { |
47 | - return function (array $item) use ($name) { |
|
47 | + return function(array $item) use ($name) { |
|
48 | 48 | $labels = new Collection($item['labels']); |
49 | 49 | |
50 | 50 | if (array_key_exists('count', $item)) { |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | private function calculate(Collection $values, int $count): Closure |
69 | 69 | { |
70 | - return function (float $quantile) use ($count, $values) { |
|
70 | + return function(float $quantile) use ($count, $values) { |
|
71 | 71 | $index = $count * $quantile; |
72 | 72 | |
73 | 73 | $value = floor($index) === $index |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | $buckets = $this->metric->buckets()->push('+Inf'); |
24 | 24 | |
25 | - return parent::group()->map(function (Collection $stored) use ($buckets) { |
|
25 | + return parent::group()->map(function(Collection $stored) use ($buckets) { |
|
26 | 26 | $sum = $stored->pop(); |
27 | 27 | |
28 | 28 | if (array_key_exists('bucket', $sum)) { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | ->fill($this->all($buckets, $stored), new Collection) |
36 | 36 | ->push(['count' => $stored->sum('value')]) |
37 | 37 | ->push(['sum' => $sum['value']]) |
38 | - ->map(function ($item) use ($labels) { |
|
38 | + ->map(function($item) use ($labels) { |
|
39 | 39 | $item['labels'] = $labels; |
40 | 40 | |
41 | 41 | return $item; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function sample(string $name): Closure |
50 | 50 | { |
51 | - return function (array $item) use ($name) { |
|
51 | + return function(array $item) use ($name) { |
|
52 | 52 | $labels = new Collection($item['labels']); |
53 | 53 | |
54 | 54 | if (array_key_exists('count', $item)) { |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | { |
74 | 74 | $missing = $buckets |
75 | 75 | ->diff($stored->pluck('bucket')) |
76 | - ->map(function ($bucket) { |
|
76 | + ->map(function($bucket) { |
|
77 | 77 | return compact('bucket') + ['value' => 0]; |
78 | 78 | }); |
79 | 79 | |
80 | 80 | return $stored |
81 | - ->reject(function (array $item) use ($buckets) { |
|
81 | + ->reject(function(array $item) use ($buckets) { |
|
82 | 82 | return !$buckets->contains($item['bucket']); |
83 | 83 | })->merge($missing) |
84 | 84 | ->sort($this->sort()) |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | private function sort(): Closure |
92 | 92 | { |
93 | - return function (array $left, array $right) { |
|
93 | + return function(array $left, array $right) { |
|
94 | 94 | // Due to http://php.net/manual/en/language.types.string.php#language.types.string.conversion the |
95 | 95 | // bucket containing "+Inf" will be cast to 0. Sorting regularly would end up with it incorrectly |
96 | 96 | // sitting at the very first spot instead of where it belongs - at the end. |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function collect(): Collection |
41 | 41 | { |
42 | - return $this->group()->flatMap(function (Collection $group) { |
|
42 | + return $this->group()->flatMap(function(Collection $group) { |
|
43 | 43 | return $group->map($this->sample($this->key($this->metric))); |
44 | 44 | }); |
45 | 45 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | { |
52 | 52 | $labels = $this->metric->labels()->toArray(); |
53 | 53 | |
54 | - return $this->stored->map(function ($value, string $key) { |
|
54 | + return $this->stored->map(function($value, string $key) { |
|
55 | 55 | return json_decode($key, true) + compact('value'); |
56 | - })->reject(function (array $data) use ($labels) { |
|
56 | + })->reject(function(array $data) use ($labels) { |
|
57 | 57 | return !array_key_exists('labels', $data) |
58 | 58 | ?: array_keys($data['labels']) !== $labels; |
59 | - })->mapToGroups(function (array $item) { |
|
59 | + })->mapToGroups(function(array $item) { |
|
60 | 60 | return [ |
61 | 61 | json_encode($item['labels']) => $item, |
62 | 62 | ]; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | protected function sample(string $name): Closure |
72 | 72 | { |
73 | - return function (array $item) use ($name) { |
|
73 | + return function(array $item) use ($name) { |
|
74 | 74 | $value = $item['value']; |
75 | 75 | $labels = new Collection($item['labels']); |
76 | 76 |
@@ -66,7 +66,7 @@ |
||
66 | 66 | */ |
67 | 67 | protected function bucket(Histogram $histogram, float $value): array |
68 | 68 | { |
69 | - $bucket = $histogram->buckets()->first(function (float $bucket) use ($value) { |
|
69 | + $bucket = $histogram->buckets()->first(function(float $bucket) use ($value) { |
|
70 | 70 | return $value <= $bucket; |
71 | 71 | }, '+Inf'); |
72 | 72 |