diff --git a/legacy/src/Command/Metrics/MetricsCommandBase.php b/legacy/src/Command/Metrics/MetricsCommandBase.php index ef8e92f7b..598ef8afa 100644 --- a/legacy/src/Command/Metrics/MetricsCommandBase.php +++ b/legacy/src/Command/Metrics/MetricsCommandBase.php @@ -40,7 +40,8 @@ abstract class MetricsCommandBase extends CommandBase public const MIN_INTERVAL = 60; // 1 minute public const MIN_RANGE = 300; // 5 minutes - public const DEFAULT_RANGE = 600; + public const DEFAULT_RANGE = 600; // 10 minutes + public const LATEST_GRAIN = 300; // 5 minutes /** * @var bool whether services have been identified that use high memory @@ -97,7 +98,7 @@ protected function addMetricsOptions(): self . "\n" . \sprintf('Minimum %s.', $duration->humanize(self::MIN_INTERVAL)), ); $this->addOption('to', null, InputOption::VALUE_REQUIRED, 'The end time. Defaults to now.'); - $this->addOption('latest', '1', InputOption::VALUE_NONE, 'Show only the latest single data point'); + $this->addOption('latest', '1', InputOption::VALUE_NONE, 'Show only the latest single data point' . "\n" . 'Defaults to a 5-minute aggregation window to ensure all containers are included. Override with --interval.'); $this->addOption('service', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service or application name' . "\n" . Wildcard::HELP); $this->addOption('type', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service type (if --service is not provided). The version is not required.' . "\n" . Wildcard::HELP); @@ -264,6 +265,10 @@ protected function getChooseEnvFilter(): ?callable */ protected function validateTimeInput(InputInterface $input): false|TimeSpec { + $isLatest = $input->getOption('latest'); + $intervalString = $input->getOption('interval'); + $intervalProvided = $intervalString !== null && $intervalString !== ''; + if ($to = $input->getOption('to')) { $endTime = \strtotime((string) $to); if (!$endTime) { @@ -286,6 +291,8 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec return false; } $rangeSeconds = (int) $rangeSeconds; + } elseif ($isLatest && !$intervalProvided) { + $rangeSeconds = self::LATEST_GRAIN; } else { $rangeSeconds = self::DEFAULT_RANGE; } @@ -293,11 +300,11 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec $startTime = $endTime - $rangeSeconds; $interval = null; - if ($intervalString = $input->getOption('interval')) { + if ($intervalProvided) { $interval = (int) (new Duration())->toSeconds($intervalString); if (empty($interval)) { - $this->stdErr->writeln('Invalid --range: ' . $intervalString . ''); + $this->stdErr->writeln('Invalid --interval: ' . $intervalString . ''); return false; } @@ -307,6 +314,8 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec return false; } + } elseif ($isLatest) { + $interval = self::LATEST_GRAIN; } return new TimeSpec($startTime, $endTime, $interval);