From e25c559eb866dcb3cca97d3a2459e435cf04b27f Mon Sep 17 00:00:00 2001 From: Atharva Sharma <60044988+atharvasharma61@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:02:23 +0530 Subject: [PATCH 1/2] fixes the UT failures caused due to Identity Service (#714) Signed-off-by: Atharva Sharma --- .../performanceanalyzer/PerformanceAnalyzerPluginTests.java | 2 +- .../config/PerformanceAnalyzerClusterConfigActionTests.java | 2 +- .../config/PerformanceAnalyzerConfigActionTests.java | 2 +- .../PerformanceAnalyzerOverridesClusterConfigActionTests.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPluginTests.java b/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPluginTests.java index 554eca27..cf7dd703 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPluginTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/PerformanceAnalyzerPluginTests.java @@ -90,7 +90,7 @@ public void setup() { e.printStackTrace(); } clusterService = new ClusterService(settings, clusterSettings, threadPool); - identityService = new IdentityService(Settings.EMPTY, List.of()); + identityService = new IdentityService(Settings.EMPTY, threadPool, List.of()); restController = new RestController( Collections.emptySet(), diff --git a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigActionTests.java b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigActionTests.java index f0e082f5..8767291a 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigActionTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigActionTests.java @@ -71,7 +71,7 @@ public void init() { UsageService usageService = new UsageService(); threadPool = new TestThreadPool("test"); nodeClient = new NodeClient(Settings.EMPTY, threadPool); - identityService = new IdentityService(Settings.EMPTY, List.of()); + identityService = new IdentityService(Settings.EMPTY, threadPool, List.of()); restController = new RestController( Collections.emptySet(), diff --git a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerConfigActionTests.java b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerConfigActionTests.java index 1f2ae19f..c182fd35 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerConfigActionTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerConfigActionTests.java @@ -64,7 +64,7 @@ public void init() { UsageService usageService = new UsageService(); threadPool = new TestThreadPool("test"); nodeClient = new NodeClient(Settings.EMPTY, threadPool); - identityService = new IdentityService(Settings.EMPTY, List.of()); + identityService = new IdentityService(Settings.EMPTY, threadPool, List.of()); restController = new RestController( Collections.emptySet(), diff --git a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerOverridesClusterConfigActionTests.java b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerOverridesClusterConfigActionTests.java index 66c0a65a..16adf381 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerOverridesClusterConfigActionTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerOverridesClusterConfigActionTests.java @@ -65,7 +65,7 @@ public void init() { UsageService usageService = new UsageService(); threadPool = new TestThreadPool("test"); nodeClient = new NodeClient(Settings.EMPTY, threadPool); - identityService = new IdentityService(Settings.EMPTY, List.of()); + identityService = new IdentityService(Settings.EMPTY, threadPool, List.of()); restController = new RestController( Collections.emptySet(), From 7fd7bc76a0b213ff4bb5cb76f3b877d7ff82d6e6 Mon Sep 17 00:00:00 2001 From: Atharva Sharma <60044988+atharvasharma61@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:03:18 +0530 Subject: [PATCH 2/2] fixes the cacheConfigRTFCollector UT (#713) Signed-off-by: Atharva Sharma --- .../telemetry/RTFCacheConfigMetricsCollectorTests.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollectorTests.java b/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollectorTests.java index 00d5d871..27d55e36 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollectorTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/collectors/telemetry/RTFCacheConfigMetricsCollectorTests.java @@ -6,13 +6,11 @@ package org.opensearch.performanceanalyzer.collectors.telemetry; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyDouble; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; import java.io.IOException; import org.junit.After; @@ -24,7 +22,6 @@ import org.opensearch.performanceanalyzer.commons.config.overrides.ConfigOverridesWrapper; import org.opensearch.performanceanalyzer.commons.metrics.MetricsConfiguration; import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController; -import org.opensearch.telemetry.metrics.Histogram; import org.opensearch.telemetry.metrics.MetricsRegistry; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -32,7 +29,6 @@ public class RTFCacheConfigMetricsCollectorTests extends OpenSearchSingleNodeTes private static final String TEST_INDEX = "test"; private RTFCacheConfigMetricsCollector rtfCacheConfigMetricsCollector; private static MetricsRegistry metricsRegistry; - private static Histogram testHistogram; private long startTimeInMills = 1153721339; @Before @@ -40,10 +36,7 @@ public void init() { MetricsConfiguration.CONFIG_MAP.put( RTFCacheConfigMetricsCollector.class, MetricsConfiguration.cdefault); metricsRegistry = mock(MetricsRegistry.class); - testHistogram = mock(Histogram.class); OpenSearchResources.INSTANCE.setMetricsRegistry(metricsRegistry); - when(metricsRegistry.createHistogram(anyString(), anyString(), anyString())) - .thenReturn(testHistogram); IndicesService indicesService = getInstanceFromNode(IndicesService.class); OpenSearchResources.INSTANCE.setIndicesService(indicesService); ConfigOverridesWrapper mockWrapper = mock(ConfigOverridesWrapper.class); @@ -62,6 +55,7 @@ public void tearDown() throws Exception { public void testCollectMetrics() throws IOException { createIndex(TEST_INDEX); rtfCacheConfigMetricsCollector.collectMetrics(startTimeInMills); - verify(testHistogram, atLeastOnce()).record(anyDouble(), any()); + verify(metricsRegistry, atLeastOnce()) + .createGauge(anyString(), anyString(), anyString(), any(), any()); } }