This repository has been archived by the owner on Dec 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graph): Create new API endpoint metrics/download (#11367)
* Add performance metric download API * Remove unused classes * Add OpenAPI documentation for metrics/download API * Fix coding style * Add new CSV response class * Enable usage of csv and json presenters * Proposal from Laurent * Allow to use custom file name in csv download response * Remove unused methods. Fix coding style * Renaming ReadDataBinRepositoryInterface to ReadPerformanceDataRepositoryInterface * Add unit test for FindPerformanceMetricResponse class * Fix Code style * Add unit tests for FindPerformanceMetrics class * Refactor FindPerformanceMetrics use case * Refactor IndexDataRepository class methods * Convert phpunit tests for Performance metric to pestphp * Add phpdoc on Find Performance Metric use case methods * Update Co-authored-by: Laurent Calvet <lcalvet@centreon.com>
- Loading branch information
Showing
27 changed files
with
1,640 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Core/Application/RealTime/Repository/ReadIndexDataRepositoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\Repository; | ||
|
||
use Core\Domain\RealTime\Model\IndexData; | ||
|
||
interface ReadIndexDataRepositoryInterface | ||
{ | ||
/** | ||
* @param int $hostId | ||
* @param int $serviceId | ||
* @throw \Throwable | ||
* @return int | ||
*/ | ||
public function findIndexByHostIdAndServiceId(int $hostId, int $serviceId): int; | ||
|
||
/** | ||
* @param int $index | ||
* @return IndexData|null | ||
*/ | ||
public function findHostNameAndServiceDescriptionByIndex(int $index): ?IndexData; | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Core/Application/RealTime/Repository/ReadMetricRepositoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\Repository; | ||
|
||
use Core\Domain\RealTime\Model\Metric; | ||
|
||
interface ReadMetricRepositoryInterface | ||
{ | ||
/** | ||
* @param int $indexId | ||
* @return array<Metric> | ||
*/ | ||
public function findMetricsByIndexId(int $indexId): array; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/Core/Application/RealTime/Repository/ReadPerformanceDataRepositoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\Repository; | ||
|
||
use DateTimeInterface; | ||
use Core\Domain\RealTime\Model\Metric; | ||
use Core\Domain\RealTime\Model\PerformanceMetric; | ||
|
||
interface ReadPerformanceDataRepositoryInterface | ||
{ | ||
/** | ||
* @param array<Metric> $metrics | ||
* @param DateTimeInterface $startDate | ||
* @param DateTimeInterface $endDate | ||
* @return iterable<PerformanceMetric> | ||
*/ | ||
public function findDataByMetricsAndDates( | ||
array $metrics, | ||
DateTimeInterface $startDate, | ||
DateTimeInterface $endDate | ||
): iterable; | ||
} |
31 changes: 31 additions & 0 deletions
31
...ation/RealTime/UseCase/FindPerformanceMetrics/FindPerformanceMetricPresenterInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\UseCase\FindPerformanceMetrics; | ||
|
||
use Core\Application\Common\UseCase\PresenterInterface; | ||
use Core\Infrastructure\Common\Presenter\DownloadInterface; | ||
|
||
interface FindPerformanceMetricPresenterInterface extends PresenterInterface, DownloadInterface | ||
{ | ||
} |
43 changes: 43 additions & 0 deletions
43
...Core/Application/RealTime/UseCase/FindPerformanceMetrics/FindPerformanceMetricRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\UseCase\FindPerformanceMetrics; | ||
|
||
use DateTimeInterface; | ||
|
||
class FindPerformanceMetricRequest | ||
{ | ||
/** | ||
* @param int $hostId | ||
* @param int $serviceId | ||
* @param DateTimeInterface $startDate | ||
* @param DateTimeInterface $endDate | ||
*/ | ||
public function __construct( | ||
public int $hostId, | ||
public int $serviceId, | ||
public DateTimeInterface $startDate, | ||
public DateTimeInterface $endDate | ||
) { | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ore/Application/RealTime/UseCase/FindPerformanceMetrics/FindPerformanceMetricResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2005 - 2022 Centreon (https://www.centreon.com/) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* For more information : contact@centreon.com | ||
* | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Core\Application\RealTime\UseCase\FindPerformanceMetrics; | ||
|
||
use Core\Domain\RealTime\Model\PerformanceMetric; | ||
|
||
class FindPerformanceMetricResponse | ||
{ | ||
/** | ||
* @var iterable<mixed> | ||
*/ | ||
public iterable $performanceMetrics = []; | ||
|
||
/** | ||
* @param iterable<PerformanceMetric> $performanceMetrics | ||
*/ | ||
public function __construct(iterable $performanceMetrics) | ||
{ | ||
$this->performanceMetrics = $this->performanceMetricToArray($performanceMetrics); | ||
} | ||
|
||
/** | ||
* @param iterable<PerformanceMetric> $performanceMetrics | ||
* @return iterable<mixed> | ||
*/ | ||
private function performanceMetricToArray(iterable $performanceMetrics): iterable | ||
{ | ||
foreach ($performanceMetrics as $performanceMetric) { | ||
yield $this->formatPerformanceMetric($performanceMetric); | ||
} | ||
} | ||
|
||
/** | ||
* @param PerformanceMetric $performanceMetric | ||
* @return array<string, mixed> | ||
*/ | ||
private function formatPerformanceMetric(PerformanceMetric $performanceMetric): array | ||
{ | ||
$formattedData = [ | ||
'time' => $performanceMetric->getDateValue()->getTimestamp(), | ||
'humantime' => $performanceMetric->getDateValue()->format('Y-m-d H:i:s') | ||
]; | ||
|
||
foreach ($performanceMetric->getMetricValues() as $metricValue) { | ||
$formattedData[$metricValue->getName()] = sprintf('%f', $metricValue->getValue()); | ||
} | ||
|
||
return $formattedData; | ||
} | ||
} |
Oops, something went wrong.