Skip to content

Commit 5e467b8

Browse files
committed
Restore metrcis --interval option
1 parent d5b249c commit 5e467b8

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

src/Command/Metrics/MetricsCommandBase.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ protected function getChooseEnvFilter(): ?callable
264264
*/
265265
protected function validateTimeInput(InputInterface $input): false|TimeSpec
266266
{
267-
$this->io->warnAboutDeprecatedOptions(['interval']);
268-
269267
if ($to = $input->getOption('to')) {
270268
$endTime = \strtotime((string) $to);
271269
if (!$endTime) {
@@ -293,8 +291,26 @@ protected function validateTimeInput(InputInterface $input): false|TimeSpec
293291
}
294292

295293
$startTime = $endTime - $rangeSeconds;
294+
$interval = null;
295+
296+
if ($intervalString = $input->getOption('interval')) {
297+
$interval = (int) (new Duration())->toSeconds($intervalString);
298+
299+
if (empty($interval)) {
300+
$this->stdErr->writeln('Invalid --range: <error>' . $intervalString . '</error>');
301+
302+
return false;
303+
}
304+
305+
if ($interval > $endTime - $startTime) {
306+
$this->stdErr->writeln(\sprintf('The --interval <error>%s</error> is invalid. It cannot be greater than the selected time range', $intervalString));
307+
308+
return false;
309+
310+
}
311+
}
296312

297-
return new TimeSpec($startTime, $endTime);
313+
return new TimeSpec($startTime, $endTime, $interval);
298314
}
299315

300316
/**

src/Model/Metrics/Query.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ final class Query
1919
public function __construct(
2020
private int $startTime,
2121
private int $endTime,
22+
private ?int $interval,
2223
) {}
2324

2425
public static function fromTimeSpec(TimeSpec $timeSpec): self
2526
{
26-
return new self($timeSpec->getStartTime(), $timeSpec->getEndTime());
27+
return new self($timeSpec->getStartTime(), $timeSpec->getEndTime(), $timeSpec->getInterval());
2728
}
2829

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

62+
if (null !== $this->interval) {
63+
$query['grain'] = $this->interval;
64+
}
65+
6166
if (!empty($this->services)) {
6267
$query['services_mode'] = '1';
6368
$query['services'] = $this->services;

src/Model/Metrics/TimeSpec.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
* @param int $startTime start time (UNIX timestamp)
1111
* @param int $endTime end time (UNIX timestamp)
1212
*/
13-
public function __construct(private int $startTime, private int $endTime) {}
13+
public function __construct(
14+
private int $startTime,
15+
private int $endTime,
16+
private ?int $interval,
17+
) {}
1418

1519
public function getStartTime(): int
1620
{
@@ -21,4 +25,9 @@ public function getEndTime(): int
2125
{
2226
return $this->endTime;
2327
}
28+
29+
public function getInterval(): ?int
30+
{
31+
return $this->interval;
32+
}
2433
}

0 commit comments

Comments
 (0)