Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit a70f2c0

Browse files
committed
feat: improve latest
1 parent 2cdfae8 commit a70f2c0

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Command/Metrics/MetricsCommandBase.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
abstract class MetricsCommandBase extends CommandBase
2828
{
29-
const MIN_INTERVAL = 60; // 1 minute
29+
const MIN_INTERVAL = 60; // 1 minute
3030

31-
const MIN_RANGE = 300; // 5 minutes
32-
const DEFAULT_RANGE = 600;
31+
const MIN_RANGE = 300; // 5 minutes
32+
const DEFAULT_RANGE = 600; // 10 minutes
33+
const LATEST_GRAIN = 300; // 5 minutes
3334

3435
/**
3536
* @var bool whether services have been identified that use high memory
@@ -64,7 +65,7 @@ protected function addMetricsOptions()
6465
. "\n" . \sprintf('Minimum <comment>%s</comment>.', $duration->humanize(self::MIN_INTERVAL))
6566
);
6667
$this->addOption('to', null, InputOption::VALUE_REQUIRED, 'The end time. Defaults to now.');
67-
$this->addOption('latest', '1', InputOption::VALUE_NONE, 'Show only the latest single data point');
68+
$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 <comment>--interval</comment>.');
6869
$this->addOption('service', 's', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter by service or application name' . "\n" . Wildcard::HELP);
6970
$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);
7071

@@ -231,6 +232,8 @@ private function getServices(InputInterface $input, Environment $environment)
231232
*/
232233
protected function validateTimeInput(InputInterface $input)
233234
{
235+
$isLatest = $input->getOption('latest');
236+
234237
if ($to = $input->getOption('to')) {
235238
$endTime = \strtotime($to);
236239
if (!$endTime) {
@@ -253,6 +256,8 @@ protected function validateTimeInput(InputInterface $input)
253256
return false;
254257
}
255258
$rangeSeconds = (int) $rangeSeconds;
259+
} elseif ($isLatest && !$input->getOption('interval')) {
260+
$rangeSeconds = self::LATEST_GRAIN;
256261
} else {
257262
$rangeSeconds = self::DEFAULT_RANGE;
258263
}
@@ -274,6 +279,8 @@ protected function validateTimeInput(InputInterface $input)
274279

275280
return false;
276281
}
282+
} elseif ($isLatest) {
283+
$interval = self::LATEST_GRAIN;
277284
}
278285

279286
return new TimeSpec($startTime, $endTime, $interval);

0 commit comments

Comments
 (0)