Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 12 |
| ProviderAbstract | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 12 |
| mustScaleUp | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| mustScaleDown | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| stats | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 4 |
|||
| getStats | n/a |
0 / 0 |
0 | n/a |
0 / 0 |
|||||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\DockerScale\Scaler\Providers; |
| 4 | |
| 5 | use Illuminate\Support\Facades\Log; |
| 6 | use Qmp\Laravel\DockerScale\Models\DockerScalerConfig; |
| 7 | |
| 8 | abstract class ProviderAbstract |
| 9 | { |
| 10 | protected static $stat = []; |
| 11 | |
| 12 | public static function mustScaleUp(DockerScalerConfig $config): bool |
| 13 | { |
| 14 | $actualReplicas = $config->service->total_replicas; |
| 15 | |
| 16 | if ($actualReplicas < $config->max_replicas) { |
| 17 | return $config->alert_up <= self::stats($config); |
| 18 | } |
| 19 | |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | public static function mustScaleDown(DockerScalerConfig $config): bool |
| 24 | { |
| 25 | $actualReplicas = $config->service->total_replicas; |
| 26 | |
| 27 | if ($actualReplicas > $config->min_replicas) { |
| 28 | return $config->alert_down >= self::stats($config); |
| 29 | } |
| 30 | |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | protected static function stats(DockerScalerConfig $config): float |
| 35 | { |
| 36 | if (!isset(self::$stat[$config->id . $config->type])) { |
| 37 | $stat = self::$stat[$config->id . $config->type] = static::getStats($config); |
| 38 | Log::debug("stats:{$config->id}-{$config->service->name}-{$config->type}:{$stat}(min:{$config->alert_down},max:{$config->alert_up})[rep:{$config->service->total_replicas}({$config->min_replicas}|{$config->max_replicas})]"); |
| 39 | } |
| 40 | |
| 41 | return self::$stat[$config->id . $config->type]; |
| 42 | } |
| 43 | |
| 44 | abstract protected static function getStats(DockerScalerConfig $config): float; |
| 45 | } |