Lines
100.00%
7 / 7
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| DeployMetricSource | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | 100.00% | 1 / 1 | |||
| collectMetrics | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | |||||
| 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\Metrics\Exposition\MetricFamily; | |
| 9 | use Stewart\Runtime\Metrics\Exposition\MetricLabels; | |
| 10 | use Stewart\Runtime\Metrics\Exposition\MetricType; | |
| 11 | use Stewart\Runtime\Metrics\RuntimeMetricSource; | |
| 12 | ||
| 13 | final readonly class DeployMetricSource implements RuntimeMetricSource | |
| 14 | { | |
| 15 | /** @return list<MetricFamily> */ | |
| 16 | public function collectMetrics(RuntimeSnapshot $snapshot): array | |
| 17 | { | |
| 18 | $deploy = $snapshot->deploy; | |
| 19 | $info = new MetricFamily('stewart_deploy_info', 'Commit the daemon runs while it polls for new ones; always 1.', MetricType::Gauge); | |
| 20 | $failures = new MetricFamily('stewart_deploy_failures_total', 'New commits that failed stewart check and were not deployed.', MetricType::Counter); | |
| 21 | ||
| 22 | if ($deploy !== null) { | |
| 23 | $info->recordSample(MetricLabels::fromLabel('commit', $deploy->commit), 1); | |
| 24 | $failures->recordSample(MetricLabels::none(), $deploy->failures); | |
| 25 | } | |
| 26 | ||
| 27 | return [$info, $failures]; | |
| 28 | } | |
| 29 | } |