diff --git a/src/Command/Metrics/MetricsCommandBase.php b/src/Command/Metrics/MetricsCommandBase.php
index 4ac0a80ad..ef8e92f7b 100644
--- a/src/Command/Metrics/MetricsCommandBase.php
+++ b/src/Command/Metrics/MetricsCommandBase.php
@@ -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) {
@@ -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: ' . $intervalString . '');
+
+ return false;
+ }
+
+ if ($interval > $endTime - $startTime) {
+ $this->stdErr->writeln(\sprintf('The --interval %s 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);
}
/**
diff --git a/src/Model/Metrics/Query.php b/src/Model/Metrics/Query.php
index 0f2bdf6b7..524907c19 100644
--- a/src/Model/Metrics/Query.php
+++ b/src/Model/Metrics/Query.php
@@ -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|null $services */
@@ -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;
diff --git a/src/Model/Metrics/TimeSpec.php b/src/Model/Metrics/TimeSpec.php
index c80a31c95..a7b70eafb 100644
--- a/src/Model/Metrics/TimeSpec.php
+++ b/src/Model/Metrics/TimeSpec.php
@@ -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
{
@@ -21,4 +25,9 @@ public function getEndTime(): int
{
return $this->endTime;
}
+
+ public function getInterval(): ?int
+ {
+ return $this->interval;
+ }
}