Skip to content

Commit 42a7ad5

Browse files
Merge pull request #53 from VladyslavSikailo/bug/MetricFamilies-MUST-NOT-be-interleaved
MetricFamilies MUST NOT be interleaved
2 parents c7f9c25 + 7655c18 commit 42a7ad5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/Result/PrometheusResult.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace RunAsRoot\PrometheusExporter\Result;
66

77
use Magento\Framework\Api\SearchCriteriaBuilder;
8+
use Magento\Framework\Api\SortOrder;
9+
use Magento\Framework\Api\SortOrderBuilder;
10+
use Magento\Framework\App\ObjectManager;
811
use Magento\Framework\App\Response\HttpInterface as HttpResponseInterface;
912
use Magento\Framework\Controller\Result\Raw;
1013
use RunAsRoot\PrometheusExporter\Api\Data\MetricInterface;
@@ -19,17 +22,20 @@ class PrometheusResult extends Raw
1922
private $searchCriteriaBuilder;
2023
private $metricAggregatorPool;
2124
private $config;
25+
private $sortOrderBuilder;
2226

2327
public function __construct(
2428
MetricAggregatorPool $metricAggregatorPool,
2529
MetricRepositoryInterface $metricRepository,
2630
SearchCriteriaBuilder $searchCriteriaBuilder,
27-
Config $config
31+
Config $config,
32+
?SortOrderBuilder $sortOrderBuilder = null,
2833
) {
29-
$this->metricRepository = $metricRepository;
34+
$this->metricRepository = $metricRepository;
3035
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
31-
$this->metricAggregatorPool = $metricAggregatorPool;
32-
$this->config = $config;
36+
$this->metricAggregatorPool = $metricAggregatorPool;
37+
$this->config = $config;
38+
$this->sortOrderBuilder = $sortOrderBuilder ?? ObjectManager::getInstance()->get(SortOrderBuilder::class);
3339
}
3440

3541
protected function render(HttpResponseInterface $response)
@@ -49,6 +55,9 @@ protected function render(HttpResponseInterface $response)
4955
protected function collectMetrics(): string
5056
{
5157
$searchCriteria = $this->searchCriteriaBuilder->create();
58+
$searchCriteria->setSortOrders([
59+
$this->sortOrderBuilder->setField('code')->setDirection(SortOrder::SORT_ASC)->create()
60+
]);
5261

5362
/** @var MetricInterface[] $metrics */
5463
$metrics = $this->metricRepository->getList($searchCriteria)->getItems();

0 commit comments

Comments
 (0)