From 574f759942b0e5ffbc3dfa600e14627dadba0c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Haracewiat?= Date: Tue, 3 Mar 2026 12:42:39 +0100 Subject: [PATCH 1/2] feat: improve latest --- legacy/src/Command/Metrics/MetricsCommandBase.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/legacy/src/Command/Metrics/MetricsCommandBase.php b/legacy/src/Command/Metrics/MetricsCommandBase.php index ef8e92f7b..90109714a 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,8 @@ protected function getChooseEnvFilter(): ?callable */ protected function validateTimeInput(InputInterface $input): false|TimeSpec { + $isLatest = $input->getOption('latest'); + if ($to = $input->getOption('to')) { $endTime = \strtotime((string) $to); if (!$endTime) { @@ -286,6 +289,8 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec return false; } $rangeSeconds = (int) $rangeSeconds; + } elseif ($isLatest && !$input->getOption('interval')) { + $rangeSeconds = self::LATEST_GRAIN; } else { $rangeSeconds = self::DEFAULT_RANGE; } @@ -307,6 +312,8 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec return false; } + } elseif ($isLatest) { + $interval = self::LATEST_GRAIN; } return new TimeSpec($startTime, $endTime, $interval); From f76eae917f0e1f9e919e4b38afdf0b94bda17223 Mon Sep 17 00:00:00 2001 From: Patrick Dawkins Date: Mon, 27 Apr 2026 21:46:45 +0100 Subject: [PATCH 2/2] fix(metrics): use strict check for --interval option Detect whether `--interval` was provided using a strict null/empty-string check rather than truthiness, so a literal `0` (or any duration that parses to zero seconds) is rejected with a clear error instead of being silently replaced with the default range/grain. Also corrects a stale "Invalid --range" message in the --interval validation branch. Addresses Copilot review feedback on #49. Co-Authored-By: Claude Opus 4.7 (1M context) --- legacy/src/Command/Metrics/MetricsCommandBase.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/legacy/src/Command/Metrics/MetricsCommandBase.php b/legacy/src/Command/Metrics/MetricsCommandBase.php index 90109714a..598ef8afa 100644 --- a/legacy/src/Command/Metrics/MetricsCommandBase.php +++ b/legacy/src/Command/Metrics/MetricsCommandBase.php @@ -266,6 +266,8 @@ 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); @@ -289,7 +291,7 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec return false; } $rangeSeconds = (int) $rangeSeconds; - } elseif ($isLatest && !$input->getOption('interval')) { + } elseif ($isLatest && !$intervalProvided) { $rangeSeconds = self::LATEST_GRAIN; } else { $rangeSeconds = self::DEFAULT_RANGE; @@ -298,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; }