Lines
100.00%
8 / 8
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ReloadMetricSource | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 5 | 100.00% | 1 / 1 | |||
| collectMetrics | 100.00% | 8 / 8 | 100.00% | 1 / 1 | 5 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Metrics\Source; | |
| 6 | ||
| 7 | use Stewart\Runtime\Control\Protocol\Status\RuntimeSnapshot; | |
| 8 | use Stewart\Runtime\Lifecycle\ReloadOutcome; | |
| 9 | use Stewart\Runtime\Metrics\Exposition\MetricFamily; | |
| 10 | use Stewart\Runtime\Metrics\Exposition\MetricLabels; | |
| 11 | use Stewart\Runtime\Metrics\Exposition\MetricType; | |
| 12 | use Stewart\Runtime\Metrics\RuntimeMetricSource; | |
| 13 | ||
| 14 | final readonly class ReloadMetricSource implements RuntimeMetricSource | |
| 15 | { | |
| 16 | /** @return list<MetricFamily> */ | |
| 17 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 18 | { | |
| 19 | $reloads = new MetricFamily('stewart_reloads_total', 'Reloads since the daemon started, by outcome.', MetricType::Counter, ['outcome']); | |
| 20 | $reload = $snapshot->reload; | |
| 21 | ||
| 22 | foreach (ReloadOutcome::cases() as $outcome) { | |
| 23 | $reloads->recordSample(MetricLabels::fromLabel('outcome', $outcome->value), match ($outcome) { | |
| 24 | ReloadOutcome::Applied => $reload->applied ?? 0, | |
| 25 | ReloadOutcome::PartlyApplied => $reload->partlyApplied ?? 0, | |
| 26 | ReloadOutcome::Failed => $reload->failed ?? 0, | |
| 27 | }); | |
| 28 | } | |
| 29 | ||
| 30 | return [$reloads]; | |
| 31 | } | |
| 32 | } |