Skip to content
Merged
Show file tree
Hide file tree
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
21 changes: 18 additions & 3 deletions src/Command/Metrics/MetricsCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ protected function getChooseEnvFilter(): ?callable
*/
protected function validateTimeInput(InputInterface $input): false|TimeSpec
{
$this->io->warnAboutDeprecatedOptions(['interval']);

if ($to = $input->getOption('to')) {
$endTime = \strtotime((string) $to);
if (!$endTime) {
Expand Down Expand Up @@ -293,8 +291,25 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec
}

$startTime = $endTime - $rangeSeconds;
$interval = null;

if ($intervalString = $input->getOption('interval')) {
$interval = (int) (new Duration())->toSeconds($intervalString);

if (empty($interval)) {
$this->stdErr->writeln('Invalid --range: <error>' . $intervalString . '</error>');

return false;
}

if ($interval > $endTime - $startTime) {
$this->stdErr->writeln(\sprintf('The --interval <error>%s</error> is invalid. It cannot be greater than the selected time range', $intervalString));

return false;
}
}

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

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Model/Metrics/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ final class Query
public function __construct(
private int $startTime,
private int $endTime,
private ?int $interval,
) {}

public static function fromTimeSpec(TimeSpec $timeSpec): self
{
return new self($timeSpec->getStartTime(), $timeSpec->getEndTime());
return new self($timeSpec->getStartTime(), $timeSpec->getEndTime(), $timeSpec->getInterval());
}

/** @param array<String>|null $services */
Expand Down Expand Up @@ -58,6 +59,10 @@ public function asArray(): array
'to' => $this->endTime,
];

if (null !== $this->interval) {
$query['grain'] = $this->interval;
}

if (!empty($this->services)) {
$query['services_mode'] = '1';
$query['services'] = $this->services;
Expand Down
11 changes: 10 additions & 1 deletion src/Model/Metrics/TimeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
* @param int $startTime start time (UNIX timestamp)
* @param int $endTime end time (UNIX timestamp)
*/
public function __construct(private int $startTime, private int $endTime) {}
public function __construct(
private int $startTime,
private int $endTime,
private ?int $interval,
) {}

public function getStartTime(): int
{
Expand All @@ -21,4 +25,9 @@ public function getEndTime(): int
{
return $this->endTime;
}

public function getInterval(): ?int
{
return $this->interval;
}
}
Loading