summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPavel Zhukov <33721692+LeaveMyYard@users.noreply.github.com>2023-08-02 13:57:59 +0300
committerGitHub <noreply@github.com>2023-08-02 13:57:59 +0300
commitd202105fdb60b20b37c34289566967a214c0e0ca (patch)
tree80d11ae20c9e9e703e2c4a54a9f87f3e2501fcd5 /tests
parent7b04d233d9638742dc5dac5fa6793f266b7eecdb (diff)
parent81d640c2ffb351fa7a6e4447a0b4de29108d3e70 (diff)
Merge pull request #116 from robusta-dev/strategy-metric-usage-refactoring
Refactor strategy dependancy on metrics
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 3b89e88..6bb1b1c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -5,7 +5,8 @@ from unittest.mock import AsyncMock, patch
import numpy as np
import pytest
-from robusta_krr.api.models import K8sObjectData, PodData, ResourceAllocations, ResourceHistoryData
+from robusta_krr.api.models import K8sObjectData, PodData, ResourceAllocations
+from robusta_krr.strategies.simple import SimpleStrategy, SimpleStrategySettings
TEST_OBJECT = K8sObjectData(
cluster="mock-cluster",
@@ -56,18 +57,16 @@ def mock_prometheus_loader():
now_ts, start_ts = now.timestamp(), start.timestamp()
metric_points_data = np.array([(t, random.randrange(0, 100)) for t in np.linspace(start_ts, now_ts, 3600)])
+ settings = SimpleStrategySettings()
+ strategy = SimpleStrategy(settings)
+
with patch(
- "robusta_krr.core.integrations.prometheus.loader.MetricsLoader.gather_data",
+ "robusta_krr.core.integrations.prometheus.loader.PrometheusMetricsLoader.gather_data",
new=AsyncMock(
- return_value=ResourceHistoryData(
- data={pod.name: metric_points_data for pod in TEST_OBJECT.pods},
- metric={ # type: ignore
- "query": f"example_promql_metric{{pod_name=~\"{'|'.join(pod.name for pod in TEST_OBJECT.pods)}\"}}",
- "start_time": start,
- "end_time": now,
- "step": "30s",
- },
- )
+ return_value={
+ metric.__name__: {pod.name: metric_points_data for pod in TEST_OBJECT.pods}
+ for metric in strategy.metrics
+ },
),
) as mock_prometheus_loader:
mock_prometheus_loader
@@ -76,5 +75,5 @@ def mock_prometheus_loader():
@pytest.fixture(autouse=True, scope="session")
def mock_prometheus_init():
- with patch("robusta_krr.core.integrations.prometheus.loader.MetricsLoader.__init__", return_value=None):
+ with patch("robusta_krr.core.integrations.prometheus.loader.PrometheusMetricsLoader.__init__", return_value=None):
yield