Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions legacy/src/Command/Metrics/MetricsCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -97,7 +98,7 @@ protected function addMetricsOptions(): self
. "\n" . \sprintf('Minimum <comment>%s</comment>.', $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 <comment>--interval</comment>.');
$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);

Expand Down Expand Up @@ -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) {
Expand All @@ -286,18 +291,20 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec
return false;
}
$rangeSeconds = (int) $rangeSeconds;
} elseif ($isLatest && !$intervalProvided) {
$rangeSeconds = self::LATEST_GRAIN;
} else {
$rangeSeconds = self::DEFAULT_RANGE;
}

$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: <error>' . $intervalString . '</error>');
$this->stdErr->writeln('Invalid --interval: <error>' . $intervalString . '</error>');

return false;
}
Expand All @@ -307,6 +314,8 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec

return false;
}
} elseif ($isLatest) {
$interval = self::LATEST_GRAIN;
}
Comment thread
pjcdawkins marked this conversation as resolved.

return new TimeSpec($startTime, $endTime, $interval);
Expand Down
Loading