| Total Complexity | 8 |
| Total Lines | 72 |
| Duplicated Lines | 0 % |
| Coverage | 88.89% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | abstract class Histogram extends Metric implements Observable |
||
| 12 | { |
||
| 13 | use TracksExecutionTime; |
||
| 14 | |||
| 15 | protected array $buckets = [ |
||
| 16 | .005, |
||
| 17 | .01, |
||
| 18 | .025, |
||
| 19 | .05, |
||
| 20 | .1, |
||
| 21 | .25, |
||
| 22 | .5, |
||
| 23 | 1, |
||
| 24 | 2.5, |
||
| 25 | 5, |
||
| 26 | 10, |
||
| 27 | ]; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | 17 | public function __construct() |
|
| 33 | { |
||
| 34 | 17 | parent::__construct(); |
|
| 35 | |||
| 36 | 17 | foreach ($this->labels as $label) { |
|
| 37 | 15 | if (preg_match('/^le$/', $label)) { |
|
| 38 | 1 | throw new LabelException('The label `le` is used internally to designate buckets.'); |
|
| 39 | } |
||
| 40 | } |
||
| 41 | |||
| 42 | 16 | if (count($this->buckets) < 1) { |
|
| 43 | 1 | throw new PrometheusException('Histograms must contain at least one bucket.'); |
|
| 44 | } |
||
| 45 | |||
| 46 | 15 | sort($this->buckets); |
|
| 47 | 15 | } |
|
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | 4 | public function type(): string |
|
| 53 | { |
||
| 54 | 4 | return 'histogram'; |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | * |
||
| 60 | * @return self |
||
| 61 | */ |
||
| 62 | 4 | public function observe(float $value, array $labels = []): self |
|
| 63 | { |
||
| 64 | 4 | static::$storage->observe($this, $value, $labels); |
|
| 65 | |||
| 66 | 4 | return $this; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return Collection |
||
| 71 | */ |
||
| 72 | 12 | public function buckets(): Collection |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | protected function track(float $value, array $labels = []): void |
||
| 83 | } |
||
| 84 | } |
||
| 85 |